fix #7173: config: drop empty tag list when writing

When the last tag of a container gets removed, for example in the web
UI, the API gets an empty 'tags' value, which then ends up as an empty
'tags:' line in the config and in the output of 'pct config'. As the
config parser reads that line back as a single space, it also gets
written out again on every following config change.

Skip a tag list without any tag when writing the config, which also
cleans up existing configs with such a line on their next change. Keep
it in the pending section, where it is still needed for removing all
tags with a pending change.

Add a basic test for parsing and writing container configs, similar to
the one in qemu-server, to cover this.

Signed-off-by: Michal Fox <me@dualfroz.com>
This commit is contained in:
dualfroz committed 2026-10-02 16:23:46 +02:00
1 parent 8275178ff1
commit 96e2453797
6 files changed
+83 -3

No files matched your search

+4 -2
View File
@@ -1243,7 +1243,7 @@ sub write_pct_config {
}
my $generate_raw_config = sub {
my ($conf) = @_;
my ($conf, $pending) = @_;
my $raw = '';
@@ -1265,6 +1265,8 @@ sub write_pct_config {
my $value = $conf->{$key};
die "detected invalid newline or carriage return inside property '$key'\n"
if $value =~ m/[\r\n]/;
# an empty tag list is only needed as pending change for removing all tags
next if $key eq 'tags' && !$pending && $value =~ m/^\s*$/;
$raw .= "$key: $value\n";
}
@@ -1293,7 +1295,7 @@ sub write_pct_config {
if (scalar(keys %{ $conf->{pending} })) {
$raw .= "\n[pve:pending]\n";
$raw .= &$generate_raw_config($conf->{pending});
$raw .= &$generate_raw_config($conf->{pending}, 1);
}
foreach my $snapname (sort keys %{ $conf->{snapshots} }) {