From: Paul Hänsch Date: Wed, 17 Nov 2021 01:49:59 +0000 (+0100) Subject: quicker update function X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=a2cd32dfe7f8c4fa0051ae5823552ac5c4cf4cf6;p=serve0 quicker update function --- diff --git a/db_meta.sh b/db_meta.sh index 5b375f7..f1eec4d 100755 --- a/db_meta.sh +++ b/db_meta.sh @@ -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