summaryrefslogtreecommitdiff
path: root/vsvs
diff options
context:
space:
mode:
authorAleksey Veresov <aleksey@veresov.pro>2020-12-06 16:57:48 +0300
committerAleksey Veresov <aleksey@veresov.pro>2020-12-06 16:57:48 +0300
commitf5596618ff3e6819c547bf833388d25b9bb36293 (patch)
tree7a47b6a3ba030e525d20713de428c14d06b6b9e4 /vsvs
parentf229b632cbc31c5efad109589cd36b07bcd48817 (diff)
downloadvsvs-f5596618ff3e6819c547bf833388d25b9bb36293.tar
vsvs-f5596618ff3e6819c547bf833388d25b9bb36293.tar.xz
vsvs-f5596618ff3e6819c547bf833388d25b9bb36293.zip
.
Diffstat (limited to 'vsvs')
-rwxr-xr-xvsvs67
1 files changed, 40 insertions, 27 deletions
diff --git a/vsvs b/vsvs
index 7977ec3..f486ba0 100755
--- a/vsvs
+++ b/vsvs
@@ -1,31 +1,44 @@
#!/bin/bash
-res=""
-buf=""
-key=""
-while IFS="" read str
-do
- if [ -z "${str##* *}" ]
- then
- newkey="${str%% *}"
- val="${str#* }"
- else
- newkey="${str}"
- val=""
- fi
- if [ -z "${newkey}" ]
+
+# This is a parser of the Very Simple Values Storage.
+# It has two arguments: an action and an object.
+# Action is a string to be evaluated with key and its value provided.
+action=$1
+# Object is like a path in filesystem (which pretty much it is),
+# this is a string describing piece of data in storage.
+object=$2
+
+# Utility functions:
+after () { test -z "${2##*$1*}" && echo -n "${2#*$1}" }
+
+# File processor:
+pfile () {
+ # First of all, we need to lock the file.
+ lockfile="$base/proc/$proc/lock/$object"
+ mkdir -p -- "${lockfile%/*}"
+ echo $proc > $lockfile
+ lockpath="$path.lock"
+ if ln $lockfile $lockpath
then
- buf="${buf}"$'\n'"${val}"
- else
- if [ -n "${buf}" ]
- then
- eval $1
- fi
- key="${newkey}"
- buf="${val}"
+ # PARSER
+ rm $lockpath
fi
+ rm $lockfile
+}
+
+# First of all, we need to locate object in filesystem.
+# To do so, we will get parts of the path from the beginning of object,
+# until we will run out of object or meet the file in filesystem.
+test "${object::1}" == "/" && path=$base || path="."
+lastpath=$object
+until test -n "$lastpath"
+do
+ # Tear another part of $lastpath until slash into $path:
+ path="$path/${lastpath%%/*}"
+ lastpath=$(after / "$lastpath")
+ # If $path does not exist, the object does not exist too,
+ test -e "$path" || exit 1
+ # otherwise it can be file, then we need to parse it and exit,
+ # or it can be a directory, then we need to repeat the process.
+ test -f "$path" && pfile "$action" "$object" "$path" "$lastpath"; exit 0
done
-if [ -n "${buf}" ]
-then
- eval $1
-fi
-echo -n "${res}"