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
diff --git a/project.py b/project.py
index de5c791..ba18337 100644
--- a/project.py
+++ b/project.py
@@ -2299,10 +2299,10 @@
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 @@
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 @@
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 @@
self._CopyAndLinkFiles()
except Exception:
if init_dotgit:
- shutil.rmtree(dotgit)
+ platform_utils.rmtree(dotgit)
raise
def _gitdir_path(self, path):