From 2f99841240904b6a487c9216b410e3e34e8506ac Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Tue, 17 May 2011 19:56:31 +0200 Subject: Improve $hashl->add_file --- bin/hashl | 13 ++++--------- lib/App/Hashl.pm | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/bin/hashl b/bin/hashl index 3f03789..4877e87 100755 --- a/bin/hashl +++ b/bin/hashl @@ -162,17 +162,12 @@ sub db_update { my ($file, $path) = @_; my ($size, $mtime) = (stat($path))[7,9]; - if ($hashl->file($file) and - $hashl->file($file)->{mtime} == $mtime and - $hashl->file($file)->{size} == $size ) { - return; - } - - $hashl->add_file($file, { - hash => $hashl->hash_file($path), + $hashl->add_file( + file => $file, mtime => $mtime, + path => $path, size => $size, - }); + ); } sub db_ignore { 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 { -- cgit v1.2.3