From fae4505cde777ff53057f867e10d40aebb0b5a31 Mon Sep 17 00:00:00 2001 From: Ted Zlatanov Date: Tue, 27 Oct 2020 07:14:09 -0400 Subject: [PATCH 1/2] Fix converge bug with anchoring and add converge_prepend In my testing with 3.16, the deletion doesn't work today, so `converge` is not functioning properly. Add `converge_prepend` with same behavior and bugfix, but inserting at start of content. --- lib/files.cf | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/files.cf b/lib/files.cf index 523d56aef5..5bb6eba7f7 100644 --- a/lib/files.cf +++ b/lib/files.cf @@ -1071,11 +1071,30 @@ bundle edit_line converge(marker, lines) "regex" string => escape($(marker)); delete_lines: - "$(regex)" comment => "Delete lines matching the marker"; + ".*$(regex).*" comment => "Delete lines matching the marker"; insert_lines: "$(lines)" comment => "Insert the given lines"; } +bundle edit_line converge_prepend(marker, lines) +# @brief Converge `lines` marked with `marker` to start of content +# +# Any content marked with `marker` is removed, then `lines` are +# inserted at *start* of content. Every `line` should contain `marker`. +# +# @param marker The marker (not a regular expression; will be escaped) +# @param lines The lines to insert; all must contain `marker` +{ + vars: + "regex" string => escape($(marker)); + + delete_lines: + ".*$(regex).*" comment => "Delete lines matching the marker"; + insert_lines: + "$(lines)" location => start, comment => "Insert the given lines"; +} + + bundle edit_line fstab_option_editor(method, mount, option) # @brief Add or remove `/etc/fstab` options for a mount # From 18b9ba19091942eb3d4e6b1eb9ec1af06ab52b83 Mon Sep 17 00:00:00 2001 From: Ted Zlatanov Date: Wed, 28 Oct 2020 06:09:33 -0400 Subject: [PATCH 2/2] Add usage clarification and small example of multiline --- lib/files.cf | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/files.cf b/lib/files.cf index 5bb6eba7f7..27519120fe 100644 --- a/lib/files.cf +++ b/lib/files.cf @@ -1077,11 +1077,19 @@ bundle edit_line converge(marker, lines) } bundle edit_line converge_prepend(marker, lines) -# @brief Converge `lines` marked with `marker` to start of content +# @brief Converge `lines` marked with `marker` to start of content. # # Any content marked with `marker` is removed, then `lines` are # inserted at *start* of content. Every `line` should contain `marker`. # +# This is helpful for files where order matters, like `pam.d/common-auth`, +# and you want the content at the top. If you want to maintain the order +# of multiple lines, pass one item with a newline in it like this: +# ``` +# "" usebundle => converge_prepend("covfefe", "first line of covfefe +# second line of covfefe"); +# ``` +# # @param marker The marker (not a regular expression; will be escaped) # @param lines The lines to insert; all must contain `marker` {