Message262584
Using tempfile.TemporaryDirectory() in Windows, creating read-only files in this temp directory leads to PermissionError during the cleanup().
This is a direct cause of this one:
https://bugs.python.org/issue19643
And the workaround which was proposed in the issue 19643 and added to the doc here:
https://docs.python.org/3/library/shutil.html?highlight=shutil#rmtree-example
is not used in the TemporaryDirectory implementation.
I don't know if the right solution is to modify the implementation to systematically delete read-only files using the cited workaround, or to add a 'remove_readonly' flag or to update the documentation to clearly says that cleanup will raise a PermissionError if the user creates a read-only file. At least documentation please :)
In my specific usecase I "git clone" in the temp directory, and the .git folder contains read-only files.
Full stacktrace:
Traceback (most recent call last):
File "C:\mycode.py", line 149, in build_libraries
update(generated_path, dest_folder)
File "C:\Program Files\Python35\lib\tempfile.py", line 807, in __exit__
self.cleanup()
File "C:\Program Files\Python35\lib\tempfile.py", line 811, in cleanup
_shutil.rmtree(self.name)
File "C:\Program Files\Python35\lib\shutil.py", line 488, in rmtree
return _rmtree_unsafe(path, onerror)
File "C:\Program Files\Python35\lib\shutil.py", line 378, in _rmtree_unsafe
_rmtree_unsafe(fullname, onerror)
File "C:\Program Files\Python35\lib\shutil.py", line 378, in _rmtree_unsafe
_rmtree_unsafe(fullname, onerror)
File "C:\Program Files\Python35\lib\shutil.py", line 378, in _rmtree_unsafe
_rmtree_unsafe(fullname, onerror)
File "C:\Program Files\Python35\lib\shutil.py", line 378, in _rmtree_unsafe
_rmtree_unsafe(fullname, onerror)
File "C:\Program Files\Python35\lib\shutil.py", line 383, in _rmtree_unsafe
onerror(os.unlink, fullname, sys.exc_info())
File "C:\Program Files\Python35\lib\shutil.py", line 381, in _rmtree_unsafe
os.unlink(fullname)
PermissionError: [WinError 5] Access is denied: 'C:\\Users\\me\\AppData\\Local\\Temp\\tmpk62cp34t\\readonly.file' |
|
Date |
User |
Action |
Args |
2016-03-28 22:22:28 | Laurent.Mazuel | set | recipients:
+ Laurent.Mazuel |
2016-03-28 22:22:28 | Laurent.Mazuel | set | messageid: <1459203748.81.0.389724870435.issue26660@psf.upfronthosting.co.za> |
2016-03-28 22:22:28 | Laurent.Mazuel | link | issue26660 messages |
2016-03-28 22:22:28 | Laurent.Mazuel | create | |
|