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

  • Committer: John Arbash Meinel
  • Date: 2006-05-10 19:59:55 UTC
  • mfrom: (1704 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1752.
  • Revision ID: john@arbash-meinel.com-20060510195955-df080afb1daa3a96
[merge] bzr.dev 1704

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import bzrlib
22
22
from bzrlib.decorators import *
23
23
import bzrlib.errors as errors
24
 
from bzrlib.errors import LockError, ReadOnlyError
 
24
from bzrlib.errors import BzrError
25
25
from bzrlib.osutils import file_iterator, safe_unicode
26
26
from bzrlib.symbol_versioning import *
27
27
from bzrlib.trace import mutter, note
111
111
            warn("file group %r was not explicitly unlocked" % self)
112
112
            self._lock.unlock()
113
113
 
 
114
    def break_lock(self):
 
115
        """Break the lock of this lockable files group if it is held.
 
116
 
 
117
        The current ui factory will be used to prompt for user conformation.
 
118
        """
 
119
        self._lock.break_lock()
 
120
 
114
121
    def _escape(self, file_or_path):
115
122
        if not isinstance(file_or_path, basestring):
116
123
            file_or_path = '/'.join(file_or_path)
212
219
        # and potentially a remote locking protocol
213
220
        if self._lock_mode:
214
221
            if self._lock_mode != 'w' or not self.get_transaction().writeable():
215
 
                raise ReadOnlyError(self)
 
222
                raise errors.ReadOnlyError(self)
216
223
            self._lock_count += 1
217
224
        else:
218
225
            self._lock.lock_write()
248
255
            #note('unlocking %s', self)
249
256
            #traceback.print_stack()
250
257
            self._finish_transaction()
251
 
            self._lock.unlock()
252
 
            self._lock_mode = self._lock_count = None
 
258
            try:
 
259
                self._lock.unlock()
 
260
            finally:
 
261
                self._lock_mode = self._lock_count = None
253
262
 
254
263
    def is_locked(self):
255
264
        """Return true if this LockableFiles group is locked"""
256
265
        return self._lock_count >= 1
257
266
 
 
267
    def get_physical_lock_status(self):
 
268
        """Return physical lock status.
 
269
        
 
270
        Returns true if a lock is held on the transport. If no lock is held, or
 
271
        the underlying locking mechanism does not support querying lock
 
272
        status, false is returned.
 
273
        """
 
274
        try:
 
275
            return self._lock.peek() is not None
 
276
        except NotImplementedError:
 
277
            return False
 
278
 
258
279
    def get_transaction(self):
259
280
        """Return the current active transaction.
260
281
 
300
321
        self._file_modebits = file_modebits
301
322
        self._dir_modebits = dir_modebits
302
323
 
 
324
    def break_lock(self):
 
325
        raise NotImplementedError(self.break_lock)
 
326
 
303
327
    def lock_write(self):
304
328
        self._lock = self._transport.lock_write(self._escaped_name)
305
329
 
310
334
        self._lock.unlock()
311
335
        self._lock = None
312
336
 
 
337
    def peek(self):
 
338
        raise NotImplementedError()
 
339
 
313
340
    def create(self, mode=None):
314
341
        """Create lock mechanism"""
315
342
        # for old-style locks, create the file now