summaryrefslogtreecommitdiff
path: root/bin/hashl
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2010-12-18 19:58:39 +0100
committerDaniel Friesel <derf@finalrewind.org>2010-12-18 19:58:39 +0100
commitcdff687c62bbb2a7c8c7bd2e4eecfd1186d7bc44 (patch)
treec239b03bc153af72892e6e8e170a8be6cf346e99 /bin/hashl
parent52ad4d2b4e2929327cde4ebd5c7fecec31c97344 (diff)
hashl: Add list mode
Diffstat (limited to 'bin/hashl')
-rwxr-xr-xbin/hashl21
1 files 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 <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__