~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lockdir.py

  • Committer: Andrew Bennetts
  • Date: 2008-10-01 05:40:45 UTC
  • mfrom: (3753 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3756.
  • Revision ID: andrew.bennetts@canonical.com-20081001054045-z50qc0d3p9qsc5im
Merge from bzr.dev; resolve osutils.py conflict by reverting my sha import hackery.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2006, 2007, 2008 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
109
109
from bzrlib import (
110
110
    debug,
111
111
    errors,
 
112
    lock,
112
113
    )
113
114
import bzrlib.config
114
115
from bzrlib.errors import (
124
125
        ResourceBusy,
125
126
        TransportError,
126
127
        )
 
128
from bzrlib.hooks import Hooks
127
129
from bzrlib.trace import mutter, note
128
130
from bzrlib.osutils import rand_chars, get_host_name
129
131
import bzrlib.ui
152
154
_DEFAULT_POLL_SECONDS = 1.0
153
155
 
154
156
 
155
 
class LockDir(object):
156
 
    """Write-lock guarding access to data."""
 
157
class LockDir(lock.Lock):
 
158
    """Write-lock guarding access to data.
 
159
    """
157
160
 
158
161
    __INFO_NAME = '/info'
159
162
 
296
299
            self._locked_via_token = False
297
300
            self._lock_held = False
298
301
        else:
 
302
            old_nonce = self.nonce
299
303
            # rename before deleting, because we can't atomically remove the
300
304
            # whole tree
301
305
            start_time = time.time()
321
325
                self.transport.delete_tree(tmpname)
322
326
            self._trace("... unlock succeeded after %dms",
323
327
                    (time.time() - start_time) * 1000)
 
328
            result = lock.LockResult(self.transport.abspath(self.path),
 
329
                old_nonce)
 
330
            for hook in self.hooks['lock_released']:
 
331
                hook(result)
324
332
 
325
333
    def break_lock(self):
326
334
        """Break a lock not held by this instance of LockDir.
450
458
        """
451
459
        if self._fake_read_lock:
452
460
            raise LockContention(self)
453
 
        return self._attempt_lock()
 
461
        result = self._attempt_lock()
 
462
        hook_result = lock.LockResult(self.transport.abspath(self.path),
 
463
                self.nonce)
 
464
        for hook in self.hooks['lock_acquired']:
 
465
            hook(hook_result)
 
466
        return result
454
467
 
455
468
    def wait_lock(self, timeout=None, poll=None, max_attempts=None):
456
469
        """Wait a certain period for a lock.