Make Lockfile._remove_lockfile more robust on win32
Sometimes, removing lockfiles fails on windows, for obscure reasons.
Following advice from gclient_utils.rmtree, lock file removal has
been improved by using the builtin executable 'del' and retrying 3
times in case it fails.
BUG=
Review URL: https://codereview.chromium.org/240653002
git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@264557 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/git_cache.py b/git_cache.py
index 88c55e6..5c1f85a 100755
--- a/git_cache.py
+++ b/git_cache.py
@@ -11,6 +11,7 @@
import optparse
import os
import tempfile
+import time
import subprocess
import sys
import urlparse
@@ -60,8 +61,22 @@
f.close()
def _remove_lockfile(self):
- """Delete the lockfile. Complains (implicitly) if it doesn't exist."""
- os.remove(self.lockfile)
+ """Delete the lockfile. Complains (implicitly) if it doesn't exist.
+
+ See gclient_utils.py:rmtree docstring for more explanation on the
+ windows case.
+ """
+ if sys.platform == 'win32':
+ lockfile = os.path.normcase(self.lockfile)
+ for _ in xrange(3):
+ exitcode = subprocess.call(['cmd.exe', '/c',
+ 'del', '/f', '/q', lockfile])
+ if exitcode == 0:
+ return
+ time.sleep(3)
+ raise LockError('Failed to remove lock: %s' % lockfile)
+ else:
+ os.remove(self.lockfile)
def lock(self):
"""Acquire the lock.