-
Notifications
You must be signed in to change notification settings - Fork 200
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
augeas modify too much lines #450
Comments
Could you gist or upload the original file somewhere, so we can reproduce it? Please also include the version of Augeas you're using. |
yes, original file is at https://gist.github.com/jreidinger/59d5d2a471ff83a94cab409db2cbe184 version of augeas I am using is jreidinger@linux-vvcf:~/prace/yast/packager/test/data/zypp> rpm -qa augeas it is opensuse 42.2 version. I can check if there is any patch on top of it. |
I check opensuse patches and it is in non-relevant lenses and only one that modify augeas source code is security fix for escaping values which should not relevant to comment removal https://build.opensuse.org/package/view_file/openSUSE:Leap:42.2/augeas/bnc925225-aug_escape.patch?expand=1 |
one idea, can it be caused by fact, that it modify |
another observation I have from my testing. If I remove comment from different section that this do not happen. |
Thanks for the sample file, I can reproduce the issue on Slightly simplified test using |
I think what is happening here is that because a comment 'in the middle' is removed, all other comments slide up one in their formatting, i.e., when That's the sort of surprise that PR #244 tries to address. |
@lutter interesting pull request, can I somehow help with it? like testing? |
@lutter it seems so. Analogously, when I add a comment in the middle, it uses the formatting of the comment that got pushed away. |
@jreidinger if you want to play with that PR a bit that would be most appreciated. The big question in my mind is whether we should just change the behavior of |
@lutter I looked into the code and I cannot understand one thing, can you explain it to me? If I got it right, on loading What is the purpose of such double parsing which leads to inconsistency and, as a consequence, to this bug? |
@mikhirev the surprise doesn't come from the fact that the file is parsed twice, but from how entries in the tree are associated with the stuff that gets ignored during The advantage of this behavior is that you can delete a whole subtree, and if you recreate it exactly the same way it was before, you will also get the same output; in that sense, Augeas is idempotent, which is incredibly useful. The downside is that you have this 'shifting up' behavior that is discussed in this bug. Therefore, this all is a tradeoff between two solutions, neither of which is ideal: either keep Augeas' idempotency or avoid shifting up. I'd love to come up with something that addresses both, but that's turned out to be pretty tricky. |
@lutter for me possible solution can be similar to what I did in my library on top of augeas. When something gets deleted I keep stub of such node and when something new appear, it replace that stub. But if nothing appear then in the end stub is really deleted, so in this case can remove line with it. This way it will be idempotent and also without shifting. JFYI this is how I do writting of modified abstracted tree using augeas https://github.com/config-files-api/config_files_api/blob/master/lib/cfa/augeas_parser/writer.rb#L181 |
@lutter this sounds reasonable. Unfortunately in my particular case minimal changes to files are more important than idempotency (I'm not going to delete entries and recreate them). The solution suggested by @jreidinger seems good: mark tree nodes as deleted instead deleting them immediately. |
@jreidinger Generalizing your approach to work with the full Augeas API would be really hard: in general, users can mix querying the tree and modifying it freely, so that if we keep deleted entries around until 'save', we'd need a lot of hairy bookkeeping to suppress those softdeleted entries when we return results of I am also not sure how this would help in the example that @domcleal posted above. I am wondering if another approach would work: use the behavior from PR #244 for |
I just updated the PR #244 so that if you set the environment variable This is good enough to make the example that @domcleal added to this issue pass (also now part of the PR) I would love to get some more feedback on whether this addresses your issues, @jreidinger and @mikhirev. If things work out, we can add a better way to enable this behavior than through an environment variable. I am not entirely sold that this is the right way to go about it, as it has repercussions for tests etc. and before this could be merged we'd definitely need more work on integrating this better with the rest of Augeas. But all these things are only a concern if the new behavior actually addresses the problem here and doesn't cause new problems. |
Sorry for the long delay. Code from PR #244 performs as desired when |
Hi,
in short problem is when I remove one comment from tree and save file, it modify content over whole file. I am mainly asking for help where to start with debugging as it is a bit usage stopper for augeas for us.
How I can reliable reproduce it:
and resulting diff is big, but in general lot of unnecessary spaces like
and I do not see any pattern in it. sometimes
##
is changed to# #
but sometimes not.I welcome any hint how I can debug what causing it.
The text was updated successfully, but these errors were encountered: