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 4C9D88CA5
for ; Mon, 31 Jul 2023 10:39:34 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
by firstgate.proxmox.com (Proxmox) with ESMTP id 3424237D81
for ; Mon, 31 Jul 2023 10:39:34 +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 ; Mon, 31 Jul 2023 10:39:33 +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 D3830431BB
for ; Mon, 31 Jul 2023 10:39:32 +0200 (CEST)
From: Philipp Hufnagl
To: pve-devel@lists.proxmox.com
Date: Mon, 31 Jul 2023 10:39:22 +0200
Message-Id: <20230731083924.18234-2-p.hufnagl@proxmox.com>
X-Mailer: git-send-email 2.39.2
In-Reply-To: <20230731083924.18234-1-p.hufnagl@proxmox.com>
References: <20230731083924.18234-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 -
Subject: [pve-devel] [V3 PATCH common 1/1] 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: Mon, 31 Jul 2023 08:39:34 -0000
Signed-off-by: Philipp Hufnagl
---
src/PVE/Tools.pm | 59 +++++++++++++++++++++++++++++++-----------------
1 file changed, 38 insertions(+), 21 deletions(-)
diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm
index 9ffac12..ab97129 100644
--- a/src/PVE/Tools.pm
+++ b/src/PVE/Tools.pm
@@ -92,23 +92,23 @@ our $EMAIL_USER_RE = qr/[\w\+\-\~]+(\.[\w\+\-\~]+)*/;
our $EMAIL_RE = qr/$EMAIL_USER_RE@[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)*/;
use constant {CLONE_NEWNS => 0x00020000,
- CLONE_NEWUTS => 0x04000000,
- CLONE_NEWIPC => 0x08000000,
- CLONE_NEWUSER => 0x10000000,
- CLONE_NEWPID => 0x20000000,
- CLONE_NEWNET => 0x40000000};
+ CLONE_NEWUTS => 0x04000000,
+ CLONE_NEWIPC => 0x08000000,
+ CLONE_NEWUSER => 0x10000000,
+ CLONE_NEWPID => 0x20000000,
+ CLONE_NEWNET => 0x40000000};
use constant {O_PATH => 0x00200000,
- O_CLOEXEC => 0x00080000,
- O_TMPFILE => 0x00400000 | O_DIRECTORY};
+ O_CLOEXEC => 0x00080000,
+ O_TMPFILE => 0x00400000 | O_DIRECTORY};
use constant {AT_EMPTY_PATH => 0x1000,
- AT_FDCWD => -100};
+ AT_FDCWD => -100};
# from
use constant {RENAME_NOREPLACE => (1 << 0),
- RENAME_EXCHANGE => (1 << 1),
- RENAME_WHITEOUT => (1 << 2)};
+ RENAME_EXCHANGE => (1 << 1),
+ RENAME_WHITEOUT => (1 << 2)};
sub run_with_timeout {
my ($timeout, $code, @param) = @_;
@@ -579,7 +579,7 @@ sub run_command {
}
}
- alarm(0);
+ alarm(0);
};
my $err = $@;
@@ -1354,7 +1354,7 @@ sub dump_journal {
my $parser = sub {
my $line = shift;
- return if $count++ < $start;
+ return if $count++ < $start;
return if $limit <= 0;
push @$lines, { n => int($count), t => $line};
$limit--;
@@ -1441,7 +1441,7 @@ sub unpack_sockaddr_in46 {
my ($sin) = @_;
my $family = Socket::sockaddr_family($sin);
my ($port, $host) = ($family == AF_INET6 ? Socket::unpack_sockaddr_in6($sin)
- : Socket::unpack_sockaddr_in($sin));
+ : Socket::unpack_sockaddr_in($sin));
return ($family, $port, $host);
}
@@ -1485,8 +1485,8 @@ sub get_fqdn {
sub parse_host_and_port {
my ($address) = @_;
if ($address =~ /^($IPV4RE|[[:alnum:]\-.]+)(?::(\d+))?$/ || # ipv4 or host with optional ':port'
- $address =~ /^\[($IPV6RE|$IPV4RE|[[:alnum:]\-.]+)\](?::(\d+))?$/ || # anything in brackets with optional ':port'
- $address =~ /^($IPV6RE)(?:\.(\d+))?$/) # ipv6 with optional port separated by dot
+ $address =~ /^\[($IPV6RE|$IPV4RE|[[:alnum:]\-.]+)\](?::(\d+))?$/ || # anything in brackets with optional ':port'
+ $address =~ /^($IPV6RE)(?:\.(\d+))?$/) # ipv6 with optional port separated by dot
{
return ($1, $2, 1); # end with 1 to support simple if(parse...) tests
}
@@ -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: $!";
+ die "got interrupted by signal\n";
+ unlink $tmp_decomp or warn "could not cleanup temporary file: $!";
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,24 @@ 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 $rerr = $@;
+ unlink $tmp_download;
+ die "$rerr\n" if $rerr;
+ }
+ rename($tmp_decomp, $dest) or die "unable to rename temporary file: $!\n";
};
if (my $err = $@) {
- unlink $tmpdest or warn "could not cleanup temporary file: $!";
+ unlink $tmp_decomp or warn "could not cleanup temporary file: $!";
die $err;
}
--
2.39.2