X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=src%2FPVE%2FSectionConfig.pm;h=6273afa35a22cb09ca14d2f010f5aad8b96dba47;hb=885641fb6a52ce2095180d912070af378026d631;hp=be13056eb1106468256fb05179f03b8b630d02b0;hpb=0d8380351a0276728d1d2b1e260cec0c8b1f204a;p=pve-common.git diff --git a/src/PVE/SectionConfig.pm b/src/PVE/SectionConfig.pm index be13056..6273afa 100644 --- a/src/PVE/SectionConfig.pm +++ b/src/PVE/SectionConfig.pm @@ -26,6 +26,9 @@ sub register { my $type = $class->type(); my $pdata = $class->private(); + die "duplicate plugin registration (type = $type)" + if defined($pdata->{plugins}->{$type}); + my $plugindata = $class->plugindata(); $pdata->{plugindata}->{$type} = $plugindata; $pdata->{plugins}->{$type} = $class; @@ -68,7 +71,6 @@ sub createSchema { }; foreach my $p (keys %$propertyList) { - next if $p eq 'type'; if (!$propertyList->{$p}->{optional}) { $props->{$p} = $propertyList->{$p}; next; @@ -102,7 +104,7 @@ sub createSchema { } sub updateSchema { - my ($class) = @_; + my ($class, $single_class) = @_; my $pdata = $class->private(); my $propertyList = $pdata->{propertyList}; @@ -110,8 +112,15 @@ sub updateSchema { my $props = {}; + my $filter_type = $class->type() if $single_class; + foreach my $p (keys %$propertyList) { next if $p eq 'type'; + + my $copts = $class->options(); + + next if defined($filter_type) && !defined($copts->{$p}); + if (!$propertyList->{$p}->{optional}) { $props->{$p} = $propertyList->{$p}; next; @@ -119,7 +128,6 @@ sub updateSchema { my $modifyable = 0; - my $copts = $class->options(); $modifyable = 1 if defined($copts->{$p}) && !$copts->{$p}->{fixed}; foreach my $t (keys %$plugins) { @@ -182,7 +190,7 @@ sub init { } $propertyList->{type}->{type} = 'string'; - $propertyList->{type}->{enum} = [keys %$plugins]; + $propertyList->{type}->{enum} = [sort keys %$plugins]; } sub lookup { @@ -201,7 +209,7 @@ sub lookup_types { my $pdata = $class->private(); - return [ keys %{$pdata->{plugins}} ]; + return [ sort keys %{$pdata->{plugins}} ]; } sub decode_value { @@ -394,8 +402,12 @@ my $format_config_line = sub { my $ct = $schema->{type}; + die "property '$key' contains a line feed\n" + if ($key =~ m/[\n\r]/) || ($value =~ m/[\n\r]/); + if ($ct eq 'boolean') { - return $value ? "\t$key\n" : ''; + return "\t$key " . ($value ? 1 : 0) . "\n" + if defined($value); } else { return "\t$key $value\n" if "$value" ne ''; }