]> git.proxmox.com Git - qemu-server.git/commitdiff
api: qga file-write: code/style cleanups/refactoring
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 10 Feb 2022 15:26:53 +0000 (16:26 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 10 Feb 2022 15:26:53 +0000 (16:26 +0100)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
PVE/API2/Qemu/Agent.pm

index 9a061914d675bd69de4367a09d2a89415c100aa8..034b1504e323f2d65f39eb8c16ad3b3b2775f006 100644 (file)
@@ -471,14 +471,13 @@ __PACKAGE__->register_method({
            },
            content => {
                type => 'string',
-               maxLength => 60*1024, # 60k, smaller than our 64k POST limit
+               maxLength => 60 * 1024, # 60k, smaller than our 64k POST limit
                description => "The content to write into the file."
            },
            encode => {
                type => 'boolean',
-               description => "If set the content will be encoded as base64"
-                   ." (required by QEMU). Otherwise the content needs to be encoded"
-                   ." beforehand. (Default is true)",
+               description => "If set, the content will be encoded as base64 (required by QEMU)."
+                   ."Otherwise the content needs to be encoded beforehand - defaults to true.",
                optional => 1,
                default => 1,
            },
@@ -490,14 +489,10 @@ __PACKAGE__->register_method({
 
        my $vmid = $param->{vmid};
        my $encode = $param->{encode} // 1;
-       my $buf;
-       if ($encode) {
-           $buf = encode_base64($param->{content});
-       } else {
-           die "content is not base64 encoded\n"
-               if $param->{content} !~ m@^(?:[A-Z0-9+/]{4})*(?:[A-Z0-9+/]{2}==|[A-Z0-9+/]{3}=)?$@mi;
-           $buf = $param->{content};
-       }
+
+       my $buf = $encode ? encode_base64($param->{content}) : $param->{content};
+       die "content is not base64 encoded\n"
+           if !$encode && $buf !~ m@^(?:[A-Z0-9+/]{4})*(?:[A-Z0-9+/]{2}==|[A-Z0-9+/]{3}=)?$@mi;
 
        my $qgafh = agent_cmd($vmid, "file-open",  { path => $param->{file}, mode => 'wb' }, "can't open file");
        my $write = agent_cmd($vmid, "file-write", { handle => $qgafh, 'buf-b64' => $buf }, "can't write to file");