build--sync: lock transaction with paclock(1)

An alternative to this is using paclock --run:

  paclock --run -- aur build--sync

Locking inside aur-build--sync keeps this implementation detail hidden,
e.g. compare the sudoers rules

  NOPASSWD: /usr/lib/aurutils/aur-build--sync

and

  NOPASSWD: /usr/bin/paclock --run aur build--sync

where in the latter the path is defined by AUR_LIB_DIR and aur(1)
instead of defined by system policy.
pull/1018/head
Alad Wenter 2022-08-07 12:47:37 +02:00
parent f571cb2056
commit 695f4ebbc1
1 changed files with 10 additions and 3 deletions

View File

@ -10,6 +10,12 @@ if (( ! $# )); then
exit 1
fi
# lock alpm database
lock_file=$(paclock --print)
lock_key=$argv0:$(hostname):$$
paclock --lockfile="$lock_file" --key="$lock_key"
# sync repository to pacman
arg_repo=$1
pacsync "$arg_repo"
pacsync "$arg_repo" --dbext=.files
@ -19,9 +25,7 @@ while IFS='/' read -r repo name; do
if [[ $repo == "$arg_repo" ]]; then
targets+=("$name")
fi
done < <(
pacman -Sup --print-format '%r/%n'
)
done < <(pacman -Sup --print-format '%r/%n')
wait $!
if (( ${#targets[@]} )); then
@ -29,4 +33,7 @@ if (( ${#targets[@]} )); then
pacman -S --noconfirm "${targets[@]}"
fi
# release lock
paclock --lockfile="$lock_file" --key="$lock_key" --unlock
# vim: set et sw=4 sts=4 ft=sh: