/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: Robert Collins
  • Date: 2006-01-18 03:09:39 UTC
  • mto: (1534.1.15 integration)
  • mto: This revision was merged to the branch mainline in revision 1550.
  • Revision ID: robertc@robertcollins.net-20060118030939-c5c7106140cf444f
Tweak storage towards mergability.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
18
 
from osutils import file_iterator
19
18
 
20
19
import bzrlib
 
20
from bzrlib.decorators import *
21
21
import bzrlib.errors as errors
22
22
from bzrlib.errors import LockError, ReadOnlyError
 
23
from bzrlib.osutils import file_iterator, safe_unicode
23
24
from bzrlib.trace import mutter
24
25
import bzrlib.transactions as transactions
25
26
 
 
27
 
26
28
class LockableFiles(object):
27
29
    """Object representing a set of files locked within the same scope
28
30
 
66
68
            file_or_path = '/'.join(file_or_path)
67
69
        if file_or_path == '':
68
70
            return u''
69
 
        return bzrlib.transport.urlescape(unicode(file_or_path))
 
71
        return bzrlib.transport.urlescape(safe_unicode(file_or_path))
70
72
 
71
73
    def _find_modes(self):
72
74
        """Determine the appropriate modes for files and directories."""
73
75
        try:
74
76
            try:
75
 
                st = self._transport.stat(u'.')
 
77
                st = self._transport.stat('.')
76
78
            except errors.NoSuchFile:
77
79
                # The .bzr/ directory doesn't exist, try to
78
80
                # inherit the permissions from the parent directory
79
81
                # but only try 1 level up
80
82
                temp_transport = self._transport.clone('..')
81
 
                st = temp_transport.stat(u'.')
 
83
                st = temp_transport.stat('.')
82
84
        except (errors.TransportNotPossible, errors.NoSuchFile):
83
85
            self._dir_mode = 0755
84
86
            self._file_mode = 0644
98
100
    def controlfile(self, file_or_path, mode='r'):
99
101
        """Open a control file for this branch.
100
102
 
101
 
        There are two classes of file in the control directory: text
 
103
        There are two classes of file in a lockable directory: text
102
104
        and binary.  binary files are untranslated byte streams.  Text
103
105
        control files are stored with Unix newlines and in UTF-8, even
104
106
        if the platform or locale defaults are different.
105
107
 
106
 
        Controlfiles should almost never be opened in write mode but
107
 
        rather should be atomically copied and replaced using atomicfile.
 
108
        Such files are not openable in write mode : they are managed via
 
109
        put and put_utf8 which atomically replace old versions using
 
110
        atomicfile.
108
111
        """
109
112
        import codecs
110
113
 
126
129
        else:
127
130
            raise BzrError("invalid controlfile mode %r" % mode)
128
131
 
 
132
    @needs_write_lock
129
133
    def put(self, path, file):
130
134
        """Write a file.
131
135
        
133
137
                     directory
134
138
        :param f: A file-like or string object whose contents should be copied.
135
139
        """
136
 
        if not self._lock_mode == 'w':
137
 
            raise ReadOnlyError()
138
140
        self._transport.put(self._escape(path), file, mode=self._file_mode)
139
141
 
 
142
    @needs_write_lock
140
143
    def put_utf8(self, path, file, mode=None):
141
144
        """Write a file, encoding as utf-8.
142
145
 
167
170
        # and potentially a remote locking protocol
168
171
        if self._lock_mode:
169
172
            if self._lock_mode != 'w':
170
 
                raise LockError("can't upgrade to a write lock from %r" %
 
173
                raise ReadOnlyError("can't upgrade to a write lock from %r" %
171
174
                                self._lock_mode)
172
175
            self._lock_count += 1
173
176
        else: