summaryrefslogtreecommitdiff
path: root/bin/hashl
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2010-12-19 10:40:29 +0100
committerDaniel Friesel <derf@finalrewind.org>2010-12-19 10:40:29 +0100
commitbed5b0763857cf672e6f7d75e486cda3578cb92c (patch)
tree9af49a3cec4d50f63391977a77e7bf2b57989458 /bin/hashl
parentf5d2893d0f76aafa51280ff76965fe52e2cee8f9 (diff)
Add hashl in-list (check if we know a file)
Diffstat (limited to 'bin/hashl')
-rwxr-xr-xbin/hashl23
1 files changed, 23 insertions, 0 deletions
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 = <STDIN>) {
+ chomp $line;
+ if (!is_in_list($line)) {
+ say $line;
+ }
+ }
+ }
+}
__END__