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