Skip to content

Commit

Permalink
Try harder to remove directories on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
pv committed Jun 27, 2015
1 parent 6d48594 commit 109cf33
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
4 changes: 2 additions & 2 deletions asv/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def create(self):

if not self.check_presence():
if os.path.exists(self._path):
shutil.rmtree(self._path)
util.long_path_rmtree(self._path)

if not os.path.exists(self._env_dir):
try:
Expand All @@ -279,7 +279,7 @@ def create(self):
except:
log.error("Failure creating environment for {0}".format(self.name))
if os.path.exists(self._path):
shutil.rmtree(self._path)
util.long_path_rmtree(self._path)
raise

self.save_info_file(self._path)
Expand Down
16 changes: 14 additions & 2 deletions asv/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,8 +798,20 @@ def _long_path_prefix(path):
return path
return "\\\\?\\" + os.path.abspath(path)

def _remove_readonly(func, path, _):
"""Clear the readonly bit and reattempt the removal;
Windows rmtree doesn't do this by default"""
os.chmod(path, stat.S_IWRITE)
func(path)

def long_path_open(filename, *a, **kw):
return open(_long_path_prefix(filename), *a, **kw)

def long_path_rmtree(path, *a, **kw):
shutil.rmtree(_long_path_prefix(path), *a, **kw)
def long_path_rmtree(path, ignore_errors=False):
if ignore_errors:
onerror = None
else:
onerror = _remove_readonly
shutil.rmtree(_long_path_prefix(path),
ignore_errors=ignore_errors,
onerror=onerror)
4 changes: 2 additions & 2 deletions asv/wheel_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def _cleanup_wheel_cache(self):
for name in names[self._wheel_cache_size:]:
path = os.path.join(self._path, name)
if os.path.isdir(path):
shutil.rmtree(path)
util.long_path_rmtree(path)

def build_project_cached(self, env, package, commit_hash):
if self._wheel_cache_size == 0:
Expand All @@ -90,7 +90,7 @@ def build_project_cached(self, env, package, commit_hash):
'--no-deps', '--no-index', build_root])
except util.ProcessError:
# failed -- clean up
shutil.rmtree(cache_path)
util.long_path_rmtree(cache_path)
raise

return self._get_wheel(commit_hash)
Expand Down

0 comments on commit 109cf33

Please sign in to comment.