summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2011-05-17 19:56:31 +0200
committerDaniel Friesel <derf@finalrewind.org>2011-05-17 19:56:31 +0200
commit2f99841240904b6a487c9216b410e3e34e8506ac (patch)
tree56da7d5d006335c635a888d9bdfdf8d6d2c97678
parent60fba3105a1bf2f537742cfe591f5af1e5c5faa2 (diff)
Improve $hashl->add_file
-rwxr-xr-xbin/hashl13
-rw-r--r--lib/App/Hashl.pm35
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 {