diff options
author | Christophe Lyon <christophe.lyon@linaro.org> | 2019-03-22 10:13:14 +0000 |
---|---|---|
committer | Christophe Lyon <christophe.lyon@linaro.org> | 2019-03-22 20:55:01 +0000 |
commit | 2179403ebfa2990eeae4d1b15b3f6d542d3b5346 (patch) | |
tree | 9a491cf324eaf591172d2fd5b7823fbf8006171a /tcwg-cleanup-stale-workspaces.sh | |
parent | c98ba8dcfcce77d78cd68dedfa8c2bfd17ff01fc (diff) |
docker-run.sh, tcwg-cleanup-stale-workspaces.sh: Use flock
In order to be able to remove old workspaces, this patch uses flock to
make sure the renaming for $dir to $dir.bak does not happen while a
build is in progress.
To achieve that, both the renaming and the command executed by
docker-run.sh use this exclusive lock.
Unfortunately, this does not prevent race conditions with builds not
relying on docker-run.sh, so such builds should either use flock or
switch to using docker-run.sh.
Change-Id: Ib8a7cbf33819d81f858c25f62a091b0b94c48d21
Diffstat (limited to 'tcwg-cleanup-stale-workspaces.sh')
-rwxr-xr-x | tcwg-cleanup-stale-workspaces.sh | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/tcwg-cleanup-stale-workspaces.sh b/tcwg-cleanup-stale-workspaces.sh index b601958a..432ddcfa 100755 --- a/tcwg-cleanup-stale-workspaces.sh +++ b/tcwg-cleanup-stale-workspaces.sh @@ -32,6 +32,9 @@ find_workspaces () { local cur_dir="$1" + # If a directory contains no file (ie. only subdirs), consider it + # is part of the workspace hierarchy: only directories with at + # least one file can be top-level workspaces. if [ x"$(find $cur_dir -maxdepth 1 -type f | wc -l)" != x"0" ]; then echo $cur_dir else @@ -54,7 +57,9 @@ for dir in "${dirs[@]}"; do if ! $dry_run; then # Move directory out of the way as quickly as possible to minimize # chance of parallel build starting in this directory. - mv "$dir" "$dir.bak" + # Use a lock to avoid a race condition with a competing + # build. + flock "$dir" mv "$dir" "$dir.bak" fi rm_dirs=("${rm_dirs[@]}" "$dir.bak") fi |