summaryrefslogtreecommitdiffstats
path: root/db-functions
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2010-04-11 13:52:32 +0200
committerPierre Schmitz <pierre@archlinux.de>2010-04-11 13:52:32 +0200
commitad520b527f3c5d2471e4b471eca5439643a01939 (patch)
tree9ab80ba4aa1537fa53c89093761473e3a0c1a49c /db-functions
parent154b5301ff08ef29ff69afc17789a4f1a6a00c20 (diff)
downloaddbscripts-ad520b527f3c5d2471e4b471eca5439643a01939.tar.gz
dbscripts-ad520b527f3c5d2471e4b471eca5439643a01939.tar.xz
Fail if lock couldn't be obtained; Unlock the repos if ftpdir-cleanup fails
Diffstat (limited to 'db-functions')
-rw-r--r--db-functions17
1 files changed, 12 insertions, 5 deletions
diff --git a/db-functions b/db-functions
index d688df6..d0665b0 100644
--- a/db-functions
+++ b/db-functions
@@ -8,11 +8,12 @@
UMASK=""
set_umask () {
[ "$UMASK" == "" ] && UMASK="$(umask)"
+ export UMASK
umask 002
}
restore_umask () {
- umask $UMASK
+ umask $UMASK >/dev/null
}
repo_lock () { #repo_lock <repo-name> <arch> [timeout]
@@ -36,24 +37,30 @@ repo_lock () { #repo_lock <repo-name> <arch> [timeout]
while [ $_count -le $_trial ] || $_lockblock ; do
if ! mkdir "$LOCKDIR" >/dev/null 2>&1 ; then
_owner="$(/usr/bin/stat -c %U $LOCKDIR)"
- echo "error: Repo $1-$2 is already locked by $_owner. Retrying in $LOCK_DELAY seconds..." >&2
+ echo "warning: Repo $1-$2 is already locked by $_owner. Retrying in $LOCK_DELAY seconds..." >&2
else
set_umask
- break
+ return 0
fi
sleep $LOCK_DELAY
let _count=$_count+1
done
+
+ echo "error: Repo $1-$2 is already locked by $_owner. Giving up!" >&2
+ return 1
}
repo_unlock () { #repo_unlock <repo-name> <arch>
LOCKDIR="$TMPDIR/.repolock.$1.$2"
if [ ! -d "$LOCKDIR" ]; then
- echo "error: repo lock doesn't exist... something went terribly wrong!" >&2
+ echo "warning: Repo lock $1-$2 was not locked!" >&2
+ restore_umask
+ return 1
else
rmdir "$LOCKDIR"
+ restore_umask
+ return 0
fi
- restore_umask
}
# usage: _grep_pkginfo pkgfile pattern