From bdb738cc6b0d8948c7d16c2c1d17ef896cafa9ad Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sat, 18 Dec 2010 21:34:50 +0100 Subject: Progressbar with ETA etc. --- bin/hashl | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/bin/hashl b/bin/hashl index 78654db..b052eb8 100755 --- a/bin/hashl +++ b/bin/hashl @@ -12,6 +12,7 @@ use Digest::SHA qw(sha1_hex); use File::Find; use Getopt::Long; use Storable qw(nstore retrieve); +use Time::Progress; my $base = getcwd(); my $rel_paths = 1; @@ -19,6 +20,7 @@ my $read_size = (2 ** 20) * 4; # 4 MiB my $db_file = "$base/hashl.db"; my $total = 0; my $cur = 0; +my $timer; my $db; @@ -36,18 +38,6 @@ if (-r $db_file) { $db = retrieve($db_file); } -sub print_status { - my ($file) = @_; - local $| = 1; - - printf( - "\r\e[2K%d/%d %s", - $cur, - $total, - $file, - ); -} - sub get_total { my $file = $File::Find::name; if (-f $file and $file ne $db_file) { @@ -55,13 +45,14 @@ sub get_total { } } - sub process_file { my $file = $File::Find::name; my $path = $file; my ($size, $mtime) = (stat($file))[7,9]; my ($fh, $data); + local $| = 1; + if (not -f $file or $file eq $db_file) { return; } @@ -72,7 +63,7 @@ sub process_file { $file = substr($file, length($base) + 1); } - print_status($file); + print $timer->report("\r\e[2KUpdating: %p done, %L elapsed, %E remaining", $cur); if (exists($db->{$file}) and $db->{$file}->{'mtime'} == $mtime and @@ -98,6 +89,13 @@ sub process_file { if ($action eq 'update') { find(\&get_total, $base); + + $timer = Time::Progress->new(); + $timer->attr( + min => 1, + max => $total + ); + find(\&process_file, $base); nstore($db, $db_file); } -- cgit v1.2.3