diff options
-rwxr-xr-x | bin/build-snapshot | 26 |
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 | ||
62 | rm_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 | |||
62 | if [ $# -eq 1 ] && [ "x$1" = 'x-h' -o "x$1" = 'x--help' ] | 85 | if [ $# -eq 1 ] && [ "x$1" = 'x-h' -o "x$1" = 'x--help' ] |
63 | then | 86 | then |
64 | echo "Usage: $myself [branch ...]" | 87 | echo "Usage: $myself [branch ...]" |
@@ -82,7 +105,6 @@ do | |||
82 | done | 105 | done |
83 | 106 | ||
84 | cd "$OLDPWD" | 107 | cd "$OLDPWD" |
85 | find "$snapshot_dir" -type f -mtime "+$((keep_days - 1))" -exec rm -f '{}' '+' | 108 | rm_old_snapshots "$snapshot_dir" "$keep_days" |
86 | find "$snapshot_dir" -type l '!' -exec test -e '{}' ';' -exec rm -f '{}' '+' | ||
87 | trap - EXIT | 109 | trap - EXIT |
88 | rm -rf "$temp_dir" | 110 | rm -rf "$temp_dir" |