47
47
Instances of this class are often called control_files.
49
This object builds on top of a Transport, which is used to actually
50
write the files to disk, and a Lock or LockDir, which controls how
51
access to the files is controlled. The particular type of locking used
52
is set when the object is constructed.
60
If _lock_mode is true, a positive count of the number of times the
61
lock has been taken *by this process*. Others may have compatible
65
Lock object from bzrlib.lock.
49
This object builds on top of a Transport, which is used to actually write
50
the files to disk, and an OSLock or LockDir, which controls how access to
51
the files is controlled. The particular type of locking used is set when
52
the object is constructed. In older formats OSLocks are used everywhere.
53
in newer formats a LockDir is used for Repositories and Branches, and
54
OSLocks for the local filesystem.
57
_lock_mode = None # None, or 'r' or 'w'
59
# If _lock_mode is true, a positive count of the number of times the
60
# lock has been taken *by this process*. Others may have compatible
71
64
# If set to False (by a plugin, etc) BzrBranch will not set the
72
65
# mode on created files or directories
73
66
_set_file_mode = True
74
67
_set_dir_mode = True
76
def __init__(self, transport, lock_name):
69
def __init__(self, transport, lock_name, lock_strategy_class=None):
70
"""Create a LockableFiles group
72
:param transport: Transport pointing to the directory holding the
73
control files and lock.
74
:param lock_name: Name of the lock guarding these files.
75
:param lock_strategy_class: Class of lock strategy to use.
77
77
object.__init__(self)
78
78
self._transport = transport
79
79
self.lock_name = lock_name
80
80
self._transaction = None
82
self._lock_strategy = OldTransportLockStrategy(transport,
83
self._escape(lock_name))
86
if self._lock_mode or self._lock:
87
# XXX: This should show something every time, and be suitable for
88
# headless operation and embedding
89
from warnings import warn
90
warn("file group %r was not explicitly unlocked" % self)
82
# TODO: remove this and make the parameter mandatory
83
if lock_strategy_class is None:
84
lock_strategy_class = OldTransportLockStrategy
85
esc_name = self._escape(lock_name)
86
self._lock_strategy = lock_strategy_class(transport, esc_name)
93
88
def _escape(self, file_or_path):
94
89
if not isinstance(file_or_path, basestring):
286
281
This is turned on by newer storage formats which want to use
287
282
LockDirs. This only guards writes, not reads.
284
# TODO: perhaps we should just refer to the LockDir directly rather than
285
# using this proxy; it would require adapting some of the method names
289
287
def __init__(self, transport, escaped_name):
290
288
from bzrlib.lockdir import LockDir
291
289
self._lockdir = LockDir(transport, escaped_name)