X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=blobdiff_plain;f=src%2FPVE%2FSectionConfig.pm;h=cc03aeaed638db1a4f6c4a736ade97ea90633649;hp=bfe4f8b958aeeedd3d7ba3c0f90904846c8ae55d;hb=3defa1690b966585534135e01f743edae7b8cb41;hpb=df89e5eb156ec9931d19d73c8a5ac3deaf70414f diff --git a/src/PVE/SectionConfig.pm b/src/PVE/SectionConfig.pm index bfe4f8b..cc03aea 100644 --- a/src/PVE/SectionConfig.pm +++ b/src/PVE/SectionConfig.pm @@ -51,7 +51,7 @@ sub plugindata { } sub createSchema { - my ($class) = @_; + my ($class, $skip_type) = @_; my $pdata = $class->private(); my $propertyList = $pdata->{propertyList}; @@ -71,6 +71,8 @@ sub createSchema { }; foreach my $p (keys %$propertyList) { + next if $skip_type && $p eq 'type'; + if (!$propertyList->{$p}->{optional}) { $props->{$p} = $propertyList->{$p}; next; @@ -257,6 +259,10 @@ sub check_value { } } + if ($ct eq 'boolean' || $ct eq 'integer' || $ct eq 'number') { + return $value + 0; # convert to number + } + return $value; } @@ -273,7 +279,7 @@ sub parse_section_header { } sub format_section_header { - my ($class, $type, $sectionId) = @_; + my ($class, $type, $sectionId, $scfg, $done_hash) = @_; return "$type: $sectionId\n"; } @@ -442,19 +448,23 @@ sub write_config { die "unknown section type '$type'\n" if !$opts; - my $data = $class->format_section_header($type, $sectionId); - if ($scfg->{comment}) { + my $done_hash = {}; + + my $data = $class->format_section_header($type, $sectionId, $scfg, $done_hash); + if ($scfg->{comment} && !$done_hash->{comment}) { my $k = 'comment'; my $v = $class->encode_value($type, $k, $scfg->{$k}); $data .= &$format_config_line($propertyList->{$k}, $k, $v); } - $data .= "\tdisable\n" if $scfg->{disable}; + $data .= "\tdisable\n" if $scfg->{disable} && !$done_hash->{disable}; - my $done_hash = { comment => 1, disable => 1}; + $done_hash->{comment} = 1; + $done_hash->{disable} = 1; my @option_keys = sort keys %$opts; foreach my $k (@option_keys) { + next if defined($done_hash->{$k}); next if $opts->{$k}->{optional}; $done_hash->{$k} = 1; my $v = $scfg->{$k};