Skip to content

Commit

Permalink
[backend] BSDispatcher::list2struct: add to arrays in leaf elements
Browse files Browse the repository at this point in the history
The old code modified the old entry instead. Thus, a prjconstraint
of
    hardware:cpu:flag exclude=true EL0
    hardware:cpu:flag cpuid
resulted in the EL0 exclude being ignored. We now default to
"add" mode for leaf elements. You can force the old "overwrite last
entry" mode by adding a '!' character, like:
    hardware:cpu:flag! cpuid
  • Loading branch information
mlschroe committed Jul 8, 2021
1 parent 953e183 commit a3b365e
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/backend/BSDispatcher/Constraints.pm
Expand Up @@ -223,13 +223,15 @@ sub list2struct {
my @loc = split(':', shift @l);
my @how = @$dtd;
my $out = $top;
my $outref;
while (@loc) {
my $am = shift @how;
my $e = shift @loc;
my $addit;
my $delit;
my ($addit, $delit, $modit);
$addit = 1 if $e =~ s/\+$//;
$delit = 1 if !$addit && $e =~ s/=$//;
$modit = 1 if !$addit && !$delit && $e =~ s/!$//;
$modit = 1 if !$addit && !$delit && @loc; # default non-leaf elements
my %known = map {ref($_) ? (!@$_ ? () : (ref($_->[0]) ? $_->[0]->[0] : $_->[0] => $_)) : ($_=> $_)} @how;
my $ke = $known{$e};
die("unknown element: $e\n") unless $ke;
Expand All @@ -241,25 +243,28 @@ sub list2struct {
if (!ref($ke) || (@$ke == 1 && !ref($ke->[0]))) {
die("element '$e' has subelements\n") if @loc;
die("element '$e' contains attributes\n") if @l && $l[0] =~ /=/;
delete $out->{$e} unless $addit;
if (!ref($ke)) {
delete $out->{$e} unless $addit;
die("element '$e' must be singleton\n") if exists $out->{$e};
$out->{$e} = join(' ', @l);
} else {
delete $out->{$e} if $modit;
push @{$out->{$e}}, @l;
}
@how = ();
} else {
my $nout = {};
if (@$ke == 1) {
$nout = pop @{$out->{$e}} if exists $out->{$e} && !$addit;
$nout = pop @{$out->{$e}} if exists $out->{$e} && $modit;
push @{$out->{$e}}, $nout;
@how = @{$ke->[0]};
$outref = $out->{$e};
} else {
$nout = delete $out->{$e} if exists $out->{$e} && !$addit;
die("element '$e' must be singleton\n") if exists $out->{$e};
$out->{$e} = $nout;
@how = @$ke;
$outref = undef;
}
$out = $nout;
}
Expand All @@ -285,8 +290,10 @@ sub list2struct {
shift @l;
}
if (@l) {
die("element '$am' contains content\n") unless $known{'_content'};
$out->{'_content'} = join(' ', @l);
die("element '$am' contains content\n") unless $known{'_content'};
@l = ( join(' ', @l) ) unless $outref;
$out->{'_content'} = shift @l;
push @$outref, BSUtil::clone({ %$out, '_content' => $_ }) for @l;
}
}
};
Expand Down

0 comments on commit a3b365e

Please sign in to comment.