Workaround shutil.rmtree limitation on Windows

By default, shutil.rmtree raises an exception when deleting readonly
files on Windows.

Replace all shutil.rmtree with platform_utils.rmtree, which adds an
error handler to make files read-write when they can't be deleted.

Change-Id: I9cfea9a7b3703fb16a82cf69331540c2c179ed53
This commit is contained in:
Renaud Paquay
2016-11-03 10:37:53 -07:00
committed by David Pursehouse
parent d5cec5e752
commit a65adf74f9
5 changed files with 27 additions and 12 deletions

View File

@ -2299,10 +2299,10 @@ class Project(object):
print("Retrying clone after deleting %s" %
self.gitdir, file=sys.stderr)
try:
shutil.rmtree(os.path.realpath(self.gitdir))
platform_utils.rmtree(os.path.realpath(self.gitdir))
if self.worktree and os.path.exists(os.path.realpath
(self.worktree)):
shutil.rmtree(os.path.realpath(self.worktree))
platform_utils.rmtree(os.path.realpath(self.worktree))
return self._InitGitDir(mirror_git=mirror_git, force_sync=False)
except:
raise e
@ -2344,9 +2344,9 @@ class Project(object):
self.config.SetString('core.bare', None)
except Exception:
if init_obj_dir and os.path.exists(self.objdir):
shutil.rmtree(self.objdir)
platform_utils.rmtree(self.objdir)
if init_git_dir and os.path.exists(self.gitdir):
shutil.rmtree(self.gitdir)
platform_utils.rmtree(self.gitdir)
raise
def _UpdateHooks(self):
@ -2516,7 +2516,7 @@ class Project(object):
except GitError as e:
if force_sync:
try:
shutil.rmtree(dotgit)
platform_utils.rmtree(dotgit)
return self._InitWorkTree(force_sync=False, submodules=submodules)
except:
raise e
@ -2536,7 +2536,7 @@ class Project(object):
self._CopyAndLinkFiles()
except Exception:
if init_dotgit:
shutil.rmtree(dotgit)
platform_utils.rmtree(dotgit)
raise
def _gitdir_path(self, path):