public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
	Lorenz Stechauner <l.stechauner@proxmox.com>
Subject: Re: [pve-devel] [PATCH storage] api: status: fix unlink on file upload
Date: Thu, 17 Jun 2021 14:56:12 +0200	[thread overview]
Message-ID: <f1addafb-13fe-f817-512f-5c2a478e7fc6@proxmox.com> (raw)
In-Reply-To: <20210609102218.59810-1-l.stechauner@proxmox.com>

On 09.06.21 12:22, Lorenz Stechauner wrote:
> after an error while copying the file to its destination the local
> path of the destination was unlinked in every case, even when on the
> destination was copied to via scp.
> 
> Signed-off-by: Lorenz Stechauner <l.stechauner@proxmox.com>
> ---
>  PVE/API2/Storage/Status.pm | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/PVE/API2/Storage/Status.pm b/PVE/API2/Storage/Status.pm
> index 897b4a7..bcc7722 100644
> --- a/PVE/API2/Storage/Status.pm
> +++ b/PVE/API2/Storage/Status.pm
> @@ -446,6 +446,7 @@ __PACKAGE__->register_method ({
>  	# we simply overwrite the destination file if it already exists
>  
>  	my $cmd;
> +	my $err_cmd;
>  	if ($node ne 'localhost' && $node ne PVE::INotify::nodename()) {
>  	    my $remip = PVE::Cluster::remote_node_ip($node);
>  
> @@ -464,10 +465,12 @@ __PACKAGE__->register_method ({
>  				    errmsg => "mkdir failed");
>   
>  	    $cmd = ['/usr/bin/scp', @ssh_options, '-p', '--', $tmpfilename, "[$remip]:" . PVE::Tools::shell_quote($dest)];
> +	    $err_cmd = [@remcmd, '/bin/unlink', $dest];
>  	} else {
>  	    PVE::Storage::activate_storage($cfg, $param->{storage});
>  	    File::Path::make_path($dirname);
>  	    $cmd = ['cp', '--', $tmpfilename, $dest];
> +	    $err_cmd = ['/bin/unlink', $dest];

depending on usr-merge[0] status unlink may not be in /bin/ but in /usr/bin/

In general, aboslute paths for system binaries, i.e., those in any s?bin dir, is not
ideal rather just use the basename, and if required setup PATH (scoped) to a sensible
value.

That naturally does not holds true for binaries of some daemons or other tools not
deemed to be for interactive execution, e.g., things in /usr/libexec or the like,
but fortunately it also seldom makes sense to call those dynamically, at least if
not owned by the same package (and thus having control over the path).

[0]: https://wiki.debian.org/UsrMerge


>  	}
>  
>  	my $worker = sub {
> @@ -481,7 +484,7 @@ __PACKAGE__->register_method ({
>  
>  	    eval { PVE::Tools::run_command($cmd, errmsg => 'import failed'); };
>  	    if (my $err = $@) {
> -		unlink $dest;
> +		eval { PVE::Tools::run_command($err_cmd); };
>  		die $err;
>  	    }
>  	    print "finished file import successfully\n";
> 





      reply	other threads:[~2021-06-17 12:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-09 10:22 Lorenz Stechauner
2021-06-17 12:56 ` Thomas Lamprecht [this message]

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=f1addafb-13fe-f817-512f-5c2a478e7fc6@proxmox.com \
    --to=t.lamprecht@proxmox.com \
    --cc=l.stechauner@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal