]> git.plutz.net Git - cgilite/blobdiff - storage.sh
escape spaces in stored data for easyer use with `read`
[cgilite] / storage.sh
index d4fbca36714a0cfe08db9ea9d465d43b3ef83b9c..8bd1b952dc54b1a9891772b2a03a01581f0a1d74 100755 (executable)
@@ -17,6 +17,9 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with CGIlite.  If not, see <http://www.gnu.org/licenses/>. 
 
+[ -n "$include_storage" ] && return 0
+include_storage="$0"
+
 LOCK(){
   lock="${1}.lock"
   timeout="${2-20}"
@@ -25,7 +28,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
@@ -39,7 +42,7 @@ LOCK(){
     sleep 1
   done
   printf '%i\n' $$ >"${lock}/pid"
-  return 1
+  return 0
 }
 
 RELEASE(){
@@ -51,6 +54,7 @@ RELEASE(){
       printf '%i\n' $$ >"${lock}/pid"
       return 1
     fi
+    return 0
   else
     printf 'Refusing to release foreign lock: %s\n' "$lock" >&2
     return 1
@@ -64,6 +68,8 @@ STRING(){
     s;\n;\\n;g;
     s;\t;\\t;g;
     s;\r;\\r;g;
+    s;\+;\\+;g;
+    s; ;+;g;
   '
 }
 
@@ -73,7 +79,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;
   '
 }