summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2010-12-19 10:14:17 +0100
committerDaniel Friesel <derf@finalrewind.org>2010-12-19 10:14:17 +0100
commitf5d2893d0f76aafa51280ff76965fe52e2cee8f9 (patch)
treeb73db939bdbae840a80099ac0d34db389f9cff2a /bin
parentbdb738cc6b0d8948c7d16c2c1d17ef896cafa9ad (diff)
Remove deleted files from list on update
Diffstat (limited to 'bin')
-rwxr-xr-xbin/hashl32
1 files changed, 25 insertions, 7 deletions
diff --git a/bin/hashl b/bin/hashl
index b052eb8..bd0eb6c 100755
--- a/bin/hashl
+++ b/bin/hashl
@@ -45,11 +45,31 @@ sub get_total {
}
}
+sub drop_deleted {
+ for my $file (keys %{$db}) {
+ if (! -e $file) {
+ delete $db->{$file};
+ }
+ }
+}
+
+sub hash_file {
+ my ($file) = @_;
+ my ($fh, $data);
+
+ open($fh, '<', $file);
+ binmode($fh);
+ read($fh, $data, $read_size);
+ close($fh);
+
+ return sha1_hex($data);
+}
+
+
sub process_file {
my $file = $File::Find::name;
my $path = $file;
my ($size, $mtime) = (stat($file))[7,9];
- my ($fh, $data);
local $| = 1;
@@ -71,13 +91,8 @@ sub process_file {
return;
}
- open($fh, '<', $path);
- binmode($fh);
- read($fh, $data, $read_size);
- close($fh);
-
$db->{$file} = {
- hash => sha1_hex($data),
+ hash => hash_file($path),
mtime => $mtime,
size => $size,
};
@@ -88,6 +103,8 @@ sub process_file {
}
if ($action eq 'update') {
+
+ drop_deleted();
find(\&get_total, $base);
$timer = Time::Progress->new();
@@ -97,6 +114,7 @@ if ($action eq 'update') {
);
find(\&process_file, $base);
+ print "\n";
nstore($db, $db_file);
}
elsif ($action eq 'list') {