Skip to content

Commit

Permalink
Be more specific in rmtree/_remove_readonly + reraise exceptions
Browse files Browse the repository at this point in the history
Reraise exceptions, so that failure to delete files during error
handling doesn't throw away the original exception on Python 2.
  • Loading branch information
pv committed Jun 25, 2017
1 parent 644fca0 commit 054a73a
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions asv/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -965,10 +965,19 @@ def long_path(path):
return "\\\\?\\" + os.path.abspath(path)

def _remove_readonly(func, path, exc_info):
"""Clear the readonly bit and reattempt the removal;
Windows rmtree doesn't do this by default"""
os.chmod(path, stat.S_IWRITE)
func(path)
"""Try harder to remove files on Windows"""

if func in (os.remove, os.rmdir) and not os.access(path, os.W_OK):
# Clear read-only flag and try again
os.chmod(path, stat.S_IWRITE)
try:
func(path)
return
except OSError:
pass

# Reraise original error
six.reraise(*exc_info)

def long_path_open(filename, *a, **kw):
return open(long_path(filename), *a, **kw)
Expand Down

0 comments on commit 054a73a

Please sign in to comment.