fetch: use per-package locks for destructive operations

pull/1017/head
Alad Wenter 2022-07-29 14:08:13 +02:00
parent 286d6c800f
commit aaf7319b5f
1 changed files with 6 additions and 0 deletions

View File

@ -119,6 +119,7 @@ if (( ! $# )); then
exit 1
fi
# XXX: race with concurrent processes
if [[ -v results_file ]]; then
: >"$results_file" || exit 1 # truncate file
fi
@ -160,6 +161,10 @@ for pkg in "${packages[@]}"; do
continue
elif [[ -d $pkg/.git ]]; then
# Per-package lock
exec {fd}< "$pkg"/.git
flock --wait 5 "$fd" || exit 1
# Avoid issues with filesystem boundaries (#274)
git() { command git -C "$pkg" "$@"; }
@ -213,6 +218,7 @@ for pkg in "${packages[@]}"; do
if [[ -v results_file ]]; then
results "$sync_pkg" "$orig_head" "$head" "$PWD/$pkg" "$results_file"
fi
exec {fd}<&- # release lock
# Otherwise, try to clone anew
else