From b70f03c8233fa342477b201455a04a13c0384ba0 Mon Sep 17 00:00:00 2001
From: Andreas Romeyke <art1@andreas-romeyke.de>
Date: Fri, 16 Oct 2020 10:22:19 +0200
Subject: [PATCH] - add read error detection

---
 deep_fixitycheck.pl | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/deep_fixitycheck.pl b/deep_fixitycheck.pl
index 6095308..fe69cdb 100644
--- a/deep_fixitycheck.pl
+++ b/deep_fixitycheck.pl
@@ -265,9 +265,16 @@ sub check_file_fixities($$) {
   my $fh = path($fileobj->{file_mounted})->openr();
   binmode($fh);
   my $buffer;
-  while (read($fh, $buffer, 128*1024)) { # 128kB blocks
-    foreach my $fixity_algorithm (keys %digest_mapping) {
-      $digest_mapping{$fixity_algorithm}->add($buffer);
+  while (1) {
+    my $ret = read($fh, $buffer, 128*1024);# 128kB blocks
+    if (defined $ret) {
+      last if 0 == $ret; # EOF
+      foreach my $fixity_algorithm (keys %digest_mapping) {
+        $digest_mapping{$fixity_algorithm}->add($buffer);
+      }
+    } else {
+      add_error($fileobj, $result, "read error, $!");
+      last;
     }
   }
   close ($fh);
@@ -276,7 +283,6 @@ sub check_file_fixities($$) {
       $result->{fixity}->{$fixity_algorithm} = $digest_mapping{$fixity_algorithm}->hexdigest();
       if ($result->{fixity}->{$fixity_algorithm} ne $fileobj->{fixity}->{$fixity_algorithm}) {
         add_error($fileobj, $result, "has fixity $result->{fixity}->{$fixity_algorithm} for algorithm $fixity_algorithm, but $fileobj->{fixity}->{$fixity_algorithm} was expected");
-        die;
       }
     }
   }
-- 
GitLab