]> git.proxmox.com Git - qemu-server.git/commitdiff
parse config: factor out finishing reading the description comment
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 16 Nov 2022 10:23:01 +0000 (11:23 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 16 Nov 2022 10:23:01 +0000 (11:23 +0100)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
PVE/QemuServer.pm

index 3b640891c7050f9231abd2c07d7c939ab5ed42ba..1607ce27fac44f7b5325f076d0d47580e9e82d24 100644 (file)
@@ -2425,6 +2425,13 @@ sub parse_vm_config {
 
     my $conf = $res;
     my $descr;
+    my $finish_description = sub {
+       if (defined($descr)) {
+           $descr =~ s/\s+$//;
+           $conf->{description} = $descr;
+       }
+       $descr = undef;
+    };
     my $section = '';
 
     my @lines = split(/\n/, $raw);
@@ -2433,11 +2440,7 @@ sub parse_vm_config {
 
        if ($line =~ m/^\[PENDING\]\s*$/i) {
            $section = 'pending';
-           if (defined($descr)) {
-               $descr =~ s/\s+$//;
-               $conf->{description} = $descr;
-           }
-           $descr = undef;
+           $finish_description->();
            $conf = $res->{$section} = {};
            next;
        } elsif ($line =~ m/^\[special:cloudinit\]\s*$/i) {
@@ -2448,11 +2451,7 @@ sub parse_vm_config {
 
        } elsif ($line =~ m/^\[([a-z][a-z0-9_\-]+)\]\s*$/i) {
            $section = $1;
-           if (defined($descr)) {
-               $descr =~ s/\s+$//;
-               $conf->{description} = $descr;
-           }
-           $descr = undef;
+           $finish_description->();
            $conf = $res->{snapshots}->{$section} = {};
            next;
        }
@@ -2506,10 +2505,7 @@ sub parse_vm_config {
        }
     }
 
-    if (defined($descr)) {
-       $descr =~ s/\s+$//;
-       $conf->{description} = $descr;
-    }
+    $finish_description->();
     delete $res->{snapstate}; # just to be sure
 
     return $res;