New submission from Walter White <homerun4...@gmail.com>:
shutil.rmtree fails on readonly files in Windows. Usually people are using the onerror callback to handle file permissions and retry, but that is not possible in this case because it is not triggerd. onerror is only triggered if a OSError is found. In my case the unlink throws a PermissionError Code shutil.rmdir(): try: os.unlink(fullname) except OSError: onerror(os.unlink, fullname, sys.exc_info()) Traceback: Traceback (most recent call last): File "c:\Users\user\test.py", line 121, in <module> shutil.rmtree(shutil.rmtree(working_dir), File "C:\python-3.9.1.amd64\lib\shutil.py", line 740, in rmtree return _rmtree_unsafe(path, onerror) File "C:\python-3.9.1.amd64\lib\shutil.py", line 613, in _rmtree_unsafe _rmtree_unsafe(fullname, onerror) File "C:\python-3.9.1.amd64\lib\shutil.py", line 613, in _rmtree_unsafe _rmtree_unsafe(fullname, onerror) File "C:\python-3.9.1.amd64\lib\shutil.py", line 618, in _rmtree_unsafe onerror(os.unlink, fullname, sys.exc_info()) File "C:\python-3.9.1.amd64\lib\shutil.py", line 616, in _rmtree_unsafe os.unlink(fullname) PermissionError: [WinError 5] Access denied: 'C:\\Users\\user\\somefile.txt' os.stat: st_mode=33060 st_ino=34621422136837665 st_dev=3929268297 st_nlink=1 st_uid=0 st_gid=0 ---------- components: Library (Lib) messages: 389697 nosy: homerun4711 priority: normal severity: normal status: open title: shutil.rmtree fails on readonly files in Windows, onerror not called type: crash versions: Python 3.9 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue43657> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com