/breezy/unstable

To get this branch, use:
bzr branch https://code.breezy-vcs.org/breezy/unstable

« back to all changes in this revision

Viewing changes to breezy/lock.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-24 01:39:33 UTC
  • mfrom: (3815.3776.6)
  • Revision ID: jelmer@jelmer.uk-20170524013933-ir4y4tqtrsiz2ka2
New upstream snapshot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
import sys
42
42
import warnings
43
43
 
44
 
from bzrlib import (
 
44
from . import (
45
45
    debug,
46
46
    errors,
47
47
    osutils,
48
48
    trace,
49
49
    )
50
 
from bzrlib.hooks import Hooks
51
 
from bzrlib.i18n import gettext
 
50
from .hooks import Hooks
 
51
from .i18n import gettext
52
52
 
53
53
class LockHooks(Hooks):
54
54
 
55
55
    def __init__(self):
56
 
        Hooks.__init__(self, "bzrlib.lock", "Lock.hooks")
 
56
        Hooks.__init__(self, "breezy.lock", "Lock.hooks")
57
57
        self.add_hook('lock_acquired',
58
 
            "Called with a bzrlib.lock.LockResult when a physical lock is "
 
58
            "Called with a breezy.lock.LockResult when a physical lock is "
59
59
            "acquired.", (1, 8))
60
60
        self.add_hook('lock_released',
61
 
            "Called with a bzrlib.lock.LockResult when a physical lock is "
 
61
            "Called with a breezy.lock.LockResult when a physical lock is "
62
62
            "released.", (1, 8))
63
63
        self.add_hook('lock_broken',
64
 
            "Called with a bzrlib.lock.LockResult when a physical lock is "
 
64
            "Called with a breezy.lock.LockResult when a physical lock is "
65
65
            "broken.", (1, 15))
66
66
 
67
67
 
155
155
        try:
156
156
            self.f = open(self.filename, filemode)
157
157
            return self.f
158
 
        except IOError, e:
 
158
        except IOError as e:
159
159
            if e.errno in (errno.EACCES, errno.EPERM):
160
160
                raise errors.LockFailed(self.filename, str(e))
161
161
            if e.errno != errno.ENOENT:
217
217
                # LOCK_NB will cause IOError to be raised if we can't grab a
218
218
                # lock right away.
219
219
                fcntl.lockf(self.f, fcntl.LOCK_EX | fcntl.LOCK_NB)
220
 
            except IOError, e:
 
220
            except IOError as e:
221
221
                if e.errno in (errno.EAGAIN, errno.EACCES):
222
222
                    # We couldn't grab the lock
223
223
                    self.unlock()
252
252
                # LOCK_NB will cause IOError to be raised if we can't grab a
253
253
                # lock right away.
254
254
                fcntl.lockf(self.f, fcntl.LOCK_SH | fcntl.LOCK_NB)
255
 
            except IOError, e:
 
255
            except IOError as e:
256
256
                # we should be more precise about whats a locking
257
257
                # error and whats a random-other error
258
258
                raise errors.LockContention(self.filename, e)
313
313
            # done by _fcntl_ReadLock
314
314
            try:
315
315
                new_f = open(self.filename, 'rb+')
316
 
            except IOError, e:
 
316
            except IOError as e:
317
317
                if e.errno in (errno.EACCES, errno.EPERM):
318
318
                    raise errors.LockFailed(self.filename, str(e))
319
319
                raise
321
321
                # LOCK_NB will cause IOError to be raised if we can't grab a
322
322
                # lock right away.
323
323
                fcntl.lockf(new_f, fcntl.LOCK_EX | fcntl.LOCK_NB)
324
 
            except IOError, e:
 
324
            except IOError as e:
325
325
                # TODO: Raise a more specific error based on the type of error
326
326
                raise errors.LockContention(self.filename, e)
327
327
            _fcntl_WriteLock._open_locks.add(self.filename)
360
360
                self._handle = win32file_CreateFile(filename, access, share,
361
361
                    None, win32file.OPEN_ALWAYS,
362
362
                    win32file.FILE_ATTRIBUTE_NORMAL, None)
363
 
            except pywintypes.error, e:
 
363
            except pywintypes.error as e:
364
364
                if e.args[0] == winerror.ERROR_ACCESS_DENIED:
365
365
                    raise errors.LockFailed(filename, e)
366
366
                if e.args[0] == winerror.ERROR_SHARING_VIOLATION: