/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/lockdir.py

  • Committer: Aaron Bentley
  • Date: 2008-10-12 16:11:17 UTC
  • mfrom: (3774 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3775.
  • Revision ID: aaron@aaronbentley.com-20081012161117-et0n1u2221zzwc8z
Merge with trunk

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
105
105
 
106
106
import os
107
107
import time
108
 
from cStringIO import StringIO
109
108
 
110
109
from bzrlib import (
111
110
    debug,
112
111
    errors,
 
112
    lock,
113
113
    )
114
114
import bzrlib.config
115
115
from bzrlib.errors import (
124
124
        PathError,
125
125
        ResourceBusy,
126
126
        TransportError,
127
 
        UnlockableTransport,
128
127
        )
 
128
from bzrlib.hooks import Hooks
129
129
from bzrlib.trace import mutter, note
130
 
from bzrlib.transport import Transport
131
 
from bzrlib.osutils import rand_chars, format_delta, get_host_name
132
 
from bzrlib.rio import read_stanza, Stanza
 
130
from bzrlib.osutils import format_delta, rand_chars, get_host_name
133
131
import bzrlib.ui
134
132
 
 
133
from bzrlib.lazy_import import lazy_import
 
134
lazy_import(globals(), """
 
135
from bzrlib import rio
 
136
""")
135
137
 
136
138
# XXX: At the moment there is no consideration of thread safety on LockDir
137
139
# objects.  This should perhaps be updated - e.g. if two threads try to take a
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.
428
436
            user = config.user_email()
429
437
        except errors.NoEmailInUsername:
430
438
            user = config.username()
431
 
        s = Stanza(hostname=get_host_name(),
 
439
        s = rio.Stanza(hostname=get_host_name(),
432
440
                   pid=str(os.getpid()),
433
441
                   start_time=str(int(time.time())),
434
442
                   nonce=self.nonce,
437
445
        return s.to_string()
438
446
 
439
447
    def _parse_info(self, info_file):
440
 
        return read_stanza(info_file.readlines()).as_dict()
 
448
        return rio.read_stanza(info_file.readlines()).as_dict()
441
449
 
442
450
    def attempt_lock(self):
443
451
        """Take the lock; fail if it's already held.
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.