diff options
author | Daniel Friesel <derf@finalrewind.org> | 2011-05-17 19:56:31 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2011-05-17 19:56:31 +0200 |
commit | 2f99841240904b6a487c9216b410e3e34e8506ac (patch) | |
tree | 56da7d5d006335c635a888d9bdfdf8d6d2c97678 /lib | |
parent | 60fba3105a1bf2f537742cfe591f5af1e5c5faa2 (diff) |
Improve $hashl->add_file
Diffstat (limited to 'lib')
-rw-r--r-- | lib/App/Hashl.pm | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/lib/App/Hashl.pm b/lib/App/Hashl.pm index f99406f..3f9bfa7 100644 --- a/lib/App/Hashl.pm +++ b/lib/App/Hashl.pm @@ -10,6 +10,24 @@ use Storable qw(nstore retrieve); my $VERSION = '0.1'; +=head1 NAME + +App::Hashl - Partially hash files, check if files are equal etc. + +=head1 SYNOPSIS + + use App::Hashl; + + my $hashl = App::Hashl->new(); + # or: App::Hashl->new_from_file($database_file); + + for my $file (@files) { + $hashl->add_file($file, { + hash + +=cut + + sub new { my ($obj, %conf) = @_; my $ref = { @@ -101,8 +119,21 @@ sub files { } sub add_file { - my ($self, $name, $data) = @_; - $self->{files}->{$name} = $data; + my ($self, %data) = @_; + my $file = $data{file}; + my $path = $data{path}; + + if ($self->file($file) and + $self->file($file)->{mtime} == $data{mtime} and + $self->file($file)->{size} == $data{size} ) { + return; + } + + $self->{files}->{$file} = { + hash => $self->hash_file($file), + mtime => $data{mtime}, + size => $data{size}, + }; } sub ignored { |