diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2013-06-15 11:20:37 -0600 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2013-06-15 11:20:37 -0600 |
commit | a8c95177c7f9bab8cb7e697c6e925b2fb1c5d342 (patch) | |
tree | ed43f04c4e2aaab033aba23fae4ead687555ca9b | |
parent | a7ee45d6259e84628599f721abc297f935504fee (diff) | |
parent | a7a05deb37b3db6aa3606f488467f621c40ce32d (diff) |
Merge commit 'a7a0': merge our and their lock functions
Arch's have shorter names, and properly escape the filename.
Ours create the directories, and check if the locks are already open.
The best of both worlds.
When merging the usages of them, I used arch's messages. Ours are too long,
even if they are more informative.
-rw-r--r-- | archbuild.in | 3 | ||||
-rw-r--r-- | lib/common.sh | 90 | ||||
-rw-r--r-- | makechrootpkg.in | 7 | ||||
-rw-r--r-- | mkarchroot.in | 18 |
4 files changed, 50 insertions, 68 deletions
diff --git a/archbuild.in b/archbuild.in index 38fb8bf..8e272a1 100644 --- a/archbuild.in +++ b/archbuild.in @@ -51,7 +51,7 @@ if ${clean_first} || [[ ! -d "${chroots}/${repo}-${arch}" ]]; then [[ -d $copy ]] || continue msg2 "Deleting chroot copy '$(basename "${copy}")'..." - lock_open_write 9 "$copy.lock" "Locking chroot copy '$copy'" + lock 9 "$copy.lock" "Locking chroot copy '$copy'" if [[ "$(stat -f -c %T "${copy}")" == btrfs ]]; then { type -P btrfs && btrfs subvolume delete "${copy}"; } &>/dev/null @@ -68,6 +68,7 @@ if ${clean_first} || [[ ! -d "${chroots}/${repo}-${arch}" ]]; then "${chroots}/${repo}-${arch}/root" \ "${base_packages[@]}" || abort else + lock 9 "${chroots}/${repo}-${arch}/root.lock" "Locking clean chroot" setarch ${arch} arch-nspawn \ -C "@pkgdatadir@/pacman-${repo}.conf" \ -M "@pkgdatadir@/makepkg-${arch}.conf" \ diff --git a/lib/common.sh b/lib/common.sh index 9f537c7..c6c5993 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -107,48 +107,76 @@ in_array() { } ## -# usage : lock_open_write( $fd, $path.lock, $wait_message ) +# usage : get_full_version( [$pkgname] ) +# return : full version spec, including epoch (if necessary), pkgver, pkgrel ## -lock_open_write() { +get_full_version() { + # set defaults if they weren't specified in buildfile + pkgbase=${pkgbase:-${pkgname[0]}} + epoch=${epoch:-0} + if [[ -z $1 ]]; then + if [[ $epoch ]] && (( ! $epoch )); then + echo $pkgver-$pkgrel + else + echo $epoch:$pkgver-$pkgrel + fi + else + for i in pkgver pkgrel epoch; do + local indirect="${i}_override" + eval $(declare -f package_$1 | sed -n "s/\(^[[:space:]]*$i=\)/${i}_override=/p") + [[ -z ${!indirect} ]] && eval ${indirect}=\"${!i}\" + done + if (( ! $epoch_override )); then + echo $pkgver_override-$pkgrel_override + else + echo $epoch_override:$pkgver_override-$pkgrel_override + fi + fi +} + +## +# usage : lock( $fd, $file, $message ) +## +lock() { local fd=$1 - local path=$2 - local msg=$3 + local file=$2 + local mesg=$3 # Only reopen the FD if it wasn't handed to us - if [[ "$(readlink -f /dev/fd/$fd)" != "$(readlink -f "${path}")" ]]; then - mkdir -p "${path%/*}" - eval "exec $fd>${path}" + if [[ "$(readlink -f /dev/fd/$fd)" != "$(readlink -f "$file")" ]]; then + mkdir -p "${file%/*}" + eval "exec $fd>"'"$file"' fi if ! flock -n $fd; then - stat_busy "$msg" + stat_busy "$mesg" flock $fd stat_done fi } ## -# usage : lock_open_read( $fd, $path.lock, $wait_message ) +# usage : slock( $fd, $file, $message ) ## -lock_open_read() { +slock() { local fd=$1 - local path=$2 - local msg=$3 + local file=$2 + local mesg=$3 # Only reopen the FD if it wasn't handed to us - if [[ "$(readlink -f /dev/fd/$fd)" != "$(readlink -f "${path}")" ]]; then - mkdir -p "${path%/*}" - eval "exec $fd>${path}" + if [[ "$(readlink -f /dev/fd/$fd)" != "$(readlink -f "$file")" ]]; then + mkdir -p "${file%/*}" + eval "exec $fd>"'"$file"' fi + eval "exec $fd>"'"$file"' if ! flock -sn $fd; then - stat_busy "$msg" + stat_busy "$mesg" flock -s $fd stat_done fi } - ## # usage : lock_close( $fd ) ## @@ -156,31 +184,3 @@ lock_close() { local fd=$1 eval "exec $fd>&-" } - -## -# usage : get_full_version( [$pkgname] ) -# return : full version spec, including epoch (if necessary), pkgver, pkgrel -## -get_full_version() { - # set defaults if they weren't specified in buildfile - pkgbase=${pkgbase:-${pkgname[0]}} - epoch=${epoch:-0} - if [[ -z $1 ]]; then - if [[ $epoch ]] && (( ! $epoch )); then - echo $pkgver-$pkgrel - else - echo $epoch:$pkgver-$pkgrel - fi - else - for i in pkgver pkgrel epoch; do - local indirect="${i}_override" - eval $(declare -f package_$1 | sed -n "s/\(^[[:space:]]*$i=\)/${i}_override=/p") - [[ -z ${!indirect} ]] && eval ${indirect}=\"${!i}\" - done - if (( ! $epoch_override )); then - echo $pkgver_override-$pkgrel_override - else - echo $epoch_override:$pkgver_override-$pkgrel_override - fi - fi -} diff --git a/makechrootpkg.in b/makechrootpkg.in index a0941b4..b68dc0a 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -120,15 +120,12 @@ umask 0022 chroottype=$(stat -f -c %T "$chrootdir") # Lock the chroot we want to use. We'll keep this lock until we exit. -# Note this is the same FD number as in mkarchroot -lock_open_write 9 "$copydir.lock" \ - "Waiting for existing lock on chroot copy to be released: [$copy]" +lock 9 "$copydir.lock" "Locking chroot copy [$copy]" if [[ ! -d $copydir ]] || $clean_first; then # Get a read lock on the root chroot to make # sure we don't clone a half-updated chroot - lock_open_read 8 "$chrootdir/root.lock" \ - "Waiting for existing lock on clean chroot to be released" + slock 8 "$chrootdir/root.lock" "Locking clean chroot" stat_busy "Creating clean working copy [$copy]" if [[ "$chroottype" == btrfs ]]; then diff --git a/mkarchroot.in b/mkarchroot.in index 68db64c..970bbb9 100644 --- a/mkarchroot.in +++ b/mkarchroot.in @@ -49,29 +49,13 @@ else cache_dirs=(${cache_dir}) fi -# {{{ functions -chroot_lock () { - # Only reopen the FD if it wasn't handed to us - if [[ $(readlink -f /dev/fd/9) != "${working_dir}.lock" ]]; then - exec 9>"${working_dir}.lock" - fi - - # Lock the chroot. Take note of the FD number. - if ! flock -n 9; then - stat_busy "Locking chroot" - flock 9 - stat_done - fi -} -# }}} - umask 0022 [[ -e $working_dir ]] && die "Working directory '$working_dir' already exists" mkdir -p "$working_dir" -chroot_lock +lock 9 "${working_dir}.lock" "Locking chroot" if [[ $(stat -f -c %T "$working_dir") == btrfs ]]; then rmdir "$working_dir" |