diff options
author | Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org> | 2017-04-28 09:58:51 +0000 |
---|---|---|
committer | Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org> | 2017-05-04 10:47:36 +0000 |
commit | 15bb8018ddf053cc717361f38aa404fd55d25ba3 (patch) | |
tree | 84eab34f0cd8c03a9bdd78c244af50683f3dff22 /tcwg-cleanup-stale-workspaces.sh | |
parent | 5191e825baed3a91ea98f33318b85e85e832a209 (diff) |
tcwg-cleanup-stale-workspaces.sh: Use better heuristic to find workspaces
Workspaces are detected as first directory (depth-wise) which has
regular files.
Change-Id: Ic6a735b22965565f599d2f07ce5d1ef17c8174dd
Diffstat (limited to 'tcwg-cleanup-stale-workspaces.sh')
-rwxr-xr-x | tcwg-cleanup-stale-workspaces.sh | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/tcwg-cleanup-stale-workspaces.sh b/tcwg-cleanup-stale-workspaces.sh index af1c21bf..a41ff586 100755 --- a/tcwg-cleanup-stale-workspaces.sh +++ b/tcwg-cleanup-stale-workspaces.sh @@ -5,14 +5,13 @@ set -e days=3 dry_run=false workspace_top=$HOME/workspace -maxdepth=1 while [ $# -gt 0 ]; do case $1 in --days) days="$2"; shift ;; --dry_run) dry_run="$2"; shift ;; --workspace_top) workspace_top="$2"; shift ;; - --maxdepth) maxdepth="$2"; shift ;; + --maxdepth) shift ;; *) echo "ERROR: Wrong option: $1"; exit 1 ;; esac shift @@ -30,13 +29,24 @@ ls -ld $workspace_top/* || true df -h $workspace_top || true du -hsc $workspace_top/* || true -# Semantics of find's mtime "+N" stands for N+1 days old or older. -days_1=$(($days-1)) +find_workspaces () +{ + local cur_dir="$1" + + if [ x"$(find $cur_dir -maxdepth 1 -type f | wc -l)" != x"0" ]; then + echo $cur_dir + else + # "tail -n +2" is to remove $cur_dir from find output. + for dir in $(find $cur_dir -maxdepth 1 -type d | tail -n +2); do + find_workspaces "$dir" + done + fi +} # Handle dirs with whitespaces by setting $IFS to newline. SAVEIFS=$IFS IFS=$'\n' -dirs=($(find $workspace_top/ -maxdepth $maxdepth -type d -mtime +$days_1)) +dirs=($(find_workspaces "$workspace_top")) IFS=$SAVEIFS rm_dirs=() |