Mercurial > hg > mercurial-crew-with-dirclash
comparison mercurial/lock.py @ 1753:e6e70450edb9
Raise a different exception when the lock is not available
When the filesystem is read-only or if we have some other
error, there is no need to wait.
Raise a lock.LockUnavailable exception.
author | Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
---|---|
date | Mon, 20 Feb 2006 01:09:40 +0100 |
parents | 59b3639df0a9 |
children | e431344e604c |
comparison
equal
deleted
inserted
replaced
1752:457cdec745f8 | 1753:e6e70450edb9 |
---|---|
3 # Copyright 2005 Matt Mackall <mpm@selenic.com> | 3 # Copyright 2005 Matt Mackall <mpm@selenic.com> |
4 # | 4 # |
5 # This software may be used and distributed according to the terms | 5 # This software may be used and distributed according to the terms |
6 # of the GNU General Public License, incorporated herein by reference. | 6 # of the GNU General Public License, incorporated herein by reference. |
7 | 7 |
8 import os, time | 8 import errno, os, time |
9 import util | 9 import util |
10 | 10 |
11 class LockHeld(Exception): | 11 class LockException(Exception): |
12 pass | |
13 class LockHeld(LockException): | |
14 pass | |
15 class LockUnavailable(LockException): | |
12 pass | 16 pass |
13 | 17 |
14 class lock(object): | 18 class lock(object): |
15 def __init__(self, file, wait=1, releasefn=None): | 19 def __init__(self, file, wait=1, releasefn=None): |
16 self.f = file | 20 self.f = file |
36 def trylock(self): | 40 def trylock(self): |
37 pid = os.getpid() | 41 pid = os.getpid() |
38 try: | 42 try: |
39 util.makelock(str(pid), self.f) | 43 util.makelock(str(pid), self.f) |
40 self.held = 1 | 44 self.held = 1 |
41 except (OSError, IOError): | 45 except (OSError, IOError), why: |
42 raise LockHeld(util.readlock(self.f)) | 46 if why.errno == errno.EEXIST: |
47 raise LockHeld(util.readlock(self.f)) | |
48 else: | |
49 raise LockUnavailable(why) | |
43 | 50 |
44 def release(self): | 51 def release(self): |
45 if self.held: | 52 if self.held: |
46 self.held = 0 | 53 self.held = 0 |
47 if self.releasefn: | 54 if self.releasefn: |