@@ -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',@_); }
No functional change with existing callers. Signed-off-by: Ian Jackson <iwj@xenproject.org> --- Osstest/TestSupport.pm | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-)