[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [OSSTEST PATCH 1/7] target_editfile_kvp_replace: Support changing multiple keys
No functional change with existing callers. Signed-off-by: Ian Jackson <iwj@xxxxxxxxxxxxxx> --- Osstest/TestSupport.pm | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/Osstest/TestSupport.pm b/Osstest/TestSupport.pm index 9362a865..d2558f31 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',@_); } -- 2.20.1
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |