-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Fix file.append #34432
Fix file.append #34432
Conversation
This concerns me. The first thing that's happening here is that a I'm a little confused by your description as well. What I was seeing when testing this was that in the current incarnation of 2015.8, only an additional line was being added which is what I would expect. However, your PR seems to modify every single line in the file. Example:
This is not at all the behavior that I would expect from
I am going to cc: @thatch45 and @terminalmage here for additional review. |
) | ||
else: | ||
ret['comment'] = 'File {0} is in correct state'.format(name) | ||
ret['result'] = True | ||
return ret | ||
|
||
if len(append_lines): |
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.
Do we need the len()
here?
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.
The len()
determines if there were any lines appended to the file.
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.
right, but an empty list evaluates to False, and a list with stuff evaluates to True, making the len unnecessary:
https://docs.python.org/2/library/stdtypes.html#truth-value-testing
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.
I'm a dufus.....
Looking at this, I wonder what we need the state changes for? I am just not following that. |
@cachedout @thatch45 I think @jfindlay explained the problem pretty well in https://gist.github.com/jfindlay/45fb2de7b5970ef773033013632a36d6 I will do some more testing |
@cachedout I believe your original file was missing a newline code after |
@twangboy The point is that |
@cachedout 'The quick brown fox' was not modified.... It's the diff comparison that thinks it was.... I submitted a fix. When it read the file before the append it was reading the line endings. After the append it was not. So, the compare showed that the line was changed. |
Rebased |
What does this PR do?
Fixes problem with extra newline characters in the file and the state return.
What issues does this PR fix or reference?
https://github.com/saltstack/zh/issues/783
Previous Behavior
Previously the salt state was iterating through each line in the source file and calling file.append. File.append checks for a newline character at the end of the file and adds one if it's missing. So there was a newline character being added on every line.
New Behavior
The salt state now sends a list of lines to be added to the file.append function.
Tests written?
Tested on Windows and Ubuntu
No