diff options
author | Holger Weiss <holger@zedat.fu-berlin.de> | 2013-10-08 19:22:43 (GMT) |
---|---|---|
committer | Holger Weiss <holger@zedat.fu-berlin.de> | 2013-10-08 19:22:43 (GMT) |
commit | 4240fabc23f587677cbd1cda518a6aa51e84e8d6 (patch) | |
tree | f036be3dd6a1fc9462bb4c968e0a112d8f457f8c /bin/build-snapshot | |
parent | 9fc0edaa353639c09a79299eebb6b895a81d63a9 (diff) | |
download | site-4240fabc23f587677cbd1cda518a6aa51e84e8d6.tar.gz |
build-snapshot: Remove only unreferenced old files
Make sure that no symlink points to an old snapshot before cleaning it
up. Also, don't check for dangling symlinks, as they should not occur
anymore.
Diffstat (limited to 'bin/build-snapshot')
-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" |