* [pve-devel] [PATCH v2 storage] api: status: fix unlink on file upload
@ 2021-06-25 7:22 Lorenz Stechauner
2021-07-22 7:05 ` Lorenz Stechauner
2021-07-29 15:14 ` [pve-devel] applied: " Thomas Lamprecht
0 siblings, 2 replies; 3+ messages in thread
From: Lorenz Stechauner @ 2021-06-25 7:22 UTC (permalink / raw)
To: pve-devel
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 72fd851..b4d2e15 100644
--- a/PVE/API2/Storage/Status.pm
+++ b/PVE/API2/Storage/Status.pm
@@ -444,6 +444,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);
@@ -462,10 +463,12 @@ __PACKAGE__->register_method ({
errmsg => "mkdir failed");
$cmd = ['/usr/bin/scp', @ssh_options, '-p', '--', $tmpfilename, "[$remip]:" . PVE::Tools::shell_quote($dest)];
+ $err_cmd = [@remcmd, 'unlink', '--', $dest];
} else {
PVE::Storage::activate_storage($cfg, $param->{storage});
File::Path::make_path($dirname);
$cmd = ['cp', '--', $tmpfilename, $dest];
+ $err_cmd = ['unlink', '--', $dest];
}
my $worker = sub {
@@ -479,7 +482,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";
--
2.30.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [pve-devel] [PATCH v2 storage] api: status: fix unlink on file upload
2021-06-25 7:22 [pve-devel] [PATCH v2 storage] api: status: fix unlink on file upload Lorenz Stechauner
@ 2021-07-22 7:05 ` Lorenz Stechauner
2021-07-29 15:14 ` [pve-devel] applied: " Thomas Lamprecht
1 sibling, 0 replies; 3+ messages in thread
From: Lorenz Stechauner @ 2021-07-22 7:05 UTC (permalink / raw)
To: Lorenz Stechauner, Proxmox VE development discussion
ping
On 25.06.21 09: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>
> ---
changes to v1:
* using 'unlink' instead of '/usr/bin/unlink'
* using '--' now
> 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 72fd851..b4d2e15 100644
> --- a/PVE/API2/Storage/Status.pm
> +++ b/PVE/API2/Storage/Status.pm
> @@ -444,6 +444,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);
>
> @@ -462,10 +463,12 @@ __PACKAGE__->register_method ({
> errmsg => "mkdir failed");
>
> $cmd = ['/usr/bin/scp', @ssh_options, '-p', '--', $tmpfilename, "[$remip]:" . PVE::Tools::shell_quote($dest)];
> + $err_cmd = [@remcmd, 'unlink', '--', $dest];
> } else {
> PVE::Storage::activate_storage($cfg, $param->{storage});
> File::Path::make_path($dirname);
> $cmd = ['cp', '--', $tmpfilename, $dest];
> + $err_cmd = ['unlink', '--', $dest];
> }
>
> my $worker = sub {
> @@ -479,7 +482,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";
^ permalink raw reply [flat|nested] 3+ messages in thread
* [pve-devel] applied: Re: [PATCH v2 storage] api: status: fix unlink on file upload
2021-06-25 7:22 [pve-devel] [PATCH v2 storage] api: status: fix unlink on file upload Lorenz Stechauner
2021-07-22 7:05 ` Lorenz Stechauner
@ 2021-07-29 15:14 ` Thomas Lamprecht
1 sibling, 0 replies; 3+ messages in thread
From: Thomas Lamprecht @ 2021-07-29 15:14 UTC (permalink / raw)
To: Proxmox VE development discussion, Lorenz Stechauner
On 25/06/2021 09: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(-)
>
>
applied, thanks! I cleaned that whole module slightly up afterwards, and
changed the local cleanup to use a perl fn unlink again.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-07-29 15:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-25 7:22 [pve-devel] [PATCH v2 storage] api: status: fix unlink on file upload Lorenz Stechauner
2021-07-22 7:05 ` Lorenz Stechauner
2021-07-29 15:14 ` [pve-devel] applied: " Thomas Lamprecht
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox