From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 9709D9082 for ; Tue, 1 Aug 2023 16:46:42 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 77D37F54E for ; Tue, 1 Aug 2023 16:46:12 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Tue, 1 Aug 2023 16:46:11 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 3320A409CB for ; Tue, 1 Aug 2023 16:46:11 +0200 (CEST) From: Philipp Hufnagl To: pve-devel@lists.proxmox.com Date: Tue, 1 Aug 2023 16:46:01 +0200 Message-Id: <20230801144604.760331-4-p.hufnagl@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230801144604.760331-1-p.hufnagl@proxmox.com> References: <20230801144604.760331-1-p.hufnagl@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.002 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [tools.pm] Subject: [pve-devel] [PATCH common v4 1/2] fix #4849: download file from url: add opt parameter for a decompression command X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Aug 2023 14:46:42 -0000 Signed-off-by: Philipp Hufnagl --- src/PVE/Tools.pm | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm index 9ffac12..159ec82 100644 --- a/src/PVE/Tools.pm +++ b/src/PVE/Tools.pm @@ -2013,10 +2013,13 @@ sub download_file_from_url { } } - my $tmpdest = "$dest.tmp.$$"; + my $tmp_download = "$dest.tmp_dwnl.$$"; + my $tmp_decomp = "$dest.tmp_dcom.$$"; eval { local $SIG{INT} = sub { - unlink $tmpdest or warn "could not cleanup temporary file: $!"; + unlink $tmp_download or warn "could not cleanup temporary file: $!"; + unlink $tmp_decomp or warn "could not cleanup temporary file: $!" + if $opts->{decompression_command}; die "got interrupted by signal\n"; }; @@ -2029,7 +2032,7 @@ sub download_file_from_url { $ENV{https_proxy} = $opts->{https_proxy}; } - my $cmd = ['wget', '--progress=dot:giga', '-O', $tmpdest, $url]; + my $cmd = ['wget', '--progress=dot:giga', '-O', $tmp_download, $url]; if (!($opts->{verify_certificates} // 1)) { # default to true push @$cmd, '--no-check-certificate'; @@ -2041,7 +2044,7 @@ sub download_file_from_url { if ($checksum_algorithm) { print "calculating checksum..."; - my $checksum_got = get_file_hash($checksum_algorithm, $tmpdest); + my $checksum_got = get_file_hash($checksum_algorithm, $tmp_download); if (lc($checksum_got) eq lc($checksum_expected)) { print "OK, checksum verified\n"; @@ -2051,10 +2054,26 @@ sub download_file_from_url { } } - rename($tmpdest, $dest) or die "unable to rename temporary file: $!\n"; + if (my $cmd = $opts->{decompression_command}) { + push @$cmd, $tmp_download; + my $fh; + if (!open($fh, ">", "$tmp_decomp")) { + die "cant open temporary file $tmp_decomp for decompresson: $!\n"; + } + print "decompressing $tmp_download to $tmp_decomp\n"; + eval { run_command($cmd, output => '>&'.fileno($fh)); }; + my $err = $@; + unlink $tmp_download; + die "$err\n" if $err; + rename($tmp_decomp, $dest) or die "unable to rename temporary file: $!\n"; + } else { + rename($tmp_download, $dest) or die "unable to rename temporary file: $!\n"; + } }; if (my $err = $@) { - unlink $tmpdest or warn "could not cleanup temporary file: $!"; + unlink $tmp_download or warn "could not cleanup temporary file: $!"; + unlink $tmp_decomp or warn "could not cleanup temporary file: $!" + if $opts->{decompression_command}; die $err; } -- 2.39.2