From 0bf2e89a39a3176c2ee4e3178982f8361d7134a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= Date: Fri, 4 Aug 2023 13:44:22 +0200 Subject: [PATCH] download file from url: improve cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit don't attempt cleanup if temp files don't exist (anymore, or not yet). Signed-off-by: Fabian Grünbichler --- src/PVE/Tools.pm | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm index 8c1ad62..d864b41 100644 --- a/src/PVE/Tools.pm +++ b/src/PVE/Tools.pm @@ -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; }