use strict;
use warnings;
-use File::Path;
use File::Basename;
-use PVE::Tools;
-use PVE::INotify;
+use File::Path;
+
use PVE::Cluster;
+use PVE::Exception qw(raise_param_exc);
+use PVE::INotify;
+use PVE::JSONSchema qw(get_standard_option);
+use PVE::RESTHandler;
+use PVE::RPCEnvironment;
use PVE::RRD;
-use PVE::Storage;
+use PVE::Tools qw(run_command);
+
use PVE::API2::Storage::Content;
-use PVE::API2::Storage::PruneBackups;
use PVE::API2::Storage::FileRestore;
-use PVE::RESTHandler;
-use PVE::RPCEnvironment;
-use PVE::JSONSchema qw(get_standard_option);
-use PVE::Exception qw(raise_param_exc);
+use PVE::API2::Storage::PruneBackups;
+use PVE::Storage;
use base qw(PVE::RESTHandler);
content => {
description => "Content type.",
type => 'string', format => 'pve-storage-content',
+ enum => ['iso', 'vztmpl'],
},
filename => {
- description => "The name of the file to create.",
+ description => "The name of the file to create. Caution: This will be normalized!",
+ maxLength => 255,
type => 'string',
},
tmpfilename => {
# 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);
my @remcmd = ('/usr/bin/ssh', @ssh_options, $remip, '--');
- eval {
- # activate remote storage
- PVE::Tools::run_command([@remcmd, '/usr/sbin/pvesm', 'status',
- '--storage', $param->{storage}]);
+ eval { # activate remote storage
+ run_command([@remcmd, '/usr/sbin/pvesm', 'status', '--storage', $param->{storage}]);
};
die "can't activate storage '$param->{storage}' on node '$node': $@\n" if $@;
- PVE::Tools::run_command([@remcmd, '/bin/mkdir', '-p', '--', PVE::Tools::shell_quote($dirname)],
- errmsg => "mkdir failed");
+ run_command(
+ [@remcmd, '/bin/mkdir', '-p', '--', PVE::Tools::shell_quote($dirname)],
+ 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 {
print "file size is: $size\n";
print "command: " . join(' ', @$cmd) . "\n";
- eval { PVE::Tools::run_command($cmd, errmsg => 'import failed'); };
+ eval { run_command($cmd, errmsg => 'import failed'); };
if (my $err = $@) {
- unlink $dest;
+ eval { run_command($err_cmd) };
die $err;
}
print "finished file import successfully\n";
},
filename => {
description => "The name of the file to create. Caution: This will be normalized!",
+ maxLength => 255,
type => 'string',
},
checksum => {
PVE::Tools::download_file_from_url("$path/$filename", $url, $opts);
};
- return $rpcenv->fork_worker('download', $filename, $user, $worker);
+ my $worker_id = PVE::Tools::encode_text($filename); # must not pass : or the like as w-ID
+
+ return $rpcenv->fork_worker('download', $worker_id, $user, $worker);
}});
1;