all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
Subject: [pve-devel] applied: [PATCH common v4 1/2] fix #4849: download file from url: add opt parameter for a decompression command
Date: Fri, 04 Aug 2023 13:47:42 +0200	[thread overview]
Message-ID: <1691149643.1ggkw89mhd.astroid@yuna.none> (raw)
In-Reply-To: <20230801144604.760331-4-p.hufnagl@proxmox.com>

with a few follow-ups.

On August 1, 2023 4:46 pm, Philipp Hufnagl wrote:
> Signed-off-by: Philipp Hufnagl <p.hufnagl@proxmox.com>
> ---
>  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
> 
> 
> 
> _______________________________________________
> pve-devel mailing list
> pve-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
> 
> 
> 




  reply	other threads:[~2023-08-04 11:48 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-01 14:45 [pve-devel] [PATCH storage/manager/common v4 0/6] fix #4849: allow download of compressed ISOs Philipp Hufnagl
2023-08-01 14:45 ` [pve-devel] [PATCH storage v4 1/2] fix #4849: download-url: allow download and decompression " Philipp Hufnagl
2023-08-04 11:51   ` Fabian Grünbichler
2023-08-01 14:46 ` [pve-devel] [PATCH storage v4 2/2] fix whitespaces Philipp Hufnagl
2023-08-04 11:49   ` [pve-devel] applied: " Fabian Grünbichler
2023-08-01 14:46 ` [pve-devel] [PATCH common v4 1/2] fix #4849: download file from url: add opt parameter for a decompression command Philipp Hufnagl
2023-08-04 11:47   ` Fabian Grünbichler [this message]
2023-08-01 14:46 ` [pve-devel] [PATCH common v4 2/2] fix whitespaces Philipp Hufnagl
2023-08-04 11:48   ` [pve-devel] applied: " Fabian Grünbichler
2023-08-01 14:46 ` [pve-devel] [PATCH manager v4 1/2] fix #4849: download to storage: automatically dectect and configure compression Philipp Hufnagl
2023-08-04 11:53   ` Fabian Grünbichler
2023-08-01 14:46 ` [pve-devel] [PATCH manager v4 2/2] fix whitespaces Philipp Hufnagl
2023-08-04 11:49   ` [pve-devel] applied: " Fabian Grünbichler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1691149643.1ggkw89mhd.astroid@yuna.none \
    --to=f.gruenbichler@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal