~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/memory.py

  • Committer: Martin Pool
  • Date: 2006-02-21 06:59:51 UTC
  • mto: This revision was merged to the branch mainline in revision 1569.
  • Revision ID: mbp@sourcefrog.net-20060221065951-2f56678a03b687bc
MemoryTransport.rename() must raise exceptions on collision

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 6 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 Canonical Ltd
2
2
 
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
23
23
from copy import copy
24
24
import os
25
25
import errno
 
26
import re
26
27
from stat import *
27
28
from cStringIO import StringIO
28
29
 
53
54
            url = url + '/'
54
55
        super(MemoryTransport, self).__init__(url)
55
56
        self._cwd = url[url.find(':') + 1:]
 
57
        # dictionaries from absolute path to file mode
56
58
        self._dirs = {}
57
59
        self._files = {}
58
60
        self._locks = {}
156
158
                path[len(_abspath)] == '/'):
157
159
                result.append(path[len(_abspath) + 1:])
158
160
        return result
 
161
 
 
162
    def rename(self, rel_from, rel_to):
 
163
        """Rename a file or directory; fail if the destination exists"""
 
164
        abs_from = self._abspath(rel_from)
 
165
        abs_to = self._abspath(rel_to)
 
166
        def replace(x):
 
167
            if x == abs_from:
 
168
                x = abs_to
 
169
            elif x.startswith(abs_from + '/'):
 
170
                x = abs_to + x[len(abs_from):]
 
171
            return x
 
172
        def do_renames(container):
 
173
            for path in container:
 
174
                new_path = replace(path)
 
175
                if new_path != path:
 
176
                    if new_path in container:
 
177
                        raise FileExists(new_path)
 
178
                    container[new_path] = container[path]
 
179
                    del container[path]
 
180
        do_renames(self._files)
 
181
        do_renames(self._dirs)
159
182
    
160
183
    def rmdir(self, relpath):
161
184
        """See Transport.rmdir."""