From aaa71c80d68971127909d7c790698e77a3b22ed9 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 15 May 2020 18:49:38 +0200 Subject: [PATCH] fix deleteKeyDB --- modules/jsonDB.sh | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/modules/jsonDB.sh b/modules/jsonDB.sh index d737147..39fabe3 100644 --- a/modules/jsonDB.sh +++ b/modules/jsonDB.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.94-pre-13-g52bde30 +#### $$VERSION$$ v0.94-pre-14-gc02327f # # source from commands.sh to use jsonDB functions # @@ -108,14 +108,13 @@ if _exists flock; then # $2 filename (must exist!), must be relative to BASHBOT_ETC, and not contain '..' jssh_deleteKeyDB() { [[ "$1" =~ ^[-a-zA-Z0-9,._]+$ ]] || return 3 + local DB; DB="$(jssh_checkDB "$2")" declare -A oldARR # start atomic delete here, exclusive max wait 10s { flock -e -w 10 200 Json2Array "oldARR" <"${DB}" - if [[ -v "oldAR[$1]" ]] ; then - unset oldARR["$1"] - Array2Json "oldARR" >"${DB}" - fi + unset oldARR["$1"] + Array2Json "oldARR" >"${DB}" } 200>"${DB}${BASHBOT_LOCKNAME}" } @@ -238,11 +237,10 @@ jssh_insertDB_async() { jssh_deleteKeyDB_async() { [[ "$1" =~ ^[-a-zA-Z0-9,._]+$ ]] || return 3 + local DB; DB="$(jssh_checkDB "$2")" declare -A oldARR jssh_readDB_async "oldARR" "$2" || return "$?" - if [[ -v "oldAR[$1]" ]] ; then - unset oldARR["$1"] - jssh_writeDB_async "oldARR" "$2" - fi + unset oldARR["$1"] + jssh_writeDB_async "oldARR" "$2" }