X-Git-Url: http://git.plutz.net/?p=cgilite;a=blobdiff_plain;f=storage.sh;h=a6b6b436a947cea57b3bf684df5e8c67caa9cb66;hp=8939fdc7c83fcb9bdde8cc1738ed1e4baabc3963;hb=6aa432e55d9227b58dbe3d20518eb7adfa057070;hpb=40c5373a1f5eb710635f340e88c31f8c9dfedfeb diff --git a/storage.sh b/storage.sh index 8939fdc..a6b6b43 100755 --- a/storage.sh +++ b/storage.sh @@ -21,6 +21,7 @@ include_storage="$0" LOCK(){ + local lock timeout block lock="${1}.lock" timeout="${2-20}" if [ \! -w "${lock%/*}" ] || [ -e "$lock" -a \! -d "$lock" ]; then @@ -28,7 +29,7 @@ LOCK(){ return 1 fi - while ! mkdir "$lock"; do + while ! mkdir "$lock" 2>&-; do block="$(cat "$lock/pid" || printf 1)" if ! { ps -eo pid |grep -qwF "$block"; }; then printf 'Overriding stale lock: %s\n' "$lock" >&2 @@ -46,6 +47,7 @@ LOCK(){ } RELEASE(){ + local lock lock="${1}.lock" if [ "$(cat "$lock/pid")" = "$$" ]; then rm "$lock/pid" @@ -68,6 +70,8 @@ STRING(){ s;\n;\\n;g; s;\t;\\t;g; s;\r;\\r;g; + s;\+;\\+;g; + s; ;+;g; ' } @@ -77,7 +81,9 @@ UNSTRING(){ s;((^|[^\\])(\\\\)*)\\n;\1\n;g; s;((^|[^\\])(\\\\)*)\\t;\1\t;g; s;((^|[^\\])(\\\\)*)\\r;\1\r;g; + s;((^|[^\\])(\\\\)*)\+;\1 ;g; tX; + s;((^|[^\\])(\\\\)*)\\\+;\1+;g; s;\\\\;\\;g; ' }