-
Notifications
You must be signed in to change notification settings - Fork 197
ENT-3417: Added allow_non_convergent to pattern_matching promise in edit_line #6025
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
29c7642 to
0ebf812
Compare
larsewi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add an acceptance test :)
|
@nickanderson can you address the questions @victormlg posted in the PR description? |
0ebf812 to
dfa3472
Compare
| strlcpy(line_buff_cp, line_buff, sizeof(line_buff_cp)); | ||
| strlcpy(after, line_buff_cp + end_off, sizeof(after)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check for truncation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not resolved
|
|
||
| ###################################################### | ||
|
|
||
| bundle agent test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you are including default.cf.sub you can add the meta data with ticket number and description
Sorry, I had responded to @victormlg directly via slack. I don't love the name I am unsure about the non-descructive thing. Maybe it should be boxed in more specifically ... the use case is for the pattern similar to: sed -i 's/PORT=.*/PORT=22/' Basically, I don't know what is there now, but it should be PORT=22 |
Ticket: ENT-3417 Signed-off-by: Victor Moene <victor.moene@northern.tech>
dfa3472 to
2bb8035
Compare
Signed-off-by: Victor Moene <victor.moene@northern.tech>
2bb8035 to
56aac28
Compare
| int needed = snprintf(line_buff + start_off, sizeof(line_buff) - start_off, | ||
| "%s%s", BufferData(replace), after); | ||
| // TODO: gripe if that truncated or failed ! | ||
| if (needed < 0 || needed >= sizeof(line_buff) - start_off) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if (needed < 0 || needed >= sizeof(line_buff) - start_off) { | |
| assert(sizeof(line_buff) >= start_off); | |
| if (needed < 0 || (size_t) needed >= (sizeof(line_buff) - start_off)) { |
| break; | ||
| strlcpy(line_buff_cp, line_buff, sizeof(line_buff_cp)); | ||
| strlcpy(after, line_buff_cp + end_off, sizeof(after)); | ||
| int needed = snprintf(line_buff_cp + start_off, sizeof(line_buff_cp) - start_off, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| strlcpy(line_buff_cp, line_buff, sizeof(line_buff_cp)); | ||
| strlcpy(after, line_buff_cp + end_off, sizeof(after)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not resolved
Added a new attribute
allow_non_convergentin replace_pattern promise to allow for idempotent non-convergent regex.I am a bit ensure on the implementation, but the idea is that we don't want to allow destructive non-convergent regex, such as:
This will replace and rematch the same line indefinitely:
PORT=22 #Some comment #Some comment #Some comment [...]So the idea was to let cfengine match and expand the pattern N times (as before), then we match and expand one more time (N+1), and if the total length of the line is greater, this means that the non-convergent regex is destructive and thus we need to error.