summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2011-11-02 10:31:45 +0100
committerDaniel Friesel <derf@finalrewind.org>2011-11-02 10:31:45 +0100
commit3f1d27c4a43492cf2ea379d8a4bea37aa18e3201 (patch)
tree80b6deba99e2bb3fe9edb655eaf9228d0d5dab1d
parent149e0945d618c6d3b929a030a61967cde3712dd9 (diff)
Fix handling of zero-length files (closes #1)
-rw-r--r--Changelog1
-rw-r--r--lib/App/Hashl.pm5
2 files changed, 6 insertions, 0 deletions
diff --git a/Changelog b/Changelog
index 5e5d34a..abf550e 100644
--- a/Changelog
+++ b/Changelog
@@ -1,6 +1,7 @@
git HEAD
* Add "hashl list <regex>" to filter listed files by name
+ * Do not fail when encountering zero-length files
hashl 0.2 - Mon May 23 2011
diff --git a/lib/App/Hashl.pm b/lib/App/Hashl.pm
index 1f43060..2c382ea 100644
--- a/lib/App/Hashl.pm
+++ b/lib/App/Hashl.pm
@@ -47,6 +47,11 @@ sub hash_file {
my ( $self, $file ) = @_;
my $data;
+ # read() fails for empty files
+ if ( ( stat($file) )[7] == 0 ) {
+ return sha1_hex();
+ }
+
#<<< perltidy has problems indenting 'or die' with tabs
open( my $fh, '<', $file )