diff options
author | Daniel Friesel <derf@finalrewind.org> | 2010-12-18 19:58:39 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2010-12-18 19:58:39 +0100 |
commit | cdff687c62bbb2a7c8c7bd2e4eecfd1186d7bc44 (patch) | |
tree | c239b03bc153af72892e6e8e170a8be6cf346e99 /bin/hashl | |
parent | 52ad4d2b4e2929327cde4ebd5c7fecec31c97344 (diff) |
hashl: Add list mode
Diffstat (limited to 'bin/hashl')
-rwxr-xr-x | bin/hashl | 21 |
1 files changed, 17 insertions, 4 deletions
@@ -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 <action>\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__ |