cleaner
changeset 6 129b39480dc5
parent 4 fb2455a007a7
child 7 a508df65c738
equal deleted inserted replaced
5:bef1e4dd8e85 6:129b39480dc5
    19     verbose => undef,
    19     verbose => undef,
    20     check => undef,
    20     check => undef,
    21 ); lock_keys(%o);
    21 ); lock_keys(%o);
    22 
    22 
    23 MAIN: {
    23 MAIN: {
       
    24     Getopt::Long::Configure qw(Bundling);
    24     GetOptions(
    25     GetOptions(
    25 	"n|dry!" => \$o{dry},
    26 	"n|dry!" => \$o{dry},
    26 	"v|verbose!" => \$o{verbose},
    27 	"v|verbose!" => \$o{verbose},
    27 	"c|check" => \$o{check},
    28 	"c|check" => \$o{check},
    28 	"h|help" => sub { pod2usage(-verbose => 1, -exit 0) },
    29 	"h|help" => sub { pod2usage(-verbose => 1, -exit 0) },
    38     my (%inuse, @idx);
    39     my (%inuse, @idx);
    39     #tie %idx, "DB_File" => $tmp->filename;
    40     #tie %idx, "DB_File" => $tmp->filename;
    40 
    41 
    41     find(sub {
    42     find(sub {
    42 	(-f) and (-M > 0) or return;
    43 	(-f) and (-M > 0) or return;
    43 	verbose("idx: $File::Find::name");
    44 	#verbose("idx: $File::Find::name");
    44 	push @idx, abs_path $_;
    45 	push @idx, abs_path $_;
    45 	foreach my $f (get_file_list($_)) {
    46 	foreach my $f (get_file_list($_)) {
    46 	    push @{$inuse{$f}} => $#idx;
    47 	    push @{$inuse{$f}} => $#idx;
    47 	}
    48 	}
    48     }, "$dir/idx");
    49     }, "$dir/idx");
    89     find(sub {
    90     find(sub {
    90 	(-f) and (-M > 0) or return;
    91 	(-f) and (-M > 0) or return;
    91 
    92 
    92 	# cut away the first part of the filename and
    93 	# cut away the first part of the filename and
    93 	# some optional extension
    94 	# some optional extension
    94 	$File::Find::name = abs_path $File::Find::name;
       
    95 	(my $rn = $File::Find::name) =~ s/^$dir\/data\/(.*?)(?:\..+)?$/$1/;
    95 	(my $rn = $File::Find::name) =~ s/^$dir\/data\/(.*?)(?:\..+)?$/$1/;
    96 	exists $inuse{$rn} and return;
    96 	exists $inuse{$rn} and return;
    97 
    97 
    98 	if ($o{dry}) {
    98 	if ($o{dry}) {
    99 	    verbose("(unlinking) $File::Find::name");
    99 	    verbose("(unlinking) abs_path $File::Find::name");
   100 	    return;
   100 	    return;
   101 	}
   101 	}
   102 
   102 
   103 	verbose("unlinking $File::Find::name");
   103 	verbose("unlinking abs_path $File::Find::name");
   104 	unlink $File::Find::name;
   104 	unlink abs_path $File::Find::name;
   105 
   105 
   106     }, "$dir/data");
   106     }, "$dir/data");
   107 
   107 
   108 }
   108 }
   109 
   109