]> git.proxmox.com Git - pve-storage.git/commitdiff
api: status: fix unlink on file upload
authorLorenz Stechauner <l.stechauner@proxmox.com>
Fri, 25 Jun 2021 07:22:40 +0000 (09:22 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 29 Jul 2021 15:12:40 +0000 (17:12 +0200)
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

index 796ab6699b996763264161013dd346e53db2ab68..13bf4b4044212f1baae48111db14bbd66103e06f 100644 (file)
@@ -448,6 +448,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);
 
@@ -466,10 +467,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 {
@@ -483,7 +486,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";