From cdff687c62bbb2a7c8c7bd2e4eecfd1186d7bc44 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sat, 18 Dec 2010 19:58:39 +0100 Subject: hashl: Add list mode --- bin/hashl | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/bin/hashl b/bin/hashl index eaa2cc9..399e373 100755 --- a/bin/hashl +++ b/bin/hashl @@ -14,10 +14,16 @@ use Storable qw(nstore retrieve); my $base = getcwd(); my $rel_paths = 1; -my $read_size = (2 ** 20) * 10; # 10 MiB +my $read_size = (2 ** 20) * 4; # 4 MiB my $db; +my $action = $ARGV[0]; + +if (not defined $action) { + die("Usage: $0 \n"); +} + if (-r 'hashl.db') { $db = retrieve('hashl.db'); } @@ -63,9 +69,16 @@ sub process_file { }; } -find(\&process_file, $base); - -nstore($db, 'hashl.db'); +if ($action eq 'update') { + find(\&process_file, $base); + nstore($db, 'hashl.db'); +} +elsif ($action eq 'list') { + for my $name (sort keys %{$db}) { + my $file = $db->{$name}; + printf("%s %s\n", $file->{'hash'}, $name); + } +} __END__ -- cgit v1.2.3