diff options
author | Daniel Friesel <derf@finalrewind.org> | 2010-12-19 10:40:29 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2010-12-19 10:40:29 +0100 |
commit | bed5b0763857cf672e6f7d75e486cda3578cb92c (patch) | |
tree | 9af49a3cec4d50f63391977a77e7bf2b57989458 /bin/hashl | |
parent | f5d2893d0f76aafa51280ff76965fe52e2cee8f9 (diff) |
Add hashl in-list (check if we know a file)
Diffstat (limited to 'bin/hashl')
-rwxr-xr-x | bin/hashl | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -65,6 +65,16 @@ sub hash_file { return sha1_hex($data); } +sub is_in_list { + my ($file) = @_; + my $hash = hash_file($file); + + if (grep { $_->{'hash'} eq $hash } values %{$db}) { + return 1; + } + return 0; +} + sub process_file { my $file = $File::Find::name; @@ -123,6 +133,19 @@ elsif ($action eq 'list') { printf("%s %s\n", $file->{'hash'}, $name); } } +elsif ($action eq 'in-list') { + if ($ARGV[1]) { + exit (!is_in_list($ARGV[1])); + } + else { + while (my $line = <STDIN>) { + chomp $line; + if (!is_in_list($line)) { + say $line; + } + } + } +} __END__ |