Commit f372610b authored by pgervais@chromium.org's avatar pgervais@chromium.org

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
parent b1b5457a
......@@ -11,6 +11,7 @@ import logging
import optparse
import os
import tempfile
import time
import subprocess
import sys
import urlparse
......@@ -60,8 +61,22 @@ class Lockfile(object):
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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment