This should fix the problem of the ftpdir-cleanup script removing the new package instead of the old one (FS#17058). The script makes $LOCK_TRIAL attempts, each separated by $LOCK_DELAY seconds, in getting the repo lock. If the lock is unsuccessful, the cleanup is skipped for that particular repo. Signed-off-by: Eric Bélanger <snowmaniscool@gmail.com> BTW, I didn't really tested this except the while loop logic. --- misc-scripts/ftpdir-cleanup | 28 +++++++++++++++++++++++++--- 1 files changed, 25 insertions(+), 3 deletions(-) diff --git a/misc-scripts/ftpdir-cleanup b/misc-scripts/ftpdir-cleanup index a185090..77f79e6 100755 --- a/misc-scripts/ftpdir-cleanup +++ b/misc-scripts/ftpdir-cleanup @@ -10,15 +10,35 @@ dest=$2 ############################################################ -. "$(dirname $0)/../db-functions" +. "$(dirname $0)/../db-functions" . "$(dirname $0)/../config" ${CLEANUP_DRYRUN} && echo 'dry run mode is active' ftppath_base="$FTP_BASE/$reponame/$FTP_OS_SUFFIX" +LOCK_DELAY=10 +LOCK_TRIAL=6 + for arch in ${ARCHES[@]}; do + IS_LOCKED=0 + count=0 + while [ $count -le $LOCK_TRIAL ]; do + if repo_lock $reponame $arch ; then + IS_LOCKED=1 + let count=$LOCK_TRIAL+1 + continue + fi + sleep $LOCK_DELAY + let count=$count+1 + done + + if [ $IS_LOCKED -eq 0 ]; then + echo "Failed to lock $reponame $arch repo" + exit 1 + fi + TMPDIR=$(mktemp -d /tmp/cleanup-XXXXXX) || exit 1 ftppath="$ftppath_base/$arch" MISSINGFILES="" @@ -80,10 +100,10 @@ for arch in ${ARCHES[@]}; do dbpkgname=$(grep -A1 '^%FILENAME%$' "${p}/desc" 2>/dev/null| tail -n1) if [ "${dbpkgname}" = "${pkgname}" ]; then continue 2 - fi + fi done EXTRAFILES="$EXTRAFILES $pkg" - done + done rm -rf ${TMPDIR} @@ -100,6 +120,8 @@ for arch in ${ARCHES[@]}; do fi done + repo_unlock $reponame $arch + #Make sure we've done *something* before outputting anything if [ -z "$DELETEFILES$DELETESYMLINKS$MISSINGFILES$EXTRAFILES" ]; then continue -- 1.7.0