summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbin/build-snapshot26
1 files changed, 24 insertions, 2 deletions
diff --git a/bin/build-snapshot b/bin/build-snapshot
index 43c6293..5633abd 100755
--- a/bin/build-snapshot
+++ b/bin/build-snapshot
@@ -59,6 +59,29 @@ create_snapshot()
59 cd "$OLDPWD" 59 cd "$OLDPWD"
60} 60}
61 61
62rm_old_snapshots()
63{
64 snapshot_dir=$1
65 keep_days=$2
66 link_targets=$(find "$snapshot_dir" -type l -exec readlink '{}' ';')
67
68 find "$snapshot_dir" -type f -mtime "+$((keep_days - 1))" -print \
69 | while read file
70 do
71 referenced=0
72
73 for link_target in $link_targets
74 do
75 if [ "$link_target" = "$file" ]
76 then
77 referenced=1
78 break
79 fi
80 done
81 test $referenced -eq 1 || rm -f "$file"
82 done
83}
84
62if [ $# -eq 1 ] && [ "x$1" = 'x-h' -o "x$1" = 'x--help' ] 85if [ $# -eq 1 ] && [ "x$1" = 'x-h' -o "x$1" = 'x--help' ]
63then 86then
64 echo "Usage: $myself [branch ...]" 87 echo "Usage: $myself [branch ...]"
@@ -82,7 +105,6 @@ do
82done 105done
83 106
84cd "$OLDPWD" 107cd "$OLDPWD"
85find "$snapshot_dir" -type f -mtime "+$((keep_days - 1))" -exec rm -f '{}' '+' 108rm_old_snapshots "$snapshot_dir" "$keep_days"
86find "$snapshot_dir" -type l '!' -exec test -e '{}' ';' -exec rm -f '{}' '+'
87trap - EXIT 109trap - EXIT
88rm -rf "$temp_dir" 110rm -rf "$temp_dir"