summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2022-01-03 10:48:58 +0000
committerPaul Buetow <paul@buetow.org>2022-01-03 10:49:53 +0000
commit8caa976ca4c5dd4b399d02ebc198d3a9db1e7bdb (patch)
tree2dbe8868b7400bcc13c6a82b98ac204f081e076d /lib
parent7f3318ecab9b9ffedc47e0a9d247dc5fdf9b2893 (diff)
lock concurrent git commands. also log bash pid.
Diffstat (limited to 'lib')
-rw-r--r--lib/git.source.sh31
-rw-r--r--lib/log.source.sh7
2 files changed, 35 insertions, 3 deletions
diff --git a/lib/git.source.sh b/lib/git.source.sh
index c502b00..c51707b 100644
--- a/lib/git.source.sh
+++ b/lib/git.source.sh
@@ -1,3 +1,28 @@
+# Git can not run concurrently
+git::_lock () {
+ local -r lock="${CONTENT_BASE_DIR}/git.lock"
+
+ while test -d $lock; do
+ sleep 0.1
+ done
+ while ! mkdir $lock 2>/dev/null; do
+ sleep 0.1
+ done
+}
+
+git::_unlock () {
+ local -r lock="${CONTENT_BASE_DIR}/git.lock"
+ rmdir $lock
+ # log DEBUG "Removed $lock"
+}
+
+git::cleanup () {
+ local -r lock="${CONTENT_BASE_DIR}/git.lock"
+ if [ -d "$lock" ]; then
+ git::_unlock
+ fi
+}
+
# Add a static content file to git
git::add () {
if [[ "$USE_GIT" != yes ]]; then
@@ -8,9 +33,11 @@ git::add () {
local file="$1"; shift
file=${file/$content_dir/.\/}
+ git::_lock
cd "$content_dir" &>/dev/null
git add "$file"
cd - &>/dev/null
+ git::_unlock
}
# Remove a static content file from git
@@ -23,9 +50,11 @@ git::rm () {
local file="$1"; shift
file=${file/$content_dir/.\/}
+ git::_lock
cd "$content_dir" &>/dev/null
git rm "$file"
cd - &>/dev/null
+ git::_unlock
}
# Commit all changes
@@ -37,6 +66,7 @@ git::commit () {
local -r content_dir="$CONTENT_BASE_DIR/$1"; shift
local -r message="$1"; shift
+ git::_lock
cd "$content_dir" &>/dev/null
set +e
git commit -a -m "$message"
@@ -47,4 +77,5 @@ git::commit () {
fi
set -e
cd - &>/dev/null
+ git::_unlock
}
diff --git a/lib/log.source.sh b/lib/log.source.sh
index 56c6587..2feb119 100644
--- a/lib/log.source.sh
+++ b/lib/log.source.sh
@@ -5,17 +5,18 @@ log () {
for message in "$@"; do
echo "$message"
- done | log::_pipe "$level"
+ done | log::_pipe "$level" $$
}
# Log a stream through a pipe.
log::pipe () {
- log::_pipe "$1"
+ log::_pipe "$1" $$
}
# Internal log implementation.
log::_pipe () {
local -r level="$1"; shift
+ local -r pid="$1"; shift
if [[ "$level" == VERBOSE && -z "$LOG_VERBOSE" ]]; then
return
@@ -25,6 +26,6 @@ log::_pipe () {
local -r stamp=$($DATE +%Y%m%d-%H%M%S)
while read -r line; do
- echo "$level|$stamp|$callee|$line" >&2
+ echo "$level|$stamp|$pid|$callee|$line" >&2
done
}