~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lockdir.py

  • Committer: Martin Pool
  • Date: 2007-10-03 08:06:44 UTC
  • mto: This revision was merged to the branch mainline in revision 2901.
  • Revision ID: mbp@sourcefrog.net-20071003080644-oivy0gkg98sex0ed
Avoid internal error tracebacks on failure to lock on readonly transport (#129701).

Add new LockFailed, which doesn't imply that we failed to get it because of
contention.  Raise this if we fail to create the pending or lock directories
because of Transport errors.

UnlockableTransport is not an internal error.

ReadOnlyLockError has a message which didn't match its name or usage; it's now
deprecated and callers are updated to use LockFailed which is more appropriate.

Add zero_ninetytwo deprecation symbol.

Unify assertMatchesRe with TestCase.assertContainsRe.

When the constructor is deprecated, just say that the class is deprecated, not
the __init__ method - this works better with applyDeprecated in tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
118
118
        LockBreakMismatch,
119
119
        LockBroken,
120
120
        LockContention,
 
121
        LockFailed,
121
122
        LockNotHeld,
122
123
        NoSuchFile,
123
124
        PathError,
124
125
        ResourceBusy,
 
126
        TransportError,
125
127
        UnlockableTransport,
126
128
        )
127
129
from bzrlib.trace import mutter, note
192
194
        This is typically only called when the object/directory containing the 
193
195
        directory is first created.  The lock is not held when it's created.
194
196
        """
195
 
        if self.transport.is_readonly():
196
 
            raise UnlockableTransport(self.transport)
197
197
        self._trace("create lock directory")
198
 
        self.transport.mkdir(self.path, mode=mode)
 
198
        try:
 
199
            self.transport.mkdir(self.path, mode=mode)
 
200
        except (TransportError, PathError), e:
 
201
            raise LockFailed(self, e)
 
202
 
199
203
 
200
204
    def _attempt_lock(self):
201
205
        """Make the pending directory and attempt to rename into place.
214
218
        """
215
219
        self._trace("lock_write...")
216
220
        start_time = time.time()
217
 
        tmpname = self._create_pending_dir()
 
221
        try:
 
222
            tmpname = self._create_pending_dir()
 
223
        except (errors.TransportError, PathError), e:
 
224
            self._trace("... failed to create pending dir, %s", e)
 
225
            raise LockFailed(self, e)
218
226
        try:
219
227
            self.transport.rename(tmpname, self._held_dir)
220
 
        except (PathError, DirectoryNotEmpty, FileExists, ResourceBusy), e:
 
228
        except (errors.TransportError, PathError, DirectoryNotEmpty,
 
229
                FileExists, ResourceBusy), e:
221
230
            self._trace("... contention, %s", e)
222
231
            self._remove_pending_dir(tmpname)
223
232
            raise LockContention(self)
446
455
        """
447
456
        if self._fake_read_lock:
448
457
            raise LockContention(self)
449
 
        if self.transport.is_readonly():
450
 
            raise UnlockableTransport(self.transport)
451
458
        return self._attempt_lock()
452
459
 
453
460
    def wait_lock(self, timeout=None, poll=None, max_attempts=None):