From ad520b527f3c5d2471e4b471eca5439643a01939 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sun, 11 Apr 2010 13:52:32 +0200 Subject: Fail if lock couldn't be obtained; Unlock the repos if ftpdir-cleanup fails --- db-functions | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'db-functions') 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 [timeout] @@ -36,24 +37,30 @@ repo_lock () { #repo_lock [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 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 -- cgit v1.2.3-24-g4f1b