From a83edab6e3044a967496eea1bc5e6207f6bf890a Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sat, 18 Dec 2010 19:27:45 +0100 Subject: Initial commit --- bin/hashl | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100755 bin/hashl 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 +## License: 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 Ederf@finalrewind.orgE + +=head1 LICENSE + + 0. You just DO WHAT THE FUCK YOU WANT TO. -- cgit v1.2.3