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 |
waynew
left a comment
There was a problem hiding this comment.
Definitely love the idea behind this! @Ch3LL asked for some feedback:
- I don't like
rmdiras the state name - sometimes we can't help but to name the states as verbs instead of adjectives, but generally.removedor.absentfor states, with.removeor similar action words for the execution modules. I like Thomas'prunedsuggestion. It's better thandir_absentwhich was the only thing I could think of 😂 That also naturally leads to the module beingpruneand the statepruned, which I like a lot. I guess that would mean that we'd just leavermdiras is and create aprunemodule, 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
forloop 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 |
waynew
left a comment
There was a problem hiding this comment.
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.prunedstate 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.rmdirexecution 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 forTruereturns on success and then using a broadelsestatement, because "falsey" behavior wasn't possible withTruevsstrreturns.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.