+.config/yt-dlp.conf
[nethome.git] / bin / rpmsafereduce
index dc793e9..71d2685 100755 (executable)
@@ -1,12 +1,15 @@
 #! /usr/bin/perl
 # rpmsafe|sort -u|rpmsafereduce >EXCLUDE-FILELIST
+use Carp;
+my $IGNORE_D;
+#$IGNORE_D=1; # Do not backup directory entry itself even if it is missing in rpms. 581692 -> 37998 vs. 44248
 use strict;
 use warnings;
 sub slashes($) {
   my($s)=@_;
   (my $sl=$s)=~tr{/}{}cd;
   $sl=length $sl;
-  $sl>=1 or die $_;
+  $sl>=1 or carp "<$s>";
   return $sl;
 }
 my(%d,%f,%t);
@@ -14,18 +17,20 @@ my $l;
 while (<>) {
   chomp;
   next if $_ eq "/";
-  die $_ if m{//};
-  m{^/} or die $_;
-  die $_ if m{/$};
-  die "sort -u: $l >= $_" if $l && $l ge $_;
+  carp $_ if m{//};
+  m{^/} or carp $_;
+  carp $_ if m{/$};
+  carp "sort -u: $l >= $_" if $l && $l ge $_;
   $l=$_;
   my $sl=slashes $_;
-  $d{$_}=$sl if -d;
+  $t{$_}=1,$d{$_}=$sl if -d;
   $f{$_}=$sl if -f;
-  s{/[^/]*$}{} or die $_;
+  s{/[^/]*$}{} or carp $_;
+  $d{$_}=$sl-1 if $IGNORE_D && $_ ne "";
   $t{$_}=1 if $d{$_};
 }
 my $time;
+my(%b);
 while (%t) {
   my @t=keys(%t);
   %t=();
@@ -37,8 +42,9 @@ while (%t) {
       print STDERR (@t+0)."    \r";
     }
     my $t=shift @t;
+    next if $b{$t};
     next if !$d{$t}&&!$f{$t};
-    opendir DIR,$t or die "$t: $!";
+    opendir DIR,$t or carp "$t: $!";
     my $ok=1;
     local $_;
     my @d;
@@ -51,18 +57,20 @@ while (%t) {
       $ok=0;
       last;
     }
-    closedir DIR or die "$t: $!";
-    next if !$ok;
+    closedir DIR or carp "$t: $!";
+    if (!$ok) {
+      do { $b{$t}=1; } while $t=~s{/[^/]*$}{};
+      next;
+    }
     for my $d (@d) {
-      delete $f{"$t/$d"};
-      delete $t{"$t/$d"};
+      $b{"$t/$d"}=1;
     }
     $f{$t}=slashes $t;
-    $t=~s{/[^/]*$}{} or die $t;
-    $d{$t}=slashes $t;
-    $t{$t}=1;
+    $t=~s{/[^/]*$}{} or carp $t;
+    $d{$t}=slashes $t if $IGNORE_D && $t ne "";
+    $t{$t}=1 if $d{$t};
   }
 }
 for my $f (sort keys(%f)) {
-  print "$f\n";
+  print "$f\n" if !$b{$f};
 }