CFE-2663: Select empty region at end of file when select_end_match_eof is set (3.27)#6229
Open
nickanderson wants to merge 5 commits into
Open
CFE-2663: Select empty region at end of file when select_end_match_eof is set (3.27)#6229nickanderson wants to merge 5 commits into
nickanderson wants to merge 5 commits into
Conversation
An insert_lines promise using select_region with select_end_match_eof cannot select the region of the final section when that section header is the last line of the file. The region is empty and sits at the end of the file, SelectRegion() rejects it, and the insertion fails with "could not select an edit region". This test fails today and will pass once SelectRegion() honors select_end_match_eof for an empty region at end of file. Ticket: CFE-2663 Changelog: None Signed-off-by: Nick Anderson <nick@cmdln.org> (cherry picked from commit ebf30a2)
When select_region matched a start delimiter on the last line of the file and include_start_delimiter was false, SelectRegion() rejected the region as an "empty region at the end of file" and the edit failed with "could not select an edit region". This happened even when select_end_match_eof was true, which is meant to let the region extend to the end of the file. Now the empty region at end of file is accepted when select_end_match_eof is set, so a trailing section (its header being the last line of the file) can still be populated by insert_lines and similar promises. Ticket: CFE-2663 Changelog: Title Signed-off-by: Nick Anderson <nick@cmdln.org> (cherry picked from commit c7bcc44)
f33e2cf to
24eb14c
Compare
Signed-off-by: Victor Moene <victor.moene@northern.tech> (cherry picked from commit ff805dd)
Pulls in the macOS build fixes from ENT-14208: the deprecated readdir_r use in unix_dir.c (PR cfengine#280) and the switch to __APPLE__ instead of DARWIN (PR cfengine#281). This unblocks the macOS build for the CFE-2663 backport. Stops deliberately at the ent-14208 merge, short of the CFE-3629 compiler-flag rework (libntech 257982d). That rework enables -Wgnu-folding-constant as an error, which breaks the pre-existing VLA in libpromises/evalfunction.c (char key[key_len]) that master has since removed but these backport branches still carry. Ticket: ENT-14208 Changelog: None Signed-off-by: Nick Anderson <nick@cmdln.org>
03afb74 to
12569da
Compare
While VLAs are supported in C99 and C11, they do pose some portability issues so best to avoid their use. alloca() allocates on the stack frame and is free'd on exit from the function so essentially equivalent. Ticket: ENT-14208 Changelog: none (cherry picked from commit 6e95201)
Member
Author
|
@cf-bottom jenkins please |
|
Sure, I triggered a build: Jenkins: https://ci.cfengine.com/job/pr-pipeline/14150/ Packages: http://buildcache.cfengine.com/packages/testing-pr/jenkins-pr-pipeline-14150/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When an insert_lines (or other edit_line) promise uses select_region with select_end_match_eof => "true", and the select_start delimiter matches the last line of the file, SelectRegion() rejects the (empty) region at EOF and the edit fails with "could not select an edit region". This makes the final section of an INI-style file impossible to populate once it is empty, which is exactly what set_variable_values_ini() / manage_variable_values_ini() hit in the wild.
Ticket: CFE-2663