From 725e7846f2133e443a6a789f645dc53aeb8bbd78 Mon Sep 17 00:00:00 2001 From: Levente Polyak <anthraxx@archlinux.org> Date: Sat, 23 Dec 2023 22:25:07 +0100 Subject: [PATCH] fix(repo_lock): remove superfluous exit pipe from repo_lock Also add explicit logging in case flock fails --- cron-jobs/ftpdir-cleanup | 2 +- cron-jobs/sourceballs | 5 ++++- db-functions | 7 ++++++- db-move | 4 ++-- db-remove | 2 +- db-repo-add | 7 ++++++- db-repo-remove | 7 ++++++- db-update | 2 +- testing2x | 7 ++++++- 9 files changed, 33 insertions(+), 10 deletions(-) diff --git a/cron-jobs/ftpdir-cleanup b/cron-jobs/ftpdir-cleanup index 1b5ebe0..90fe1ae 100755 --- a/cron-jobs/ftpdir-cleanup +++ b/cron-jobs/ftpdir-cleanup @@ -28,7 +28,7 @@ script_lock for repo in "${PKGREPOS[@]}"; do for arch in "${ARCHES[@]}"; do - repo_lock "${repo}" "${arch}" || exit 1 + repo_lock "${repo}" "${arch}" done done diff --git a/cron-jobs/sourceballs b/cron-jobs/sourceballs index f9ff780..b1da196 100755 --- a/cron-jobs/sourceballs +++ b/cron-jobs/sourceballs @@ -1,5 +1,8 @@ #!/bin/bash +set -eo pipefail +shopt -s nullglob + dirname="$(dirname "$(readlink -e "$0")")" . "${dirname}/../config" . "${dirname}/../db-functions" @@ -9,7 +12,7 @@ script_lock for repo in "${PKGREPOS[@]}"; do for arch in "${ARCHES[@]}"; do - repo_lock "${repo}" "${arch}" || exit 1 + repo_lock "${repo}" "${arch}" done done diff --git a/db-functions b/db-functions index 9973256..432ecce 100644 --- a/db-functions +++ b/db-functions @@ -117,6 +117,7 @@ acquire_lock() { local lock_mode=$1 local handle=$2 local fd + local ret # acquire fd from handle fd=$(acquire_fd "${handle}") @@ -129,7 +130,11 @@ acquire_lock() { if ! flock "${lock_mode}" --nonblock "${fd}"; then stat_busy "${@:3}" - flock "${lock_mode}" "${fd}" + if ! flock "${lock_mode}" "${fd}"; then + ret=$? + error "failed to lock %s: %s" "${handle}" "${ret}" + return ${ret} + fi stat_done fi } diff --git a/db-move b/db-move index ecdbc1e..2c5c9d2 100755 --- a/db-move +++ b/db-move @@ -47,8 +47,8 @@ fi # TODO: this might lock too much (architectures) for pkgarch in "${ARCHES[@]}"; do - repo_lock "${repo_to}" "${pkgarch}" || exit 1 - repo_lock "${repo_from}" "${pkgarch}" || exit 1 + repo_lock "${repo_to}" "${pkgarch}" + repo_lock "${repo_from}" "${pkgarch}" done # check if packages to be moved exist in version control and ftp dir diff --git a/db-remove b/db-remove index bb2ea21..bd27708 100755 --- a/db-remove +++ b/db-remove @@ -98,7 +98,7 @@ fi # lock repos for tarch in "${tarches[@]}"; do - repo_lock "$repo" "$tarch" || exit 1 + repo_lock "$repo" "$tarch" done declare -A remove_pkgbases diff --git a/db-repo-add b/db-repo-add index 6109d84..0d5f2d6 100755 --- a/db-repo-add +++ b/db-repo-add @@ -3,6 +3,11 @@ . "$(dirname "$(readlink -e "$0")")/config" . "$(dirname "$(readlink -e "$0")")/db-functions" +set -eo pipefail +shopt -s nullglob + +colorize + if (( $# < 3 )); then msg "usage: %s <repo> <arch> <pkgfile> ..." "${0##*/}" exit 1 @@ -25,7 +30,7 @@ else fi for tarch in "${tarches[@]}"; do - repo_lock "$repo" "$tarch" || exit 1 + repo_lock "$repo" "$tarch" done for tarch in "${tarches[@]}"; do diff --git a/db-repo-remove b/db-repo-remove index 8d2c6c7..c663867 100755 --- a/db-repo-remove +++ b/db-repo-remove @@ -3,6 +3,11 @@ . "$(dirname "$(readlink -e "$0")")/config" . "$(dirname "$(readlink -e "$0")")/db-functions" +set -eo pipefail +shopt -s nullglob + +colorize + if (( $# < 3 )); then msg "usage: %s <repo> <arch> <pkgname> ..." "${0##*/}" exit 1 @@ -25,7 +30,7 @@ else fi for tarch in "${tarches[@]}"; do - repo_lock "$repo" "$tarch" || exit 1 + repo_lock "$repo" "$tarch" done for tarch in "${tarches[@]}"; do diff --git a/db-update b/db-update index de63674..eb14d2c 100755 --- a/db-update +++ b/db-update @@ -107,7 +107,7 @@ done # TODO: this might lock too much (architectures) for repo in "${!staging[@]}"; do for pkgarch in "${ARCHES[@]}"; do - repo_lock "${repo}" "${pkgarch}" || exit 1 + repo_lock "${repo}" "${pkgarch}" done done diff --git a/testing2x b/testing2x index 215be39..bf955b1 100755 --- a/testing2x +++ b/testing2x @@ -3,6 +3,11 @@ . "$(dirname "$(readlink -e "$0")")/config" . "$(dirname "$(readlink -e "$0")")/db-functions" +set -eo pipefail +shopt -s nullglob + +colorize + if (( $# < 1 )); then msg "usage: %s <pkgname|pkgbase> ..." "${0##*/}" exit 1 @@ -12,7 +17,7 @@ fi script_lock for repo in "${TESTING_REPOS[@]}" "${STABLE_REPOS[@]}"; do for pkgarch in "${ARCHES[@]}"; do - repo_lock "${repo}" "${pkgarch}" || exit 1 + repo_lock "${repo}" "${pkgarch}" done done -- GitLab