]> git.proxmox.com Git - pve-storage.git/commitdiff
fix #4849: download-url: allow download and decompression of compressed ISOs
authorPhilipp Hufnagl <p.hufnagl@proxmox.com>
Mon, 14 Aug 2023 14:42:17 +0000 (16:42 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 18 Aug 2023 07:58:06 +0000 (09:58 +0200)
adds information for how to decompress isos.

generates the compressor regex from a list of comression formats (to
avoid redundancy)
extends the download_url wtih the functionality to handley compression
for images

Signed-off-by: Philipp Hufnagl <p.hufnagl@proxmox.com>
src/PVE/API2/Storage/Status.pm
src/PVE/Storage.pm
src/PVE/Storage/Plugin.pm

index 2aaeff6e959524c9023068a3d0b7865c5f94d004..78755308c97baa2b3f24a4f351d9bfe51937b80f 100644 (file)
@@ -578,6 +578,12 @@ __PACKAGE__->register_method({
                requires => 'checksum-algorithm',
                optional => 1,
            },
+           compression => {
+               description => "Decompress the downloaded file using specified compression algorithm",
+               type => 'string',
+               enum => $PVE::Storage::Plugin::KNOWN_COMPRESSION_FORMATS,
+               optional => 1,
+           },
            'checksum-algorithm' => {
                description => "The algorithm to calculate the checksum of the file.",
                type => 'string',
@@ -604,7 +610,7 @@ __PACKAGE__->register_method({
 
        my $cfg = PVE::Storage::config();
 
-       my ($node, $storage) = $param->@{'node', 'storage'};
+       my ($node, $storage, $compression) = $param->@{'node', 'storage','compression'};
        my $scfg = PVE::Storage::storage_check_enabled($cfg, $storage, $node);
 
        die "can't upload to storage type '$scfg->{type}', not a file based storage!\n"
@@ -649,6 +655,12 @@ __PACKAGE__->register_method({
        }
 
        my $worker = sub {
+           if ($compression) {
+               die "decompression not supported for $content\n" if $content ne 'iso';
+               my $info = PVE::Storage::decompressor_info('iso', $compression);
+               die "no decompression method found\n" if (! $info->{decompressor});
+               $opts->{decompression_command} = $info->{decompressor};
+           }
            PVE::Tools::download_file_from_url("$path/$filename", $url, $opts);
        };
 
index a4d85e1220c47e113374b8555030fbbe02b48534..cb70113bc3d7a5e3be4b8e3a972915eb1706de8b 100755 (executable)
@@ -1531,6 +1531,12 @@ sub decompressor_info {
            lzo => ['lzop', '-d', '-c'],
            zst => ['zstd', '-q', '-d', '-c'],
        },
+       iso => {
+           # zstd seem to be able to handle .gzip fine. Therefore we dont need additional other tool
+           gz => ['zcat'],
+           lzo => ['lzop', '-d', '-c'],
+           zst => ['zstd', '-q', '-d', '-c'],
+       },
     };
 
     die "ERROR: archive format not defined\n"
index 74d19873668885db5a224e0bfeeaeebff717f471..71fcff0a719724fcba17bab73e9778e45063438f 100644 (file)
@@ -19,7 +19,8 @@ use JSON;
 
 use base qw(PVE::SectionConfig);
 
-use constant COMPRESSOR_RE => 'gz|lzo|zst';
+use constant KNOWN_COMPRESSION_FORMATS =>  ( 'gz', 'lzo', 'zst');
+use constant COMPRESSOR_RE => join( '|', KNOWN_COMPRESSION_FORMATS);
 
 use constant LOG_EXT => ".log";
 use constant NOTES_EXT => ".notes";