diff options
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 |