~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lockable_files.py

  • Committer: Jelmer Vernooij
  • Date: 2009-02-23 20:55:58 UTC
  • mfrom: (4034 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4053.
  • Revision ID: jelmer@samba.org-20090223205558-1cx2k4w1zgs8r5qa
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
    support this.)
58
58
 
59
59
    Instances of this class are often called control_files.
60
 
    
 
60
 
61
61
    This object builds on top of a Transport, which is used to actually write
62
62
    the files to disk, and an OSLock or LockDir, which controls how access to
63
63
    the files is controlled.  The particular type of locking used is set when
64
64
    the object is constructed.  In older formats OSLocks are used everywhere.
65
 
    in newer formats a LockDir is used for Repositories and Branches, and 
 
65
    in newer formats a LockDir is used for Repositories and Branches, and
66
66
    OSLocks for the local filesystem.
67
67
 
68
 
    This class is now deprecated; code should move to using the Transport 
69
 
    directly for file operations and using the lock or CountedLock for 
 
68
    This class is now deprecated; code should move to using the Transport
 
69
    directly for file operations and using the lock or CountedLock for
70
70
    locking.
71
71
    """
72
72
 
73
73
    # _lock_mode: None, or 'r' or 'w'
74
74
 
75
75
    # _lock_count: If _lock_mode is true, a positive count of the number of
76
 
    # times the lock has been taken *by this process*.   
77
 
    
 
76
    # times the lock has been taken *by this process*.
 
77
 
78
78
    def __init__(self, transport, lock_name, lock_class):
79
79
        """Create a LockableFiles group
80
80
 
81
 
        :param transport: Transport pointing to the directory holding the 
 
81
        :param transport: Transport pointing to the directory holding the
82
82
            control files and lock.
83
83
        :param lock_name: Name of the lock guarding these files.
84
84
        :param lock_class: Class of lock strategy to use: typically
132
132
 
133
133
    def _find_modes(self):
134
134
        """Determine the appropriate modes for files and directories.
135
 
        
 
135
 
136
136
        :deprecated: Replaced by BzrDir._find_modes.
137
137
        """
138
138
        try:
152
152
    @deprecated_method(deprecated_in((1, 6, 0)))
153
153
    def controlfilename(self, file_or_path):
154
154
        """Return location relative to branch.
155
 
        
 
155
 
156
156
        :deprecated: Use Transport methods instead.
157
157
        """
158
158
        return self._transport.abspath(self._escape(file_or_path))
161
161
    @deprecated_method(deprecated_in((1, 5, 0)))
162
162
    def get(self, relpath):
163
163
        """Get a file as a bytestream.
164
 
        
 
164
 
165
165
        :deprecated: Use a Transport instead of LockableFiles.
166
166
        """
167
167
        relpath = self._escape(relpath)
171
171
    @deprecated_method(deprecated_in((1, 5, 0)))
172
172
    def get_utf8(self, relpath):
173
173
        """Get a file as a unicode stream.
174
 
        
 
174
 
175
175
        :deprecated: Use a Transport instead of LockableFiles.
176
176
        """
177
177
        relpath = self._escape(relpath)
182
182
    @deprecated_method(deprecated_in((1, 6, 0)))
183
183
    def put(self, path, file):
184
184
        """Write a file.
185
 
        
 
185
 
186
186
        :param path: The path to put the file, relative to the .bzr control
187
187
                     directory
188
188
        :param file: A file-like or string object whose contents should be copied.
234
234
 
235
235
    def lock_write(self, token=None):
236
236
        """Lock this group of files for writing.
237
 
        
 
237
 
238
238
        :param token: if this is already locked, then lock_write will fail
239
239
            unless the token matches the existing lock.
240
240
        :returns: a token if this instance supports tokens, otherwise None.
277
277
            self._set_transaction(transactions.ReadOnlyTransaction())
278
278
            # 5K may be excessive, but hey, its a knob.
279
279
            self.get_transaction().set_cache_size(5000)
280
 
                        
 
280
 
281
281
    def unlock(self):
282
282
        if not self._lock_mode:
283
283
            raise errors.LockNotHeld(self)
297
297
 
298
298
    def get_physical_lock_status(self):
299
299
        """Return physical lock status.
300
 
        
 
300
 
301
301
        Returns true if a lock is held on the transport. If no lock is held, or
302
302
        the underlying locking mechanism does not support querying lock
303
303
        status, false is returned.
385
385
    def validate_token(self, token):
386
386
        if token is not None:
387
387
            raise errors.TokenLockingNotSupported(self)
388
 
        
 
388