~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lockable_files.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-04-12 08:40:15 UTC
  • mfrom: (1651.1.7 bzr.mbp.escape-stores)
  • Revision ID: pqm@pqm.ubuntu.com-20060412084015-e6472a0717edbca6
(mbp) storage escaping, cleanups

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
from cStringIO import StringIO
18
18
import codecs
 
19
#import traceback
19
20
 
20
21
import bzrlib
21
22
from bzrlib.decorators import *
23
24
from bzrlib.errors import LockError, ReadOnlyError
24
25
from bzrlib.osutils import file_iterator, safe_unicode
25
26
from bzrlib.symbol_versioning import *
26
 
from bzrlib.trace import mutter
 
27
from bzrlib.trace import mutter, note
27
28
import bzrlib.transactions as transactions
28
29
 
29
30
# XXX: The tracking here of lock counts and whether the lock is held is
80
81
        self._lock_mode = None
81
82
        self._lock_count = 0
82
83
        esc_name = self._escape(lock_name)
83
 
        self._lock = lock_class(transport, esc_name, 
 
84
        self._lock = lock_class(transport, esc_name,
84
85
                                file_modebits=self._file_mode,
85
86
                                dir_modebits=self._dir_mode)
86
87
 
95
96
    def __repr__(self):
96
97
        return '%s(%r)' % (self.__class__.__name__,
97
98
                           self._transport)
 
99
    def __str__(self):
 
100
        return 'LockableFiles(%s, %s)' % (self.lock_name, self._transport.base)
 
101
 
 
102
    def __del__(self):
 
103
        if self.is_locked():
 
104
            # XXX: This should show something every time, and be suitable for
 
105
            # headless operation and embedding
 
106
            from warnings import warn
 
107
            warn("file group %r was not explicitly unlocked" % self)
 
108
            self._lock.unlock()
98
109
 
99
110
    def _escape(self, file_or_path):
100
111
        if not isinstance(file_or_path, basestring):
201
212
            self._lock_count += 1
202
213
        else:
203
214
            self._lock.lock_write()
 
215
            #note('write locking %s', self)
 
216
            #traceback.print_stack()
204
217
            self._lock_mode = 'w'
205
218
            self._lock_count = 1
206
219
            self._set_transaction(transactions.WriteTransaction())
213
226
            self._lock_count += 1
214
227
        else:
215
228
            self._lock.lock_read()
 
229
            #note('read locking %s', self)
 
230
            #traceback.print_stack()
216
231
            self._lock_mode = 'r'
217
232
            self._lock_count = 1
218
233
            self._set_transaction(transactions.ReadOnlyTransaction())
226
241
        if self._lock_count > 1:
227
242
            self._lock_count -= 1
228
243
        else:
 
244
            #note('unlocking %s', self)
 
245
            #traceback.print_stack()
229
246
            self._finish_transaction()
230
247
            self._lock.unlock()
231
248
            self._lock_mode = self._lock_count = None