Skip to content

Commit 4a2ab25

Browse files
committed
Catch OSError on ignore_errors
1 parent 4a9eb37 commit 4a2ab25

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

‎Lib/tempfile.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,10 @@ def onexc(func, path, exc, direntry=None, dir_fd=None):
10361036
dir_fd=dir_fd, fullname=fullpath)
10371037
except FileNotFoundError:
10381038
pass
1039+
except OSError:
1040+
if ignore_errors:
1041+
return
1042+
raise
10391043
elif isinstance(exc, FileNotFoundError):
10401044
pass
10411045
else:

‎Lib/test/test_tempfile.py‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2079,22 +2079,25 @@ def test_modes(self):
20792079
d.cleanup()
20802080
self.assertFalse(os.path.exists(d.name))
20812081

2082-
def test_parent_mode_preserved(self):
2082+
@support.subTests('ignore_errors', (True, False))
2083+
def test_parent_mode_preserved(self, ignore_errors):
20832084
# Test that cleanup does not touch the parent directory,
20842085
# even if that prevents removal.
20852086
for mode in range(8):
20862087
mode <<= 6
20872088
with self.subTest(mode=format(mode, '03o')):
20882089
outer = self.do_create()
20892090
with outer:
2090-
d = self.do_create(dir=outer.name, dirs=2, files=2)
2091+
d = self.do_create(dir=outer.name, dirs=2, files=2,
2092+
ignore_cleanup_errors=ignore_errors)
20912093
with d:
20922094
os.chmod(outer.name, mode)
20932095
orig_mode = os.stat(outer.name).st_mode
20942096
try:
20952097
d.cleanup()
20962098
except PermissionError:
2097-
pass
2099+
if ignore_errors:
2100+
raise
20982101
self.assertEqual(os.stat(outer.name).st_mode, orig_mode)
20992102
outer.cleanup()
21002103
self.assertFalse(os.path.exists(outer.name))

0 commit comments

Comments
 (0)