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 F3AD187D1 for ; Fri, 28 Jul 2023 10:11:45 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id D676112DBE for ; Fri, 28 Jul 2023 10:11:45 +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 ; Fri, 28 Jul 2023 10:11:44 +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 2B0CF40673 for ; Fri, 28 Jul 2023 10:11:44 +0200 (CEST) Date: Fri, 28 Jul 2023 10:11:36 +0200 From: Fabian =?iso-8859-1?q?Gr=FCnbichler?= To: Proxmox VE development discussion References: <20230727152817.775699-1-p.hufnagl@proxmox.com> <20230727152817.775699-4-p.hufnagl@proxmox.com> In-Reply-To: <20230727152817.775699-4-p.hufnagl@proxmox.com> MIME-Version: 1.0 User-Agent: astroid/0.16.0 (https://github.com/astroidmail/astroid) Message-Id: <1690530748.lsblj0i04c.astroid@yuna.none> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-SPAM-LEVEL: Spam detection results: 0 AWL 0.019 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 PROLO_LEO1 0.1 Meta Catches all Leo drug variations so far 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. [storage.pm, proxmox.com, status.pm] Subject: Re: [pve-devel] [PATCH V2 storage 1/1] fix #4849: download-url: allow download and decompression of compressed ISOs 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, 28 Jul 2023 08:11:46 -0000 On July 27, 2023 5:28 pm, Philipp Hufnagl wrote: > Signed-off-by: Philipp Hufnagl > --- > src/PVE/API2/Storage/Status.pm | 22 +++++++++++++++++++--- > src/PVE/Storage.pm | 6 ++++++ > 2 files changed, 25 insertions(+), 3 deletions(-) >=20 > diff --git a/src/PVE/API2/Storage/Status.pm b/src/PVE/API2/Storage/Status= .pm > index 2aaeff6..a087c53 100644 > --- a/src/PVE/API2/Storage/Status.pm > +++ b/src/PVE/API2/Storage/Status.pm > @@ -23,6 +23,8 @@ use PVE::Storage; > =20 > use base qw(PVE::RESTHandler); > =20 > +our $KNOWN_COMPRESSION_FORMATS =3D ['zst', 'gz', 'lzo']; > + > __PACKAGE__->register_method ({ > subclass =3D> "PVE::API2::Storage::PruneBackups", > path =3D> '{storage}/prunebackups', > @@ -578,6 +580,12 @@ __PACKAGE__->register_method({ > requires =3D> 'checksum-algorithm', > optional =3D> 1, > }, > + compression =3D> { > + description =3D> "Decompress the downloaded file using following compr= ession algorithm", nit: s/following/specified or "this" > + type =3D> 'string', > + enum =3D> $KNOWN_COMPRESSION_FORMATS, > + optional =3D> 1, > + }, > 'checksum-algorithm' =3D> { > description =3D> "The algorithm to calculate the checksum of the file.= ", > type =3D> 'string', > @@ -604,7 +612,7 @@ __PACKAGE__->register_method({ > =20 > my $cfg =3D PVE::Storage::config(); > =20 > - my ($node, $storage) =3D $param->@{'node', 'storage'}; > + my ($node, $storage, $compression) =3D $param->@{'node', 'storage','com= pression'}; > my $scfg =3D PVE::Storage::storage_check_enabled($cfg, $storage, $node)= ; > =20 > die "can't upload to storage type '$scfg->{type}', not a file based sto= rage!\n" > @@ -627,6 +635,7 @@ __PACKAGE__->register_method({ > if ($filename !~ m![^/]+$PVE::Storage::VZTMPL_EXT_RE_1$!) { > raise_param_exc({ filename =3D> "wrong file extension" }); > } > + die "decompression not supported for vztempl" if $compressio= n; 'vztmpl', or CT template, but I would switch this check around -> only allow iso. that way, if we ever add new content types, we only expose them to decompression by adding them, instead of automatically. in general, it is usually a better approach to specify what you accept, and not what you reject, unless you want to automatically accept all future additions, which is rarely the case ;) > $path =3D PVE::Storage::get_vztmpl_dir($cfg, $storage); > } else { > raise_param_exc({ content =3D> "upload content-type '$content' is n= ot allowed" }); > @@ -642,14 +651,21 @@ __PACKAGE__->register_method({ > http_proxy =3D> $dccfg->{http_proxy}, > }; > =20 > - my ($checksum, $checksum_algorithm) =3D $param->@{'checksum', 'checksum= -algorithm'}; > + my ($checksum, $checksum_algorithm) =3D $param->@{'checksum', 'checksum= -algorithm' }; > if ($checksum) { > $opts->{"${checksum_algorithm}sum"} =3D $checksum; > $opts->{hash_required} =3D 1; > } > =20 > my $worker =3D sub { > - PVE::Tools::download_file_from_url("$path/$filename", $url, $opts); > + my $save_to =3D "$path/$filename"; > + die "refusing to override existing file $save_to \n" if -e $save_to= ; > + $save_to .=3D ".$compression" if $compression; see below - this is not needed (here) if the decompressor is switched to STDOUT.. the idea of moving the decompression into download_file_from_url was that the caller need not be concerned with *how* the decompression is handled - just provide the command to do the decompression ;) > + if ($compression) { > + my $info =3D PVE::Storage::decompressor_info('iso', $com= pression); > + $opts->{decompression_command} =3D $info->{decompressor}= ; nit: indentation? > + } > + PVE::Tools::download_file_from_url($save_to, $url, $opts); > }; > =20 > my $worker_id =3D PVE::Tools::encode_text($filename); # must not pass := or the like as w-ID > diff --git a/src/PVE/Storage.pm b/src/PVE/Storage.pm > index a4d85e1..9dbf38f 100755 > --- a/src/PVE/Storage.pm > +++ b/src/PVE/Storage.pm > @@ -1531,6 +1531,12 @@ sub decompressor_info { > lzo =3D> ['lzop', '-d', '-c'], > zst =3D> ['zstd', '-q', '-d', '-c'], > }, > + iso =3D> { > + # zstd seem to be able to handle .gzip fine. Therefore we do= nt need additional other tool nit: indentation of comment > + gz =3D> ['zstd', '-q', '-d'], > + zst =3D> ['zstd', '-q', '-d'], > + lzo =3D> ['lzop', '-q', '-d'], I'd still like these switched to the STDOUT variants like with vma, see previous review and comment at the pve-common patch. > + }, > }; > =20 > die "ERROR: archive format not defined\n" > --=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