~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lockable_files.py

MergeĀ upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2008 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 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
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
from cStringIO import StringIO
18
18
 
22
22
import warnings
23
23
 
24
24
from bzrlib import (
 
25
    counted_lock,
25
26
    errors,
26
27
    osutils,
27
28
    transactions,
85
86
    This class is now deprecated; code should move to using the Transport
86
87
    directly for file operations and using the lock or CountedLock for
87
88
    locking.
 
89
    
 
90
    :ivar _lock: The real underlying lock (e.g. a LockDir)
 
91
    :ivar _counted_lock: A lock decorated with a semaphore, so that it 
 
92
        can be re-entered.
88
93
    """
89
94
 
90
95
    # _lock_mode: None, or 'r' or 'w'
111
116
        self._lock = lock_class(transport, esc_name,
112
117
                                file_modebits=self._file_mode,
113
118
                                dir_modebits=self._dir_mode)
 
119
        self._counted_lock = counted_lock.CountedLock(self._lock)
114
120
 
115
121
    def create_lock(self):
116
122
        """Create the lock.
146
152
 
147
153
        :deprecated: Replaced by BzrDir._find_modes.
148
154
        """
 
155
        # XXX: The properties created by this can be removed or deprecated
 
156
        # once all the _get_text_store methods etc no longer use them.
 
157
        # -- mbp 20080512
149
158
        try:
150
159
            st = self._transport.stat('.')
151
160
        except errors.TransportNotPossible:
271
280
            #traceback.print_stack()
272
281
            self._lock_mode = 'w'
273
282
            self._lock_warner.lock_count = 1
274
 
            self._set_transaction(transactions.WriteTransaction())
 
283
            self._set_write_transaction()
275
284
            self._token_from_lock = token_from_lock
276
285
            return token_from_lock
277
286
 
285
294
            #traceback.print_stack()
286
295
            self._lock_mode = 'r'
287
296
            self._lock_warner.lock_count = 1
288
 
            self._set_transaction(transactions.ReadOnlyTransaction())
289
 
            # 5K may be excessive, but hey, its a knob.
290
 
            self.get_transaction().set_cache_size(5000)
 
297
            self._set_read_transaction()
 
298
 
 
299
    def _set_read_transaction(self):
 
300
        """Setup a read transaction."""
 
301
        self._set_transaction(transactions.ReadOnlyTransaction())
 
302
        # 5K may be excessive, but hey, its a knob.
 
303
        self.get_transaction().set_cache_size(5000)
 
304
 
 
305
    def _set_write_transaction(self):
 
306
        """Setup a write transaction."""
 
307
        self._set_transaction(transactions.WriteTransaction())
291
308
 
292
309
    def unlock(self):
293
310
        if not self._lock_mode: