File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -236,7 +236,38 @@ def _rmtree_inner(path):
236
236
else :
237
237
_unlink = os .unlink
238
238
_rmdir = os .rmdir
239
- _rmtree = shutil .rmtree
239
+
240
+ def _rmtree (path ):
241
+ import stat
242
+ try :
243
+ shutil .rmtree (path )
244
+ return
245
+ except EnvironmentError :
246
+ pass
247
+
248
+ def force_run (path , func , * args ):
249
+ try :
250
+ return func (* args )
251
+ except EnvironmentError as err :
252
+ if verbose >= 2 :
253
+ print ('%s: %s' % (err .__class__ .__name__ , err ))
254
+ print ('re-run %s%r' % (func .__name__ , args ))
255
+ os .chmod (path , stat .S_IRWXU )
256
+ return func (* args )
257
+ def _rmtree_inner (path ):
258
+ for name in force_run (path , os .listdir , path ):
259
+ fullname = os .path .join (path , name )
260
+ try :
261
+ mode = os .lstat (fullname ).st_mode
262
+ except EnvironmentError :
263
+ mode = 0
264
+ if stat .S_ISDIR (mode ):
265
+ _rmtree_inner (fullname )
266
+ force_run (path , os .rmdir , fullname )
267
+ else :
268
+ force_run (path , os .unlink , fullname )
269
+ _rmtree_inner (path )
270
+ os .rmdir (path )
240
271
241
272
def unlink (filename ):
242
273
try :
Original file line number Diff line number Diff line change @@ -262,6 +262,9 @@ Documentation
262
262
Tests
263
263
-----
264
264
265
+ - Issue #28666: Now test.test_support.rmtree is able to remove unwritable or
266
+ unreadable directories.
267
+
265
268
- Issue #23839: Various caches now are cleared before running every test file.
266
269
267
270
- Issue #27369: In test_pyexpat, avoid testing an error message detail that
You can’t perform that action at this time.
0 commit comments