[Python-checkins] cpython (2.7): Issue #28666: Now test.test_support.rmtree is able to remove unwritable or
serhiy.storchaka
python-checkins at python.org
Sun Nov 20 10:43:23 EST 2016
https://hg.python.org/cpython/rev/b51607ea54c5
changeset: 105222:b51607ea54c5
branch: 2.7
parent: 105215:63820871014d
user: Serhiy Storchaka <storchaka at gmail.com>
date: Sun Nov 20 17:42:03 2016 +0200
summary:
Issue #28666: Now test.test_support.rmtree is able to remove unwritable or
unreadable directories on Windows too.
files:
Lib/test/test_support.py | 31 ++++++++++++++-------------
1 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py
--- a/Lib/test/test_support.py
+++ b/Lib/test/test_support.py
@@ -182,6 +182,16 @@
except KeyError:
pass
+def _force_run(path, func, *args):
+ try:
+ return func(*args)
+ except EnvironmentError as err:
+ if verbose >= 2:
+ print('%s: %s' % (err.__class__.__name__, err))
+ print('re-run %s%r' % (func.__name__, args))
+ os.chmod(path, stat.S_IRWXU)
+ return func(*args)
+
if sys.platform.startswith("win"):
def _waitfor(func, pathname, waitall=False):
# Perform the operation
@@ -224,13 +234,13 @@
def _rmtree(path):
def _rmtree_inner(path):
- for name in os.listdir(path):
+ for name in _force_run(path, os.listdir, path):
fullname = os.path.join(path, name)
if os.path.isdir(fullname):
_waitfor(_rmtree_inner, fullname, waitall=True)
- os.rmdir(fullname)
+ _force_run(path, os.rmdir, fullname)
else:
- os.unlink(fullname)
+ _force_run(path, os.unlink, fullname)
_waitfor(_rmtree_inner, path, waitall=True)
_waitfor(os.rmdir, path)
else:
@@ -245,17 +255,8 @@
except EnvironmentError:
pass
- def force_run(path, func, *args):
- try:
- return func(*args)
- except EnvironmentError as err:
- if verbose >= 2:
- print('%s: %s' % (err.__class__.__name__, err))
- print('re-run %s%r' % (func.__name__, args))
- os.chmod(path, stat.S_IRWXU)
- return func(*args)
def _rmtree_inner(path):
- for name in force_run(path, os.listdir, path):
+ for name in _force_run(path, os.listdir, path):
fullname = os.path.join(path, name)
try:
mode = os.lstat(fullname).st_mode
@@ -263,9 +264,9 @@
mode = 0
if stat.S_ISDIR(mode):
_rmtree_inner(fullname)
- force_run(path, os.rmdir, fullname)
+ _force_run(path, os.rmdir, fullname)
else:
- force_run(path, os.unlink, fullname)
+ _force_run(path, os.unlink, fullname)
_rmtree_inner(path)
os.rmdir(path)
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list