chiark / gitweb /
expire-iso8601: provide --rename-only
[chiark-utils.git] / scripts / expire-iso8601
index 8ec0aef11544a1c8c8c86ac52414a085eb07c1c1..af1543ceb3439b78d8cb923ce5b76ae83ab8929a 100755 (executable)
@@ -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;