summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2010-12-18 19:27:45 +0100
committerDaniel Friesel <derf@finalrewind.org>2010-12-18 19:27:45 +0100
commita83edab6e3044a967496eea1bc5e6207f6bf890a (patch)
tree1eb7e5a5c90bbc93097ba8edce3701192bd20cf8
Initial commit
-rwxr-xr-xbin/hashl87
1 files changed, 87 insertions, 0 deletions
diff --git a/bin/hashl b/bin/hashl
new file mode 100755
index 0000000..a89bbee
--- /dev/null
+++ b/bin/hashl
@@ -0,0 +1,87 @@
+#!/usr/bin/env perl
+## Copyright © 2010 by Daniel Friesel <derf@finalrewind.org>
+## License: WTFPL <http://sam.zoy.org/wtfpl>
+## 0. You just DO WHAT THE FUCK YOU WANT TO.
+use strict;
+use warnings;
+use 5.010;
+use autodie;
+
+use Cwd;
+use Digest::MD5 qw(md5_hex);
+use File::Find;
+use Storable qw(nstore retrieve);
+
+my $base = getcwd();
+my $rel_paths = 1;
+my $read_size = (2 ** 20) * 10; # 10 MiB
+
+my $db;
+
+if (-r 'hashl.db') {
+ $db = retrieve('hashl.db');
+}
+
+sub process_file {
+ my $file = $File::Find::name;
+ my $path = $file;
+ my ($size, $mtime) = (stat($file))[7,9];
+ my ($fh, $data);
+
+ if (not -f $file or $file eq "${base}/hashl.db") {
+ return;
+ }
+
+ if ($rel_paths) {
+ $file = substr($file, length($base) + 1);
+ }
+
+ if (exists($db->{$file}) and
+ $db->{$file}->{'mtime'} == $mtime and
+ $db->{$file}->{'size'} == $size ) {
+ return;
+ }
+
+ open($fh, '<', $path);
+ binmode($fh);
+ read($fh, $data, $read_size);
+ close($fh);
+
+ $db->{$file} = {
+ hash => md5_hex($data),
+ mtime => $mtime,
+ size => $size,
+ };
+
+ printf("%s %s\n", $db->{$file}->{'hash'}, $file);
+}
+
+find(\&process_file, $base);
+
+nstore($db, 'hashl.db');
+
+__END__
+
+=head1 NAME
+
+=head1 SYNOPSIS
+
+=head1 DESCRIPTION
+
+=head1 OPTIONS
+
+=head1 EXIT STATUS
+
+=head1 CONFIGURATION
+
+=head1 DEPENDENCIES
+
+=head1 BUGS AND LIMITATIONS
+
+=head1 AUTHOR
+
+Copyright (C) 2010 by Daniel Friesel E<lt>derf@finalrewind.orgE<gt>
+
+=head1 LICENSE
+
+ 0. You just DO WHAT THE FUCK YOU WANT TO.