Xen-Devel Archive on lore.kernel.org
 help / color / Atom feed
* [OSSTEST PATCH 1/7] target_editfile_kvp_replace: Support changing multiple keys
@ 2021-01-22 15:55 Ian Jackson
  2021-01-22 15:55 ` [OSSTEST PATCH 2/7] target_editfile_kvp_replace: Add a bit of logging Ian Jackson
                   ` (5 more replies)
  0 siblings, 6 replies; 19+ messages in thread
From: Ian Jackson @ 2021-01-22 15:55 UTC (permalink / raw)
  To: xen-devel; +Cc: Ian Jackson

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(-)

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



^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, back to index

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-22 15:55 [OSSTEST PATCH 1/7] target_editfile_kvp_replace: Support changing multiple keys Ian Jackson
2021-01-22 15:55 ` [OSSTEST PATCH 2/7] target_editfile_kvp_replace: Add a bit of logging Ian Jackson
2021-01-22 15:55 ` [OSSTEST PATCH 3/7] ts-xen-install: Rename $commons_config_file Ian Jackson
2021-01-22 15:56 ` [OSSTEST PATCH 4/7] ts-xen-install: Break out @commons_config Ian Jackson
2021-01-22 15:56 ` [OSSTEST PATCH 5/7] ts-xen-install: Honour xenstored target var Ian Jackson
2021-01-22 15:56 ` [OSSTEST PATCH 6/7] mfi-common: Provide stripy_rand Ian Jackson
2021-01-22 15:56 ` [OSSTEST PATCH 7/7] make-flight: Stripy xenstored Ian Jackson
2021-01-22 16:07   ` Andrew Cooper
2021-01-22 16:22     ` Ian Jackson
2021-01-22 16:24       ` Jürgen Groß
2021-01-22 16:26         ` Ian Jackson
2021-01-22 16:29           ` Jürgen Groß
2021-01-22 16:29       ` Andrew Cooper
2021-01-22 17:37         ` [OSSTEST PATCH 7/7] make-flight: Stripy xenstored [and 2 more messages] Ian Jackson
2021-01-22 17:52           ` Andrew Cooper
2021-01-28 14:26             ` Ian Jackson
2021-01-22 16:11   ` [OSSTEST PATCH 7/7] make-flight: Stripy xenstored Christian Lindig
2021-01-22 16:36   ` Andrew Cooper
2021-01-22 16:40   ` Edwin Torok

Xen-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/xen-devel/0 xen-devel/git/0.git
	git clone --mirror https://lore.kernel.org/xen-devel/1 xen-devel/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 xen-devel xen-devel/ https://lore.kernel.org/xen-devel \
		xen-devel@lists.xenproject.org xen-devel@lists.xen.org
	public-inbox-index xen-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.xenproject.lists.xen-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git