Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
8e943639
Commit
8e943639
authored
Nov 20, 2016
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Plain Diff
Issue #28666: Now test.support.rmtree is able to remove unwritable or
unreadable directories on Windows too.
parents
1de32cc8
6b5c9d09
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
15 deletions
+16
-15
Lib/test/support/__init__.py
Lib/test/support/__init__.py
+16
-15
No files found.
Lib/test/support/__init__.py
View file @
8e943639
...
@@ -298,6 +298,16 @@ def unload(name):
...
@@ -298,6 +298,16 @@ def unload(name):
except
KeyError
:
except
KeyError
:
pass
pass
def
_force_run
(
path
,
func
,
*
args
):
try
:
return
func
(
*
args
)
except
OSError
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"
):
if
sys
.
platform
.
startswith
(
"win"
):
def
_waitfor
(
func
,
pathname
,
waitall
=
False
):
def
_waitfor
(
func
,
pathname
,
waitall
=
False
):
# Perform the operation
# Perform the operation
...
@@ -340,7 +350,7 @@ if sys.platform.startswith("win"):
...
@@ -340,7 +350,7 @@ if sys.platform.startswith("win"):
def
_rmtree
(
path
):
def
_rmtree
(
path
):
def
_rmtree_inner
(
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
)
fullname
=
os
.
path
.
join
(
path
,
name
)
try
:
try
:
mode
=
os
.
lstat
(
fullname
).
st_mode
mode
=
os
.
lstat
(
fullname
).
st_mode
...
@@ -350,9 +360,9 @@ if sys.platform.startswith("win"):
...
@@ -350,9 +360,9 @@ if sys.platform.startswith("win"):
mode
=
0
mode
=
0
if
stat
.
S_ISDIR
(
mode
):
if
stat
.
S_ISDIR
(
mode
):
_waitfor
(
_rmtree_inner
,
fullname
,
waitall
=
True
)
_waitfor
(
_rmtree_inner
,
fullname
,
waitall
=
True
)
os
.
rmdir
(
fullname
)
_force_run
(
path
,
os
.
rmdir
,
fullname
)
else
:
else
:
os
.
unlink
(
fullname
)
_force_run
(
path
,
os
.
unlink
,
fullname
)
_waitfor
(
_rmtree_inner
,
path
,
waitall
=
True
)
_waitfor
(
_rmtree_inner
,
path
,
waitall
=
True
)
_waitfor
(
os
.
rmdir
,
path
)
_waitfor
(
os
.
rmdir
,
path
)
else
:
else
:
...
@@ -366,17 +376,8 @@ else:
...
@@ -366,17 +376,8 @@ else:
except
OSError
:
except
OSError
:
pass
pass
def
force_run
(
path
,
func
,
*
args
):
try
:
return
func
(
*
args
)
except
OSError
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
):
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
)
fullname
=
os
.
path
.
join
(
path
,
name
)
try
:
try
:
mode
=
os
.
lstat
(
fullname
).
st_mode
mode
=
os
.
lstat
(
fullname
).
st_mode
...
@@ -384,9 +385,9 @@ else:
...
@@ -384,9 +385,9 @@ else:
mode
=
0
mode
=
0
if
stat
.
S_ISDIR
(
mode
):
if
stat
.
S_ISDIR
(
mode
):
_rmtree_inner
(
fullname
)
_rmtree_inner
(
fullname
)
force_run
(
path
,
os
.
rmdir
,
fullname
)
_
force_run
(
path
,
os
.
rmdir
,
fullname
)
else
:
else
:
force_run
(
path
,
os
.
unlink
,
fullname
)
_
force_run
(
path
,
os
.
unlink
,
fullname
)
_rmtree_inner
(
path
)
_rmtree_inner
(
path
)
os
.
rmdir
(
path
)
os
.
rmdir
(
path
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment