Message223685
It would be useful for shutil.rmtree to have a "force" argument that overrode read-only permission issues, essentially replicating the behaviour of the -f flag in rm -rf (Unix) and the -force parameter of del (Windows Powershell).
It's possible to use the onerror callback to implement this, but it's tricky to get right in a cross-platform manner. See http://stackoverflow.com/questions/2656322, which recommends
def onerror(func, path, exc_info):
if not os.access(path, os.W_OK):
os.chmod(path, stat.S_IWUSR)
func(path)
else:
raise
and http://stackoverflow.com/questions/1889597 which recommends
def remove_readonly(func, path, excinfo):
os.chmod(path, stat.S_IWRITE)
func(path)
It's not clear whether either of these is portable, though (the former looks to me like it's Unix-specific and the latter like it's for Windows, but I'm not sure).
Having the functionality available in the standard library function directly avoids having people write tricky and potentially buggy code for what is a pretty common situation. (In particular, this comes up a lot in code that deletes git checkouts on Windows, where git makes parts of the .git directory readonly). |
|
Date |
User |
Action |
Args |
2014-07-22 19:54:30 | paul.moore | set | recipients:
+ paul.moore |
2014-07-22 19:54:30 | paul.moore | set | messageid: <1406058870.67.0.270826115135.issue22040@psf.upfronthosting.co.za> |
2014-07-22 19:54:30 | paul.moore | link | issue22040 messages |
2014-07-22 19:54:30 | paul.moore | create | |
|