~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/memory.py

  • Committer: Ian Clatworthy
  • Date: 2009-09-09 11:43:10 UTC
  • mto: (4634.37.2 prepare-2.0)
  • mto: This revision was merged to the branch mainline in revision 4689.
  • Revision ID: ian.clatworthy@canonical.com-20090909114310-glw7tv76i5gnx9pt
put rules back in Makefile supporting plain-style docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
"""Implementation of Transport that uses memory for its storage.
18
18
 
85
85
        if len(path) == 0 or path[-1] != '/':
86
86
            path += '/'
87
87
        url = self._scheme + path
88
 
        result = MemoryTransport(url)
 
88
        result = self.__class__(url)
89
89
        result._dirs = self._dirs
90
90
        result._files = self._files
91
91
        result._locks = self._locks
158
158
                'undefined', bytes, 0, 1,
159
159
                'put_file must be given a file of bytes, not unicode.')
160
160
        self._files[_abspath] = (bytes, mode)
 
161
        return len(bytes)
161
162
 
162
163
    def mkdir(self, relpath, mode=None):
163
164
        """See Transport.mkdir()."""
182
183
        for file in self._files:
183
184
            if file.startswith(self._cwd):
184
185
                yield urlutils.escape(file[len(self._cwd):])
185
 
    
 
186
 
186
187
    def list_dir(self, relpath):
187
188
        """See Transport.list_dir()."""
188
189
        _abspath = self._abspath(relpath)
221
222
                    del container[path]
222
223
        do_renames(self._files)
223
224
        do_renames(self._dirs)
224
 
    
 
225
 
225
226
    def rmdir(self, relpath):
226
227
        """See Transport.rmdir."""
227
228
        _abspath = self._abspath(relpath)
242
243
        """See Transport.stat()."""
243
244
        _abspath = self._abspath(relpath)
244
245
        if _abspath in self._files:
245
 
            return MemoryStat(len(self._files[_abspath][0]), False, 
 
246
            return MemoryStat(len(self._files[_abspath][0]), False,
246
247
                              self._files[_abspath][1])
247
248
        elif _abspath in self._dirs:
248
249
            return MemoryStat(0, True, self._dirs[_abspath])
260
261
    def _abspath(self, relpath):
261
262
        """Generate an internal absolute path."""
262
263
        relpath = urlutils.unescape(relpath)
263
 
        if relpath.find('..') != -1:
264
 
            raise AssertionError('relpath contains ..')
265
 
        if relpath == '':
266
 
            return '/'
267
 
        if relpath[0] == '/':
 
264
        if relpath[:1] == '/':
268
265
            return relpath
269
 
        if relpath == '.':
270
 
            if (self._cwd == '/'):
271
 
                return self._cwd
272
 
            return self._cwd[:-1]
273
 
        if relpath.endswith('/'):
274
 
            relpath = relpath[:-1]
275
 
        if relpath.startswith('./'):
276
 
            relpath = relpath[2:]
277
 
        return self._cwd + relpath
 
266
        cwd_parts = self._cwd.split('/')
 
267
        rel_parts = relpath.split('/')
 
268
        r = []
 
269
        for i in cwd_parts + rel_parts:
 
270
            if i == '..':
 
271
                if not r:
 
272
                    raise ValueError("illegal relpath %r under %r"
 
273
                        % (relpath, self._cwd))
 
274
                r = r[:-1]
 
275
            elif i == '.' or i == '':
 
276
                pass
 
277
            else:
 
278
                r.append(i)
 
279
        return '/' + '/'.join(r)
278
280
 
279
281
 
280
282
class _MemoryLock(object):
281
283
    """This makes a lock."""
282
284
 
283
285
    def __init__(self, path, transport):
284
 
        assert isinstance(transport, MemoryTransport)
285
286
        self.path = path
286
287
        self.transport = transport
287
288
        if self.path in self.transport._locks: