Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(266)

Side by Side Diff: git_cache.py

Issue 240653002: Make Lockfile._remove_lockfile more robust on win32 (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Fixed indentation Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """A git command for managing a local cache of git repositories.""" 6 """A git command for managing a local cache of git repositories."""
7 7
8 from __future__ import print_function 8 from __future__ import print_function
9 import errno 9 import errno
10 import logging 10 import logging
11 import optparse 11 import optparse
12 import os 12 import os
13 import tempfile 13 import tempfile
14 import time
14 import subprocess 15 import subprocess
15 import sys 16 import sys
16 import urlparse 17 import urlparse
17 18
18 from download_from_google_storage import Gsutil 19 from download_from_google_storage import Gsutil
19 import gclient_utils 20 import gclient_utils
20 import subcommand 21 import subcommand
21 22
22 try: 23 try:
23 # pylint: disable=E0602 24 # pylint: disable=E0602
(...skipping 29 matching lines...) Expand all
53 54
54 def _make_lockfile(self): 55 def _make_lockfile(self):
55 """Safely creates a lockfile containing the current pid.""" 56 """Safely creates a lockfile containing the current pid."""
56 open_flags = (os.O_CREAT | os.O_EXCL | os.O_WRONLY) 57 open_flags = (os.O_CREAT | os.O_EXCL | os.O_WRONLY)
57 fd = os.open(self.lockfile, open_flags, 0o644) 58 fd = os.open(self.lockfile, open_flags, 0o644)
58 f = os.fdopen(fd, 'w') 59 f = os.fdopen(fd, 'w')
59 print(self.pid, file=f) 60 print(self.pid, file=f)
60 f.close() 61 f.close()
61 62
62 def _remove_lockfile(self): 63 def _remove_lockfile(self):
63 """Delete the lockfile. Complains (implicitly) if it doesn't exist.""" 64 """Delete the lockfile. Complains (implicitly) if it doesn't exist.
M-A Ruel 2014/04/17 17:17:19 Deletes :)
64 os.remove(self.lockfile) 65
66 See gclient_utils.py:rmtree docstring for more explanation on the
67 windows case.
68 """
69 if sys.platform == 'win32':
70 lockfile = os.path.normcase(self.lockfile)
71 for _ in xrange(3):
72 exitcode = subprocess.call(['cmd.exe', '/c',
73 'del', '/f', '/q', lockfile])
74 if exitcode == 0:
75 return
76 time.sleep(3)
77 raise LockError('Failed to remove lock: %s' % lockfile)
78 else:
79 os.remove(self.lockfile)
65 80
66 def lock(self): 81 def lock(self):
67 """Acquire the lock. 82 """Acquire the lock.
68 83
69 Note: This is a NON-BLOCKING FAIL-FAST operation. 84 Note: This is a NON-BLOCKING FAIL-FAST operation.
70 Do. Or do not. There is no try. 85 Do. Or do not. There is no try.
71 """ 86 """
72 try: 87 try:
73 self._make_lockfile() 88 self._make_lockfile()
74 except OSError as e: 89 except OSError as e:
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 return options, args 505 return options, args
491 506
492 507
493 def main(argv): 508 def main(argv):
494 dispatcher = subcommand.CommandDispatcher(__name__) 509 dispatcher = subcommand.CommandDispatcher(__name__)
495 return dispatcher.execute(OptionParser(), argv) 510 return dispatcher.execute(OptionParser(), argv)
496 511
497 512
498 if __name__ == '__main__': 513 if __name__ == '__main__':
499 sys.exit(main(sys.argv[1:])) 514 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698