From a2cd32dfe7f8c4fa0051ae5823552ac5c4cf4cf6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Wed, 17 Nov 2021 02:49:59 +0100 Subject: [PATCH] quicker update function --- db_meta.sh | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) 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 -- 2.39.2