]> git.plutz.net Git - serve0/blob - multitag.sh
fix bug in exclusive tag support
[serve0] / multitag.sh
1 #!/bin/sh
2
3 . "$_EXEC/cgilite/storage.sh"
4 . "$_EXEC/indexmeta.sh"
5
6 newtags=''
7 for tn in $(seq 1 $(POST_COUNT tag)); do
8   newtags="$(POST tag $tn)${BR}${newtags}"
9 done
10 newtags="$(POST newtag |tr -d '\r' |tr , '\n')${BR}${newtags}"
11
12 while [ "${newtags#${BR}}" != "${newtags}" ]; do newtags="${newtags#${BR}}"; done
13 while [ "${newtags%${BR}}" != "${newtags}" ]; do newtags="${newtags%${BR}}"; done
14
15 [ "$(POST op)" = del ] && deltags="$newtags"
16
17 echo "x $newtags x" >&2
18
19 for select in $(seq 1 $(POST_COUNT select)); do
20   file="$_DATA/$ITEM/$(POST select $select |PATH)"
21   meta="${file%/*}/.index/meta"
22
23   read -r length width height tags comment fn <<-EOF
24         $(meta_info "$file")
25         EOF
26   tags="$(UNSTRING "${tags#tags=}" |tr , '\n')"
27
28   if [ ! "$deltags" ]; then
29     extags="$(printf '%s' "${newtags}" |grep -e "^-" |cut -d: -f1 )"
30     [ "$extags" ] && tags="$(printf %s\\n "$tags" |grep -vwFe "$extags")"
31     if printf %s "${newtags}" |grep -e "^-" |grep -qEe "^-[^:]+$"; then
32       tags="$(printf %s\\n "$tags" |grep -vEe '^-[^:]+$')"
33     fi
34     tags="$(printf '%s\n' "${tags},${newtags}" \
35             | tr , '\n' |sort -u |tr '\n' , \
36             | STRING)"
37   else
38     detag="${deltags}${BR}"; while [ "$detag" ]; do
39       tags="$(printf '%s\n' "$tags" |grep -vxFe "${detag%%${BR}*}")"
40       detag="${detag#*${BR}}"
41     done
42     tags="$(printf '%s\n' "$tags" |sort -u |tr '\n' , |STRING)"
43   fi
44   tags="${tags#,}"; tags="${tags%,}"
45
46   if LOCK "$meta"; then
47     grep -avF " $fn" "$meta" >"${meta}.tmp"
48
49     printf '%i  %i      %i      tags=%s comment=%s      %s\n' \
50            "$length" "$width" "$height" "$tags" \
51            "${comment#comment=}" "$fn" \
52       >>"${meta}.tmp"
53     mv "${meta}.tmp" "$meta"
54
55     RELEASE "$meta"
56   fi
57 done