/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/lock.py

merge bzr.dev r4164

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2008, 2009 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
42
42
    osutils,
43
43
    trace,
44
44
    )
45
 
from bzrlib.hooks import Hooks
 
45
from bzrlib.hooks import HookPoint, Hooks
46
46
 
47
47
 
48
48
class LockHooks(Hooks):
49
49
 
50
50
    def __init__(self):
51
51
        Hooks.__init__(self)
52
 
 
53
 
        # added in 1.8; called with a LockResult when a physical lock is
54
 
        # acquired
55
 
        self['lock_acquired'] = []
56
 
 
57
 
        # added in 1.8; called with a LockResult when a physical lock is
58
 
        # acquired
59
 
        self['lock_released'] = []
 
52
        self.create_hook(HookPoint('lock_acquired',
 
53
            "Called with a bzrlib.lock.LockResult when a physical lock is "
 
54
            "acquired.", (1, 8), None))
 
55
        self.create_hook(HookPoint('lock_released',
 
56
            "Called with a bzrlib.lock.LockResult when a physical lock is "
 
57
            "released.", (1, 8), None))
60
58
 
61
59
 
62
60
class Lock(object):
185
183
                    self.unlock()
186
184
                # we should be more precise about whats a locking
187
185
                # error and whats a random-other error
188
 
                raise errors.LockContention(e)
 
186
                raise errors.LockContention(self.filename, e)
189
187
 
190
188
        def unlock(self):
191
189
            _fcntl_WriteLock._open_locks.remove(self.filename)
209
207
            except IOError, e:
210
208
                # we should be more precise about whats a locking
211
209
                # error and whats a random-other error
212
 
                raise errors.LockContention(e)
 
210
                raise errors.LockContention(self.filename, e)
213
211
 
214
212
        def unlock(self):
215
213
            count = _fcntl_ReadLock._open_locks[self.filename]
277
275
                fcntl.lockf(new_f, fcntl.LOCK_EX | fcntl.LOCK_NB)
278
276
            except IOError, e:
279
277
                # TODO: Raise a more specific error based on the type of error
280
 
                raise errors.LockContention(e)
 
278
                raise errors.LockContention(self.filename, e)
281
279
            _fcntl_WriteLock._open_locks.add(self.filename)
282
280
 
283
281
            self.f = new_f
322
320
                raise
323
321
            except Exception, e:
324
322
                self._clear_f()
325
 
                raise errors.LockContention(e)
 
323
                raise errors.LockContention(filename, e)
326
324
 
327
325
        def unlock(self):
328
326
            overlapped = pywintypes.OVERLAPPED()
330
328
                win32file.UnlockFileEx(self.hfile, 0, 0x7fff0000, overlapped)
331
329
                self._clear_f()
332
330
            except Exception, e:
333
 
                raise errors.LockContention(e)
 
331
                raise errors.LockContention(self.filename, e)
334
332
 
335
333
 
336
334
    class _w32c_ReadLock(_w32c_FileLock):
439
437
                last_err = _GetLastError()
440
438
                if last_err in (ERROR_LOCK_VIOLATION,):
441
439
                    raise errors.LockContention(filename)
442
 
                raise errors.LockContention('Unknown locking error: %s'
443
 
                                            % (last_err,))
 
440
                raise errors.LockContention(filename,
 
441
                    'Unknown locking error: %s' % (last_err,))
444
442
 
445
443
        def unlock(self):
446
444
            overlapped = OVERLAPPED()
454
452
            if result == 0:
455
453
                self._clear_f()
456
454
                last_err = _GetLastError()
457
 
                raise errors.LockContention('Unknown unlocking error: %s'
458
 
                                            % (last_err,))
 
455
                raise errors.LockContention(self.filename,
 
456
                    'Unknown unlocking error: %s' % (last_err,))
459
457
 
460
458
 
461
459
    class _ctypes_ReadLock(_ctypes_FileLock):