##// END OF EJS Templates
lock: while releasing, unlink lockfile even if the release function throws...
Siddharth Agarwal -
r23032:f484be02 default
parent child Browse files
Show More
@@ -139,12 +139,14 b' class lock(object):'
139 if os.getpid() != self.pid:
139 if os.getpid() != self.pid:
140 # we forked, and are not the parent
140 # we forked, and are not the parent
141 return
141 return
142 if self.releasefn:
143 self.releasefn()
144 try:
142 try:
145 self.vfs.unlink(self.f)
143 if self.releasefn:
146 except OSError:
144 self.releasefn()
147 pass
145 finally:
146 try:
147 self.vfs.unlink(self.f)
148 except OSError:
149 pass
148 for callback in self.postrelease:
150 for callback in self.postrelease:
149 callback()
151 callback()
150
152
@@ -11,6 +11,42 b' Prepare'
11 updating to branch default
11 updating to branch default
12 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
12 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
13
13
14 Test that raising an exception in the release function doesn't cause the lock to choke
15
16 $ cat > testlock.py << EOF
17 > from mercurial import cmdutil, error, util
18 >
19 > cmdtable = {}
20 > command = cmdutil.command(cmdtable)
21 >
22 > def acquiretestlock(repo, releaseexc):
23 > def unlock():
24 > if releaseexc:
25 > raise util.Abort('expected release exception')
26 > l = repo._lock(repo.vfs, 'testlock', False, unlock, None, 'test lock')
27 > return l
28 >
29 > @command('testlockexc')
30 > def testlockexc(ui, repo):
31 > testlock = acquiretestlock(repo, True)
32 > try:
33 > testlock.release()
34 > finally:
35 > try:
36 > testlock = acquiretestlock(repo, False)
37 > except error.LockHeld:
38 > raise util.Abort('lockfile on disk even after releasing!')
39 > testlock.release()
40 > EOF
41 $ cat >> $HGRCPATH << EOF
42 > [extensions]
43 > testlock=$TESTTMP/testlock.py
44 > EOF
45
46 $ hg -R b testlockexc
47 abort: expected release exception
48 [255]
49
14 One process waiting for another
50 One process waiting for another
15
51
16 $ cat > hooks.py << EOF
52 $ cat > hooks.py << EOF
General Comments 0
You need to be logged in to leave comments. Login now