]> git.plutz.net Git - serve0/commitdiff
quicker update function
authorPaul Hänsch <paul@plutz.net>
Wed, 17 Nov 2021 01:49:59 +0000 (02:49 +0100)
committerPaul Hänsch <paul@plutz.net>
Wed, 17 Nov 2021 01:49:59 +0000 (02:49 +0100)
db_meta.sh

index 5b375f703c30e5ed66d669755aa86743acd6679a..f1eec4d237db1c97ab890b7f71c92a4564c70f71 100755 (executable)
@@ -65,21 +65,24 @@ update_meta(){
   esac; done
 
   if LOCK "$meta_db"; then
-    while read -r LENGTH WIDTH HEIGHT TAGS COMMENT NAME; do
-      if [ "$name" = "${NAME%${CR}}" ]; then
-        printf '%i     %i      %i      tags=%s comment=%s      %s\r\n' \
-               "${length:-${length-${LENGTH}}${length+0}}" \
-               "${width:-${width-${WIDTH}}${width+0}}" \
-               "${height:-${height-${HEIGHT}}${height+0}}" \
-               "$(STRING "${tags-$(UNSTRING "${TAGS#tags=}")}")" \
-               "$(STRING "${comment-$(UNSTRING "${COMMENT#comment=}")}")" \
-               "$(STRING "${name-$(UNSTRING "${NAME%${CR}}")}")"
-      else
-        printf '%i     %i      %i      tags=%s comment=%s      %s\r\n' \
-               "$LENGTH" "$WIDTH" "$HEIGHT" "${TAGS#tags=}" \
-               "${COMMENT#comment=}" "${NAME%${CR}}"
-      fi
-    done <"$meta_db" >"${meta_db}.$$"
+    read -r LENGTH WIDTH HEIGHT TAGS COMMENT NAME <<-EOF
+       $(grep -F "     ${name}${CR}" "$meta_db")
+       EOF
+    if [ ! "$NAME" ]; then
+      RELEASE "$meta_db"
+      return 1
+    fi
+    printf '%i %i      %i      tags=%s comment=%s      %s\r\n' \
+           "${length:-${length-${LENGTH}}${length+0}}" \
+           "${width:-${width-${WIDTH}}${width+0}}" \
+           "${height:-${height-${HEIGHT}}${height+0}}" \
+           "$(STRING "${tags-$(UNSTRING "${TAGS#tags=}")}")" \
+           "$(STRING "${comment-$(UNSTRING "${COMMENT#comment=}")}")" \
+           "${NAME%${CR}}" \
+    >"${meta_db}.$$"
+
+    grep -vF " ${name}${CR}" "$meta_db" >>"${meta_db}.$$"
+
     mv -- "${meta_db}.$$" "${meta_db}"
     RELEASE "$meta_db"
   else