~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/memory.py

  • Committer: Robert Collins
  • Date: 2007-07-04 08:08:13 UTC
  • mfrom: (2572 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2587.
  • Revision ID: robertc@robertcollins.net-20070704080813-wzebx0r88fvwj5rq
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
136
136
        """See Transport.put_file()."""
137
137
        _abspath = self._abspath(relpath)
138
138
        self._check_parent(_abspath)
139
 
        self._files[_abspath] = (f.read(), mode)
 
139
        bytes = f.read()
 
140
        if type(bytes) is not str:
 
141
            # Although not strictly correct, we raise UnicodeEncodeError to be
 
142
            # compatible with other transports.
 
143
            raise UnicodeEncodeError(
 
144
                'undefined', bytes, 0, 1,
 
145
                'put_file must be given a file of bytes, not unicode.')
 
146
        self._files[_abspath] = (bytes, mode)
140
147
 
141
148
    def mkdir(self, relpath, mode=None):
142
149
        """See Transport.mkdir()."""
161
168
        if _abspath != '/' and _abspath not in self._dirs:
162
169
            raise NoSuchFile(relpath)
163
170
        result = []
164
 
        for path in self._files:
165
 
            if (path.startswith(_abspath) and 
166
 
                path[len(_abspath) + 1:].find('/') == -1 and
167
 
                len(path) > len(_abspath)):
168
 
                result.append(path[len(_abspath) + 1:])
169
 
        for path in self._dirs:
170
 
            if (path.startswith(_abspath) and 
171
 
                path[len(_abspath) + 1:].find('/') == -1 and
172
 
                len(path) > len(_abspath) and
173
 
                path[len(_abspath)] == '/'):
174
 
                result.append(path[len(_abspath) + 1:])
 
171
 
 
172
        if not _abspath.endswith('/'):
 
173
            _abspath += '/'
 
174
 
 
175
        for path_group in self._files, self._dirs:
 
176
            for path in path_group:
 
177
                if path.startswith(_abspath):
 
178
                    trailing = path[len(_abspath):]
 
179
                    if trailing and '/' not in trailing:
 
180
                        result.append(trailing)
175
181
        return map(urlutils.escape, result)
176
182
 
177
183
    def rename(self, rel_from, rel_to):
201
207
        if _abspath in self._files:
202
208
            self._translate_error(IOError(errno.ENOTDIR, relpath), relpath)
203
209
        for path in self._files:
204
 
            if path.startswith(_abspath):
 
210
            if path.startswith(_abspath + '/'):
205
211
                self._translate_error(IOError(errno.ENOTEMPTY, relpath),
206
212
                                      relpath)
207
213
        for path in self._dirs:
208
 
            if path.startswith(_abspath) and path != _abspath:
 
214
            if path.startswith(_abspath + '/') and path != _abspath:
209
215
                self._translate_error(IOError(errno.ENOTEMPTY, relpath), relpath)
210
216
        if not _abspath in self._dirs:
211
217
            raise NoSuchFile(relpath)