summaryrefslogtreecommitdiff
path: root/bin/hashl
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2011-01-02 00:29:02 +0100
committerDaniel Friesel <derf@finalrewind.org>2011-01-02 00:29:02 +0100
commitcd1e903ece481f25c57852c8e467f1fea298bdb0 (patch)
treed6c2248665c8bc7fb991f767bed14e33b9c97a38 /bin/hashl
parent04ab1adad34e69c5ef44884c5d85d366623eb90b (diff)
Add -n option, fix hashl find-new <directory>
Diffstat (limited to 'bin/hashl')
-rwxr-xr-xbin/hashl22
1 files changed, 18 insertions, 4 deletions
diff --git a/bin/hashl b/bin/hashl
index af070a9..f295d6f 100755
--- a/bin/hashl
+++ b/bin/hashl
@@ -22,6 +22,7 @@ my $read_size = (2 ** 20) * 4; # 4 MiB
my $db_file = '.hashl.db';
my $total = 0;
my $cur = 0;
+my $show_progress = 1;
my $timer;
my $incoming_dir;
my ($find_ref, $find_db_write);
@@ -34,6 +35,7 @@ STDOUT->autoflush(1);
GetOptions(
'd|database=s' => \$db_file,
+ 'n|no-progress' => sub { $show_progress = 0 },
's|read-size=i' => sub { $read_size = $_[1] * 1024 },
) or usage();
@@ -172,7 +174,12 @@ sub process_file {
$cur++;
- print $timer->report("\r\e[2KUpdating: %p done, %L elapsed, %E remaining", $cur);
+ if ($show_progress) {
+ print $timer->report(
+ "\r\e[2KUpdating: %p done, %L elapsed, %E remaining",
+ $cur,
+ );
+ }
&{$code}($file, $path);
@@ -229,7 +236,14 @@ sub mkdirs {
}
sub prepare_db_run {
- find(\&get_total, $base);
+ my ($dir) = @_;
+ $dir //= $base;
+
+ if (not $show_progress) {
+ return;
+ }
+
+ find(\&get_total, $dir);
$timer = Time::Progress->new();
$timer->attr(
@@ -262,12 +276,12 @@ sub cmd_find_new {
$new_dir //= $base;
- prepare_db_run();
-
if (substr($new_dir, 0, 1) ne '/') {
$new_dir = $base . '/' . $new_dir;
}
+ prepare_db_run($new_dir);
+
$find_ref = \&db_find_new;
$find_db_write = 0;
find(\&process_file, $new_dir);