From 4240fabc23f587677cbd1cda518a6aa51e84e8d6 Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Tue, 8 Oct 2013 21:22:43 +0200 Subject: 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. 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() cd "$OLDPWD" } +rm_old_snapshots() +{ + snapshot_dir=$1 + keep_days=$2 + link_targets=$(find "$snapshot_dir" -type l -exec readlink '{}' ';') + + find "$snapshot_dir" -type f -mtime "+$((keep_days - 1))" -print \ + | while read file + do + referenced=0 + + for link_target in $link_targets + do + if [ "$link_target" = "$file" ] + then + referenced=1 + break + fi + done + test $referenced -eq 1 || rm -f "$file" + done +} + if [ $# -eq 1 ] && [ "x$1" = 'x-h' -o "x$1" = 'x--help' ] then echo "Usage: $myself [branch ...]" @@ -82,7 +105,6 @@ do done cd "$OLDPWD" -find "$snapshot_dir" -type f -mtime "+$((keep_days - 1))" -exec rm -f '{}' '+' -find "$snapshot_dir" -type l '!' -exec test -e '{}' ';' -exec rm -f '{}' '+' +rm_old_snapshots "$snapshot_dir" "$keep_days" trap - EXIT rm -rf "$temp_dir" -- cgit v0.10-9-g596f