-
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
Add file pruned state #62179
Add file pruned state #62179
Conversation
looks like the windows test failures are related to these changes |
I feel like this would be better as a |
|
re-run pr-debian-10-amd64-py3-pytest |
re-run pr-ubuntu-2004-amd64-py3-tcp-pytest |
Also, |
open to suggestions |
re-run pr-centos-7-x86_64-py3-m2crypto-pytest |
looks like there is a merge conflict. Also maybe dir_absent instead of rmdir? Let me ask the rest of the core team what they think of the naming of the state function here. |
personally this seems more like a pruned_tree more than absent or rmdir. |
re-run pr-debian-11-amd64-py3-pytest |
1 similar comment
re-run pr-debian-11-amd64-py3-pytest |
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.
Definitely love the idea behind this! @Ch3LL asked for some feedback:
- I don't like
rmdir
as the state name - sometimes we can't help but to name the states as verbs instead of adjectives, but generally.removed
or.absent
for states, with.remove
or similar action words for the execution modules. I like Thomas'pruned
suggestion. It's better thandir_absent
which was the only thing I could think of 😂 That also naturally leads to the module beingprune
and the statepruned
, which I like a lot. I guess that would mean that we'd just leavermdir
as is and create aprune
module, if we wanted to make that change. - I have some thoughts about the deleting what we can but then failing. Maybe it doesn't matter and it's OK to partially fail. We could check that at least the folders are empty before attempting to delete all of them - basically do the existing
for
loop but instead of
os.rmdir(subdir_path)
deleted.append(subdir_path)
do something like
if os.listdir(subdir_path):
errors.append([subdir_path, "Directory is not empty"])
else:
to_delete.append(subdir_path)
for dir in to_delete:
try:
os.rmdir(dir)
except OSError as exc:
...
But... I don't know if that's super important 🤷 - anyway, just my thoughts - I don't feel super strongly about them (aside from liking adjectives for states and verbs for modules)
re-run pr-ubuntu-2204-amd64-py3-pytest |
@waynew and @whytewolf can you re-review please |
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 good with this 👍 I did just realize that it might just be worth noting in the documentation that it will take the steamroller approach - i.e. it will prune whatever directories it can, rather than bailing out either at the first error or looking before it leaps.
I don't think it should hold up merging the PR but it might be worth a follow-up PR 🤷
What does this PR do?
This PR adds a
file.pruned
state which can delete empty directories within a given root.What issues does this PR fix or reference?
Fixes: #62178
Previous Behavior
No native state supported this workflow.
New Behavior
Empty directories can easily be pruned from a tree. Note that the
file.rmdir
execution module operation was also slightly changed. Errors encountered previously returned the error string. This was changed to a more uniform boolean return. This is unlikely to affect any logic as users were most likely checking forTrue
returns on success and then using a broadelse
statement, because "falsey" behavior wasn't possible withTrue
vsstr
returns.Merge requirements satisfied?
[NOTICE] Bug fixes or features added to Salt require tests.
Commits signed with GPG?
Yes
Please review Salt's Contributing Guide for best practices.
See GitHub's page on GPG signing for more information about signing commits with GPG.