]> git.proxmox.com Git - pve-common.git/commitdiff
download file from url: improve cleanup
authorFabian Grünbichler <f.gruenbichler@proxmox.com>
Fri, 4 Aug 2023 11:44:22 +0000 (13:44 +0200)
committerFabian Grünbichler <f.gruenbichler@proxmox.com>
Fri, 4 Aug 2023 11:47:10 +0000 (13:47 +0200)
don't attempt cleanup if temp files don't exist (anymore, or not yet).

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
src/PVE/Tools.pm

index 8c1ad62f37a7eed7a1d13cb38f7d97871ebbb6e9..d864b41b3226007f95aac0ba5e3b1a855290710f 100644 (file)
@@ -2017,9 +2017,10 @@ sub download_file_from_url {
     my $tmp_decomp = "$dest.tmp_dcom.$$";
     eval {
        local $SIG{INT} = sub {
-           unlink $tmp_download or warn "could not cleanup temporary file: $!";
+           unlink $tmp_download or warn "could not cleanup temporary file: $!"
+               if -e $tmp_download;
            unlink $tmp_decomp or warn "could not cleanup temporary file: $!"
-               if $opts->{decompression_command};
+               if $opts->{decompression_command} && -e $tmp_decomp;
            die "got interrupted by signal\n";
        };
 
@@ -2069,9 +2070,10 @@ sub download_file_from_url {
        }
     };
     if (my $err = $@) {
-       unlink $tmp_download or warn "could not cleanup temporary file: $!";
+       unlink $tmp_download or warn "could not cleanup temporary file: $!"
+           if -e $tmp_download;
        unlink $tmp_decomp or warn "could not cleanup temporary file: $!"
-           if $opts->{decompression_command};
+           if $opts->{decompression_command} && -e $tmp_decomp;
        die $err;
     }