~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lockdir.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-12-03 00:17:53 UTC
  • mfrom: (4852.2.1 bzr-fix-publishing)
  • Revision ID: pqm@pqm.ubuntu.com-20091203001753-rrgwdoyxoojmn504
(David Roberts) Doc: delete unnecessary push of a checkout.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007, 2008 Canonical Ltd
 
1
# Copyright (C) 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
110
110
    debug,
111
111
    errors,
112
112
    lock,
 
113
    osutils,
113
114
    )
114
115
import bzrlib.config
 
116
from bzrlib.decorators import only_raises
115
117
from bzrlib.errors import (
116
118
        DirectoryNotEmpty,
117
119
        FileExists,
240
242
        # incorrect.  It's possible some other servers or filesystems will
241
243
        # have a similar bug allowing someone to think they got the lock
242
244
        # when it's already held.
243
 
        #
244
 
        # See <https://bugs.edge.launchpad.net/bzr/+bug/498378> for one case.
245
 
        #
246
 
        # Strictly the check is unnecessary and a waste of time for most
247
 
        # people, but probably worth trapping if something is wrong.
248
245
        info = self.peek()
249
246
        self._trace("after locking, info=%r", info)
250
 
        if info is None:
251
 
            raise LockFailed(self, "lock was renamed into place, but "
252
 
                "now is missing!")
253
247
        if info['nonce'] != self.nonce:
254
248
            self._trace("rename succeeded, "
255
249
                "but lock is still held by someone else")
294
288
                                            info_bytes)
295
289
        return tmpname
296
290
 
 
291
    @only_raises(LockNotHeld, LockBroken)
297
292
    def unlock(self):
298
293
        """Release a held lock
299
294
        """
422
417
 
423
418
        peek() reads the info file of the lock holder, if any.
424
419
        """
425
 
        return self._parse_info(self.transport.get(path))
 
420
        return self._parse_info(self.transport.get_bytes(path))
426
421
 
427
422
    def peek(self):
428
423
        """Check if the lock is held by anyone.
455
450
                   )
456
451
        return s.to_string()
457
452
 
458
 
    def _parse_info(self, info_file):
459
 
        return rio.read_stanza(info_file.readlines()).as_dict()
 
453
    def _parse_info(self, info_bytes):
 
454
        # TODO: Handle if info_bytes is empty
 
455
        return rio.read_stanza(osutils.split_lines(info_bytes)).as_dict()
460
456
 
461
457
    def attempt_lock(self):
462
458
        """Take the lock; fail if it's already held.