]> xenbits.xensource.com Git - people/aperard/osstest.git/commitdiff
target_editfile_kvp_replace: Support changing multiple keys
authorIan Jackson <iwj@xenproject.org>
Fri, 22 Jan 2021 14:36:20 +0000 (14:36 +0000)
committerIan Jackson <iwj@xenproject.org>
Fri, 22 Jan 2021 15:39:53 +0000 (15:39 +0000)
No functional change with existing callers.

Signed-off-by: Ian Jackson <iwj@xenproject.org>
Osstest/TestSupport.pm

index 9362a865f14cec6816d36a1ab48ece4f2d07617c..d2558f3172067c024a1f20800a37d5c4d7eca913 100644 (file)
@@ -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',@_); }