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 79B819AE1 for ; Fri, 4 Aug 2023 13:48:20 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 534C9E2AD for ; Fri, 4 Aug 2023 13:47:50 +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)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Fri, 4 Aug 2023 13:47:49 +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 7A9C940BCD for ; Fri, 4 Aug 2023 13:47:49 +0200 (CEST) Date: Fri, 04 Aug 2023 13:47:42 +0200 From: Fabian =?iso-8859-1?q?Gr=FCnbichler?= To: Proxmox VE development discussion References: <20230801144604.760331-1-p.hufnagl@proxmox.com> <20230801144604.760331-4-p.hufnagl@proxmox.com> In-Reply-To: <20230801144604.760331-4-p.hufnagl@proxmox.com> MIME-Version: 1.0 User-Agent: astroid/0.16.0 (https://github.com/astroidmail/astroid) Message-Id: <1691149643.1ggkw89mhd.astroid@yuna.none> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-SPAM-LEVEL: Spam detection results: 0 AWL 0.069 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, proxmox.com] Subject: [pve-devel] applied: [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: Fri, 04 Aug 2023 11:48:20 -0000 with a few follow-ups. On August 1, 2023 4:46 pm, Philipp Hufnagl wrote: > Signed-off-by: Philipp Hufnagl > --- > src/PVE/Tools.pm | 31 +++++++++++++++++++++++++------ > 1 file changed, 25 insertions(+), 6 deletions(-) >=20 > 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 { > } > } > =20 > - my $tmpdest =3D "$dest.tmp.$$"; > + my $tmp_download =3D "$dest.tmp_dwnl.$$"; > + my $tmp_decomp =3D "$dest.tmp_dcom.$$"; > eval { > local $SIG{INT} =3D 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"; > }; > =20 > @@ -2029,7 +2032,7 @@ sub download_file_from_url { > $ENV{https_proxy} =3D $opts->{https_proxy}; > } > =20 > - my $cmd =3D ['wget', '--progress=3Ddot:giga', '-O', $tmpdest, $url]= ; > + my $cmd =3D ['wget', '--progress=3Ddot:giga', '-O', $tmp_download, = $url]; > =20 > 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..."; > =20 > - my $checksum_got =3D get_file_hash($checksum_algorithm, $tmpdest); > + my $checksum_got =3D get_file_hash($checksum_algorithm, $tmp_downlo= ad); > =20 > if (lc($checksum_got) eq lc($checksum_expected)) { > print "OK, checksum verified\n"; > @@ -2051,10 +2054,26 @@ sub download_file_from_url { > } > } > =20 > - rename($tmpdest, $dest) or die "unable to rename temporary file: $!\n"; > + if (my $cmd =3D $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 =3D> '>&'.fileno($fh)); }; > + my $err =3D $@; > + 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 =3D $@) { > - 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; > } > =20 > --=20 > 2.39.2 >=20 >=20 >=20 > _______________________________________________ > pve-devel mailing list > pve-devel@lists.proxmox.com > https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel >=20 >=20 >=20