Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Modile file, State=absent ignores recursive=false and does rmtree automatically for directory #52653
File module ignores recursive=no and force=no and does rmtree on previous state=directory state=absent.
OS / ENVIRONMENT
STEPS TO REPRODUCE
We have a large number of hosts and encountered this when removing links across our inventory. One host the link was an actual directory and we had presumed that setting recursive=false would have raised an error and not gone ahead and blown away hundred of gigs of data.
shutil.rmtree should only be executed if previous state=directory AND recursive is set, otherwise unlink should be attempted, which will fail for non-empty directories.