New submission from Laurent Mazuel: 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' ---------- components: Library (Lib) messages: 262584 nosy: Laurent.Mazuel priority: normal severity: normal status: open title: tempfile.TemporaryDirectory() cleanup exception on Windows if readonly files created type: enhancement versions: Python 3.5 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue26660> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com