Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archbuild.in9
-rw-r--r--lib/common.sh74
-rw-r--r--makechrootpkg.in23
3 files changed, 73 insertions, 33 deletions
diff --git a/archbuild.in b/archbuild.in
index 7872cd4..38fb8bf 100644
--- a/archbuild.in
+++ b/archbuild.in
@@ -51,19 +51,14 @@ if ${clean_first} || [[ ! -d "${chroots}/${repo}-${arch}" ]]; then
[[ -d $copy ]] || continue
msg2 "Deleting chroot copy '$(basename "${copy}")'..."
- exec 9>"$copydir.lock"
- if ! flock -n 9; then
- stat_busy "Locking chroot copy '$copy'"
- flock 9
- stat_done
- fi
+ lock_open_write 9 "$copy.lock" "Locking chroot copy '$copy'"
if [[ "$(stat -f -c %T "${copy}")" == btrfs ]]; then
{ type -P btrfs && btrfs subvolume delete "${copy}"; } &>/dev/null
fi
rm -rf --one-file-system "${copy}"
done
- exec 9>&-
+ lock_close 9
rm -rf --one-file-system "${chroots}/${repo}-${arch}"
mkdir -p "${chroots}/${repo}-${arch}"
diff --git a/lib/common.sh b/lib/common.sh
index b39bbbc..9f537c7 100644
--- a/lib/common.sh
+++ b/lib/common.sh
@@ -2,7 +2,7 @@
export LANG=C
# check if messages are to be printed using color
-unset ALL_OFF BOLD BLUE GREEN RED YELLOW
+declare ALL_OFF= BOLD= BLUE= GREEN= RED= YELLOW=
if [[ -t 2 ]]; then
# prefer terminal safe colored and bold text when tput is supported
if tput setaf 0 &>/dev/null; then
@@ -40,12 +40,12 @@ msg2() {
warning() {
local mesg=$1; shift
- printf "${YELLOW}==> WARNING:${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
+ printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
}
error() {
local mesg=$1; shift
- printf "${RED}==> ERROR:${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
+ printf "${RED}==> $(gettext "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
}
stat_busy() {
@@ -54,16 +54,22 @@ stat_busy() {
}
stat_done() {
- printf "${BOLD}done${ALL_OFF}\n" >&2
+ printf "${BOLD}$(gettext "done")${ALL_OFF}\n" >&2
}
+_setup_workdir=false
setup_workdir() {
- [[ -z $WORKDIR ]] && WORKDIR=$(mktemp -d --tmpdir "${0##*/}.XXXXXXXXXX")
+ [[ -z ${WORKDIR:-} ]] && WORKDIR=$(mktemp -d --tmpdir "${0##*/}.XXXXXXXXXX")
+ _setup_workdir=true
+ trap 'trap_abort' INT QUIT TERM HUP
+ trap 'trap_exit' EXIT
}
cleanup() {
- [[ -n $WORKDIR ]] && rm -rf "$WORKDIR"
- [[ $1 ]] && exit $1
+ if [[ -n ${WORKDIR:-} ]] && $_setup_workdir; then
+ rm -rf "$WORKDIR"
+ fi
+ [[ -n ${1:-} ]] && exit $1
}
abort() {
@@ -86,9 +92,6 @@ die() {
cleanup 1
}
-trap 'trap_abort' INT QUIT TERM HUP
-trap 'trap_exit' EXIT
-
##
# usage : in_array( $needle, $haystack )
# return : 0 - found
@@ -104,6 +107,57 @@ in_array() {
}
##
+# usage : lock_open_write( $fd, $path.lock, $wait_message )
+##
+lock_open_write() {
+ local fd=$1
+ local path=$2
+ local msg=$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}"
+ fi
+
+ if ! flock -n $fd; then
+ stat_busy "$msg"
+ flock $fd
+ stat_done
+ fi
+}
+
+##
+# usage : lock_open_read( $fd, $path.lock, $wait_message )
+##
+lock_open_read() {
+ local fd=$1
+ local path=$2
+ local msg=$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}"
+ fi
+
+ if ! flock -sn $fd; then
+ stat_busy "$msg"
+ flock -s $fd
+ stat_done
+ fi
+}
+
+
+##
+# usage : lock_close( $fd )
+##
+lock_close() {
+ local fd=$1
+ eval "exec $fd>&-"
+}
+
+##
# usage : get_full_version( [$pkgname] )
# return : full version spec, including epoch (if necessary), pkgver, pkgrel
##
diff --git a/makechrootpkg.in b/makechrootpkg.in
index bf4034e..a0941b4 100644
--- a/makechrootpkg.in
+++ b/makechrootpkg.in
@@ -121,23 +121,14 @@ 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
-exec 9>"$copydir.lock"
-if ! flock -n 9; then
- stat_busy "Locking chroot copy [$copy]"
- flock 9
- stat_done
-fi
+lock_open_write 9 "$copydir.lock" \
+ "Waiting for existing lock on chroot copy to be released: [$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
- exec 8>"$chrootdir/root.lock"
-
- if ! flock -sn 8; then
- stat_busy "Locking clean chroot"
- flock -s 8
- stat_done
- fi
+ lock_open_read 8 "$chrootdir/root.lock" \
+ "Waiting for existing lock on clean chroot to be released"
stat_busy "Creating clean working copy [$copy]"
if [[ "$chroottype" == btrfs ]]; then
@@ -154,7 +145,7 @@ if [[ ! -d $copydir ]] || $clean_first; then
stat_done
# Drop the read lock again
- exec 8>&-
+ lock_close 8
fi
if [[ -n "${install_pkgs[*]}" ]]; then
@@ -289,11 +280,11 @@ EOF
chmod +x "$copydir/chrootbuild"
if arch-nspawn "$copydir" /chrootbuild; then
+ mkdir -p "$copydir/repo"
for pkgfile in "$copydir"/pkgdest/*.pkg.tar.?z; do
if $add_to_db; then
- mkdir -p "$copydir/repo"
+ cp "$pkgfile" "$copydir/repo"
pushd "$copydir/repo" >/dev/null
- cp "$pkgfile" .
repo-add repo.db.tar.gz "${pkgfile##*/}"
popd >/dev/null
fi