From b8e1bdbff60ac6fa2a280a68334203b6b4be3ec6 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 20 Aug 2020 11:30:29 +0100 Subject: [PATCH] expire-iso8601: provide --rename-only Signed-off-by: Ian Jackson --- scripts/expire-iso8601 | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts/expire-iso8601 b/scripts/expire-iso8601 index 8ec0aef..af1543c 100755 --- a/scripts/expire-iso8601 +++ b/scripts/expire-iso8601 @@ -28,6 +28,7 @@ options: longer apart than specified; default is 0.1 unit -n do not really delete -r recursive removal (rm -r) + --rename-only rename to *.rm, but do not delete --help example: /home/ian/junk/expire-iso8601 14x1 4x7 @@ -55,7 +56,7 @@ $|=1; our @oldfiles; our @files; -our $rm = 1; +our $enable = 2; our $recurse = 1; our $unit = 86400; our $slop; @@ -194,7 +195,7 @@ sub flag ($) { sub do_rm ($) { my ($fn) = @_; - if ($rm) { + if ($enable >= 2) { my $r= system 'rm', ($recurse ? ('-r') : ()), "--", $fn; die "run rm: $!\n" unless defined($r) && $r >= 0; exit 4 if $r; @@ -215,7 +216,7 @@ sub implement () { next if @{$_->{U}}; printf "remove %s - age %.1f\n", $_->{F}, $_->{A}; - if ($rm) { + if ($enable >= 1) { my $tmp = "$_->{F}.rm"; rename $_->{F}, $tmp or die "rename $_->{F} to $tmp: $!\n"; do_rm($tmp); @@ -230,13 +231,15 @@ while (@ARGV && $ARGV[0] =~ m/^-/) { last if $_ eq '-' || $_ eq '--'; if (m/^-[^-]/) { while (m/^-./) { - if (s/^-n/-/) { $rm=0; } + if (s/^-n/-/) { $enable=0; } elsif (s/-r/-/) { $recurse=1; } elsif (s/-D/-/) { $debug++; } elsif (s/-u(\d+)$//) { $unit=$1; } elsif (s/-s(\d+)$//) { $slop=$1; } else { badusage "unknown short option $_" } } + } elsif (m/^--rename-only$/) { + $enable=1; } elsif (m/^--help$/) { print $usage or die $!; exit 0; -- 2.30.2