]> git.proxmox.com Git - pve-common.git/commitdiff
tools: download_file_from_url: move check for existing file outside eval
authorLorenz Stechauner <l.stechauner@proxmox.com>
Wed, 16 Jun 2021 09:35:58 +0000 (11:35 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 16 Jun 2021 10:14:52 +0000 (12:14 +0200)
it is not necessary to include this block in the eval which when it
fails tries to unlink $tmpdest, because in the check for the existing
file $tmpdest is not used.

src/PVE/Tools.pm

index 3cf7c4db0f97d6b7700cac936a30254d7e29c27d..9046b4f2c4ef7953b60581024b1d3b1f4a42398a 100644 (file)
@@ -1862,22 +1862,22 @@ sub download_file_from_url {
 
     print "downloading $url to $dest\n";
 
-    my $tmpdest = "$dest.tmp.$$";
-    eval {
-       if (-f $dest && $checksum_algorithm) {
-           print "calculating checksum of existing file...";
-           my $checksum_got = get_file_hash($checksum_algorithm, $dest);
+    if (-f $dest && $checksum_algorithm) {
+       print "calculating checksum of existing file...";
+       my $checksum_got = get_file_hash($checksum_algorithm, $dest);
 
-           if (lc($checksum_got) eq lc($checksum_expected)) {
-               print "OK, got correct file already, no need to download\n";
-               return;
-           } else {
-               # we could re-download, but may not be safe so just abort for now..
-               print "\n";  # the front end expects the error to reside at the last line without any noise
-               die "checksum mismatch: got '$checksum_got' != expect '$checksum_expected', aborting\n";
-           }
+       if (lc($checksum_got) eq lc($checksum_expected)) {
+           print "OK, got correct file already, no need to download\n";
+           return;
+       } else {
+           # we could re-download, but may not be safe so just abort for now..
+           print "\n";  # the front end expects the error to reside at the last line without any noise
+           die "checksum mismatch: got '$checksum_got' != expect '$checksum_expected', aborting\n";
        }
+    }
 
+    my $tmpdest = "$dest.tmp.$$";
+    eval {
        local $SIG{INT} = sub {
            unlink $tmpdest or warn "could not cleanup temporary file: $!";
            die "got interrupted by signal\n";