[pve-devel] [PATCH manager 1/2] aplinfo: use fh for both digests

Fabian Grünbichler f.gruenbichler at proxmox.com
Wed Aug 24 12:27:41 CEST 2016


for consistency, because Digest::MD5 cannot handle filenames directly..
---
 PVE/API2/Nodes.pm | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/PVE/API2/Nodes.pm b/PVE/API2/Nodes.pm
index 5c0f6fa..96cec22 100644
--- a/PVE/API2/Nodes.pm
+++ b/PVE/API2/Nodes.pm
@@ -1114,17 +1114,17 @@ __PACKAGE__->register_method({
 		my $expected;
 
 		eval {
+		    open(my $fh, '<', $filename) or die "Can't open '$filename': $!";
+		    binmode($fh);
 		    if ($expected = $template_info->{sha512sum}) {
-			$digest = Digest::SHA->new(512)->addfile($filename, "b")->hexdigest;
+			$digest = Digest::SHA->new(512)->addfile($fh)->hexdigest;
 		    } elsif ($expected = $template_info->{md5sum}) {
 			#fallback to MD5
-			open (my $fh, '<', $filename) or die "Can't open '$filename': $!";
-			binmode ($fh);
 			$digest = Digest::MD5->new->addfile($fh)->hexdigest;
-			close($fh);
 		    } else {
 			die "no expected checksum defined";
 		    }
+		    close($fh);
 		};
 
 		die "checking hash failed - $@\n" if $@ && !$noerr;
-- 
2.1.4





More information about the pve-devel mailing list