From: Ian Jackson Date: Fri, 22 Jan 2021 14:36:20 +0000 (+0000) Subject: target_editfile_kvp_replace: Support changing multiple keys X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=b369019f0d64ecef3712717d5c2a1aece73cd9ea;p=osstest.git target_editfile_kvp_replace: Support changing multiple keys No functional change with existing callers. Signed-off-by: Ian Jackson --- diff --git a/Osstest/TestSupport.pm b/Osstest/TestSupport.pm index 9362a86..d2558f3 100644 --- a/Osstest/TestSupport.pm +++ b/Osstest/TestSupport.pm @@ -769,25 +769,32 @@ sub teditfileex { if $install; } -# Replace a Key=Value style line in a config file. +# Replace Key=Value style line(s) in a config file. # # To be used as 3rd argument to target_editfile(_root) as: # target_editfile_root($ho, "/path/to/a/file", # sub { target_editfile_kvp_replace($key, $value) }); -sub target_editfile_kvp_replace ($$) +sub target_editfile_kvp_replace { - my ($key,$value) = @_; - my $prnow; - $prnow= sub { + my (%kv) = @_; + my $prnow= sub { + my ($key) = @_; + my $value = $kv{$key}; + return unless defined $value; print ::EO "$key=$value\n" or die $!; - $prnow= sub { }; + delete $kv{$key}; }; while (<::EI>) { - print ::EO or die $! unless m/^$key\b/; - $prnow->() if m/^#$key/; + if (m/^\S+\b/ && exists $kv{$&}) { + $prnow->($&); + } else { + print ::EO or die $!; + } } print ::EO "\n" or die $!; - $prnow->(); + foreach my $key (sort keys %kv) { + $prnow->($key); + } }; sub target_editfile_root ($$$;$$) { teditfileex('root',@_); }