summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorHolger Weiss <holger@zedat.fu-berlin.de>2013-10-08 19:22:43 (GMT)
committerHolger Weiss <holger@zedat.fu-berlin.de>2013-10-08 19:22:43 (GMT)
commit4240fabc23f587677cbd1cda518a6aa51e84e8d6 (patch)
treef036be3dd6a1fc9462bb4c968e0a112d8f457f8c /bin
parent9fc0edaa353639c09a79299eebb6b895a81d63a9 (diff)
downloadsite-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')
-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"