From bed5b0763857cf672e6f7d75e486cda3578cb92c Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 19 Dec 2010 10:40:29 +0100 Subject: Add hashl in-list (check if we know a file) --- bin/hashl | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/bin/hashl b/bin/hashl index bd0eb6c..0724f9d 100755 --- a/bin/hashl +++ b/bin/hashl @@ -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 = ) { + chomp $line; + if (!is_in_list($line)) { + say $line; + } + } + } +} __END__ -- cgit v1.2.3