Fix silent flag in file.directory recurse (#60597)#69774
Open
ggiesen wants to merge 2 commits into
Open
Conversation
The silence marker for recurse was assigned before the check_perms walk loop, so the per-file and per-dir change notifications gathered inside the loop repopulated ret["changes"] and overrode it. Move the marker reset to after the walk loop (but before the clean block, so removed entries are preserved) so individual change notifications are suppressed as documented. Fixes saltstack#60597
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.
What does this PR do?
Fixes the
silentoption offile.directory'srecurseso that individual per-file and per-directory change notifications are actually suppressed.In
salt/states/file.pydirectory(), the silence marker (ret["changes"] = {"recursion": "Changes silenced"}) was assigned before thefile.check_permswalk loop. Eachcheck_permscall inside the loop mutates the sameretand repopulatesret["changes"], so the marker was immediately overwritten and every visited file/dir still showed up in the output. This PR moves the marker reset to just after the walk loop (and before thecleanblock, soclean'sremovedentries are preserved).Note: the
silentflag belongs insiderecurse(for examplerecurse: [user, group, mode, silent]), not at the state top level.What issues does this PR fix or reference?
Fixes #60597
Previous Behavior
With
silentin therecurseset,file.directorystill emitted a change notification for every file and directory touched by the recursive permission enforcement, instead of the single "Changes silenced" marker documented forsilent.New Behavior
With
silentin therecurseset,ret["changes"]is{"recursion": "Changes silenced"}only. Anyremovedentries from a concurrentclean=Truerun are still reported. Runs withoutsilentare unchanged and continue to report individual changes.Merge requirements satisfied?
recurse/silentdocumentation already describes this behavior)changelog/60597.fixed.md)tests/pytests/unit/states/file/test_directory.py):test_directory_recurse_silent_suppresses_changes_60597: production-shape callrecurse=["mode", "silent"]with a walk yielding a child file and dir; assertsret["changes"] == {"recursion": "Changes silenced"}(fails before the fix).test_directory_recurse_without_silent_still_reports_changes_60597: must-not-regress;recurse=["mode"]still reports the child file/dir changes and never adds arecursionkey.test_directory_recurse_silent_preserves_clean_removed_60597: withclean=True, the silence marker and theremovedentry coexist, verifying the reset runs before thecleanblock.Commits signed with GPG? No