~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/memory.py

Move put mode tests into test_transport_implementation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 
28
28
class MemoryStat(object):
29
29
 
30
 
    def __init__(self, size, is_dir):
 
30
    def __init__(self, size, is_dir, perms):
31
31
        self.st_size = size
 
32
        if perms is None:
 
33
            perms = 0644
32
34
        if not is_dir:
33
 
            self.st_mode = S_IFREG
 
35
            self.st_mode = S_IFREG | perms
34
36
        else:
35
 
            self.st_mode = S_IFDIR
 
37
            self.st_mode = S_IFDIR | perms
36
38
 
37
39
 
38
40
class MemoryTransport(Transport):
78
80
        """See Transport.append()."""
79
81
        _abspath = self._abspath(relpath)
80
82
        self._check_parent(_abspath)
81
 
        self._files[_abspath] = self._files.get(_abspath, "") + f.read()
 
83
        orig_content, orig_mode = self._files.get(_abspath, ("", None))
 
84
        self._files[_abspath] = (orig_content + f.read(), orig_mode)
82
85
 
83
86
    def _check_parent(self, _abspath):
84
87
        dir = os.path.dirname(_abspath)
103
106
        _abspath = self._abspath(relpath)
104
107
        if not _abspath in self._files:
105
108
            raise NoSuchFile(relpath)
106
 
        return StringIO(self._files[_abspath])
 
109
        return StringIO(self._files[_abspath][0])
107
110
 
108
111
    def put(self, relpath, f, mode=None):
109
112
        """See Transport.put()."""
110
113
        _abspath = self._abspath(relpath)
111
114
        self._check_parent(_abspath)
112
 
        self._files[_abspath] = f.read()
 
115
        self._files[_abspath] = (f.read(), mode)
113
116
 
114
117
    def mkdir(self, relpath, mode=None):
115
118
        """See Transport.mkdir()."""
150
153
        """See Transport.stat()."""
151
154
        _abspath = self._abspath(relpath)
152
155
        if _abspath in self._files:
153
 
            return MemoryStat(len(self._files[_abspath]), False)
 
156
            return MemoryStat(len(self._files[_abspath][0]), False, 
 
157
                              self._files[_abspath][1])
154
158
        elif _abspath in self._dirs or _abspath == '':
155
 
            return MemoryStat(0, True)
 
159
            return MemoryStat(0, True, None)
156
160
        else:
157
161
            raise NoSuchFile(relpath)
158
162