So that we can delete descriptions with
qm set <vmid> --descr ''
my $vmid = $1;
my $conf = $res;
my $vmid = $1;
my $conf = $res;
my $section = '';
my @lines = split(/\n/, $raw);
my $section = '';
my @lines = split(/\n/, $raw);
if ($line =~ m/^\[PENDING\]\s*$/i) {
$section = 'pending';
if ($line =~ m/^\[PENDING\]\s*$/i) {
$section = 'pending';
- $conf->{description} = $descr if $descr;
- $descr = '';
+ if (defined($descr)) {
+ $descr =~ s/\s+$//;
+ $conf->{description} = $descr;
+ }
+ $descr = undef;
$conf = $res->{$section} = {};
next;
} elsif ($line =~ m/^\[([a-z][a-z0-9_\-]+)\]\s*$/i) {
$section = $1;
$conf = $res->{$section} = {};
next;
} elsif ($line =~ m/^\[([a-z][a-z0-9_\-]+)\]\s*$/i) {
$section = $1;
- $conf->{description} = $descr if $descr;
- $descr = '';
+ if (defined($descr)) {
+ $descr =~ s/\s+$//;
+ $conf->{description} = $descr;
+ }
+ $descr = undef;
$conf = $res->{snapshots}->{$section} = {};
next;
}
if ($line =~ m/^\#(.*)\s*$/) {
$conf = $res->{snapshots}->{$section} = {};
next;
}
if ($line =~ m/^\#(.*)\s*$/) {
+ $descr = '' if !defined($descr);
$descr .= PVE::Tools::decode_text($1) . "\n";
next;
}
if ($line =~ m/^(description):\s*(.*\S)\s*$/) {
$descr .= PVE::Tools::decode_text($1) . "\n";
next;
}
if ($line =~ m/^(description):\s*(.*\S)\s*$/) {
+ $descr = '' if !defined($descr);
$descr .= PVE::Tools::decode_text($2);
} elsif ($line =~ m/snapstate:\s*(prepare|delete)\s*$/) {
$conf->{snapstate} = $1;
$descr .= PVE::Tools::decode_text($2);
} elsif ($line =~ m/snapstate:\s*(prepare|delete)\s*$/) {
$conf->{snapstate} = $1;
- $conf->{description} = $descr if $descr;
-
+ if (defined($descr)) {
+ $descr =~ s/\s+$//;
+ $conf->{description} = $descr;
+ }
delete $res->{snapstate}; # just to be sure
return $res;
delete $res->{snapstate}; # just to be sure
return $res;
}
my $generate_raw_config = sub {
}
my $generate_raw_config = sub {
+ my ($conf, $pending) = @_;
my $raw = '';
# add description as comment to top of file
my $raw = '';
# add description as comment to top of file
- my $descr = $conf->{description} || '';
- foreach my $cl (split(/\n/, $descr)) {
- $raw .= '#' . PVE::Tools::encode_text($cl) . "\n";
+ if (defined(my $descr = $conf->{description})) {
+ if ($descr) {
+ foreach my $cl (split(/\n/, $descr)) {
+ $raw .= '#' . PVE::Tools::encode_text($cl) . "\n";
+ }
+ } else {
+ $raw .= "#\n" if $pending;
+ }
}
foreach my $key (sort keys %$conf) {
}
foreach my $key (sort keys %$conf) {
if (scalar(keys %{$conf->{pending}})){
$raw .= "\n[PENDING]\n";
if (scalar(keys %{$conf->{pending}})){
$raw .= "\n[PENDING]\n";
- $raw .= &$generate_raw_config($conf->{pending});
+ $raw .= &$generate_raw_config($conf->{pending}, 1);
}
foreach my $snapname (sort keys %{$conf->{snapshots}}) {
}
foreach my $snapname (sort keys %{$conf->{snapshots}}) {
'onboot' => 1,
'shares' => 1,
'startup' => 1,
'onboot' => 1,
'shares' => 1,
'startup' => 1,
};
# hotplug changes in [PENDING]
};
# hotplug changes in [PENDING]