[issue22040] Add a "force" parameter to shutil.rmtree
Nirbheek Chauhan
report at bugs.python.org
Thu May 19 01:01:24 EDT 2016
Nirbheek Chauhan added the comment:
> In other words, on unix shutil.rmtree is *already* 'rm -rf'.
This is not true. See:
$ mkdir testdir && chmod 200 testdir && ls -lhd testdir
d-w------- 2 nirbheek nirbheek 4.0K May 19 10:21 testdir
`rm -rf` works fine on this. But shutil.rmtree borks:
$ python3 -c 'import shutil; shutil.rmtree("testdir")'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib64/python3.5/shutil.py", line 470, in rmtree
onerror(os.lstat, path, sys.exc_info())
File "/usr/lib64/python3.5/shutil.py", line 468, in rmtree
fd = os.open(path, os.O_RDONLY)
PermissionError: [Errno 13] Permission denied: 'testdir'
The -f option to `rm` ensures that it tries its hardest to resolve permissions problems and does not error out if it can't resolve them either. The latter is available via 'ignore_errors', but the former is a missing feature. A shutil.rmtree flag that 'resolves permissions' would be useful on all platforms. Not just Windows.
----------
nosy: +Nirbheek Chauhan
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22040>
_______________________________________
More information about the Python-bugs-list
mailing list