cleaner works, imager uses nice stats
authorHeiko Schlittermann (JUMPER) <hs@schlittermann.de>
Sun, 24 Jul 2011 00:51:36 +0200
changeset 6 129b39480dc5
parent 5 bef1e4dd8e85
child 7 a508df65c738
cleaner works, imager uses nice stats
cleaner
imager
--- a/cleaner	Sun Jul 24 00:22:11 2011 +0200
+++ b/cleaner	Sun Jul 24 00:51:36 2011 +0200
@@ -21,6 +21,7 @@
 ); lock_keys(%o);
 
 MAIN: {
+    Getopt::Long::Configure qw(Bundling);
     GetOptions(
 	"n|dry!" => \$o{dry},
 	"v|verbose!" => \$o{verbose},
@@ -40,7 +41,7 @@
 
     find(sub {
 	(-f) and (-M > 0) or return;
-	verbose("idx: $File::Find::name");
+	#verbose("idx: $File::Find::name");
 	push @idx, abs_path $_;
 	foreach my $f (get_file_list($_)) {
 	    push @{$inuse{$f}} => $#idx;
@@ -91,17 +92,16 @@
 
 	# cut away the first part of the filename and
 	# some optional extension
-	$File::Find::name = abs_path $File::Find::name;
 	(my $rn = $File::Find::name) =~ s/^$dir\/data\/(.*?)(?:\..+)?$/$1/;
 	exists $inuse{$rn} and return;
 
 	if ($o{dry}) {
-	    verbose("(unlinking) $File::Find::name");
+	    verbose("(unlinking) abs_path $File::Find::name");
 	    return;
 	}
 
-	verbose("unlinking $File::Find::name");
-	unlink $File::Find::name;
+	verbose("unlinking abs_path $File::Find::name");
+	unlink abs_path $File::Find::name;
 
     }, "$dir/data");
 
--- a/imager	Sun Jul 24 00:22:11 2011 +0200
+++ b/imager	Sun Jul 24 00:51:36 2011 +0200
@@ -90,13 +90,25 @@
 
     my %stats = (
 	written => 0,
-	skipped => 0
+	skipped => 0,
+	todo => 1 + int($size / $o{blocksize}),
     );
 
+    local $SIG{ALRM} = sub {
+	my $speed = ($stats{written} + $stats{skipped}) / (time - $^T + 1);
+	say sprintf "# done %4.1f%% | %24s (%*d of $stats{todo}, written %*d, skipped %*d)",
+	    100 * (($stats{written}+$stats{skipped})/$stats{todo}), 
+	    ($speed ? (scalar localtime($^T + $stats{todo} / $speed)) : ""),
+	    length($stats{todo}) => $stats{written} + $stats{skipped},
+	    length($stats{todo}) => $stats{written},
+	    length($stats{todo}) => $stats{skipped};
+	alarm(5);
+    };
+    $SIG{ALRM}->();
+
     while (my $buffer = <$in>) {
 	my ($file, $ext, $cs);
 	$file = $cs = md5_hex($buffer);
-#	$file =~ s/((..)(..).*)/$2\/$3\/$1/g;
 	$file =~ s/(?<fn>(?<prefix>...).*)/$+{prefix}\/$+{fn}/g;
 	$ext = $o{compress} ? ".gz" : "";
 
@@ -125,9 +137,11 @@
 	    $stats{skipped}++;
 	}
 
-	say $log . sprintf "%3d%%" => 100 * ($. * $o{blocksize})/$size;
+	#say $log . sprintf "%3d%%" => 100 * ($. * $o{blocksize})/$size;
 	say {$index} $log;
     }
+    $SIG{ALRM}->();
+    alarm 0;
 
     say {$index} "# DONE (runtime " . (time() - $^T) . "s)";