diff options
-rw-r--r-- | db-functions | 17 | ||||
-rwxr-xr-x | db-move | 4 | ||||
-rwxr-xr-x | db-remove | 2 | ||||
-rwxr-xr-x | db-update | 2 | ||||
-rwxr-xr-x | misc-scripts/ftpdir-cleanup | 13 |
5 files changed, 28 insertions, 10 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 @@ -44,8 +44,8 @@ die() { trap ctrl_c 2 trap cleanup 0 -repo_lock $repoto $_arch -repo_lock $repofrom $_arch +repo_lock $repoto $_arch || exit 1 +repo_lock $repofrom $_arch || exit 1 /bin/mkdir -p "$WORKDIR" @@ -40,7 +40,7 @@ die() { trap ctrl_c 2 trap cleanup 0 -repo_lock $reponame $_arch +repo_lock $reponame $_arch || exit 1 /bin/mkdir -p "$WORKDIR" @@ -141,7 +141,7 @@ for current_arch in ${ARCHES[@]}; do svnrepo="$reponame-$current_arch" - repo_lock $reponame $current_arch + repo_lock $reponame $current_arch || continue /bin/mkdir -p "$WORKDIR/build" cd "$WORKDIR" diff --git a/misc-scripts/ftpdir-cleanup b/misc-scripts/ftpdir-cleanup index 4c559b9..d5f5737 100755 --- a/misc-scripts/ftpdir-cleanup +++ b/misc-scripts/ftpdir-cleanup @@ -13,13 +13,24 @@ dest=$2 . "$(dirname $0)/../db-functions" . "$(dirname $0)/../config" +cleanup() { + trap '' 2 15 + for arch in ${ARCHES[@]}; do + repo_unlock $reponame $arch + done + exit 1 +} + +trap cleanup 2 +trap cleanup 15 + ${CLEANUP_DRYRUN} && echo 'dry run mode is active' ftppath_base="$FTP_BASE/$reponame/$FTP_OS_SUFFIX" for arch in ${ARCHES[@]}; do - repo_lock $reponame $arch $LOCK_TIMEOUT + repo_lock $reponame $arch $LOCK_TIMEOUT || continue TMPDIR=$(mktemp -d /tmp/cleanup-XXXXXX) || exit 1 ftppath="$ftppath_base/$arch" |