~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/vfs.py

  • Committer: Vincent Ladeuil
  • Date: 2010-02-09 17:19:50 UTC
  • mto: (5029.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 5030.
  • Revision ID: v.ladeuil+lp@free.fr-20100209171950-nxdtof8b29fene6e
Move FakeNFSServer to bzrlib.tests.test_server

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
"""VFS operations for the smart server.
18
18
 
27
27
import os
28
28
 
29
29
from bzrlib import errors
 
30
from bzrlib import urlutils
30
31
from bzrlib.smart import request
31
32
 
32
33
 
51
52
 
52
53
class VfsRequest(request.SmartServerRequest):
53
54
    """Base class for VFS requests.
54
 
    
 
55
 
55
56
    VFS requests are disabled if vfs_enabled() returns False.
56
57
    """
57
58
 
59
60
        if not vfs_enabled():
60
61
            raise errors.DisabledMethod(self.__class__.__name__)
61
62
 
 
63
    def translate_client_path(self, relpath):
 
64
        # VFS requests are made with escaped paths so the escaping done in
 
65
        # SmartServerRequest.translate_client_path leads to double escaping.
 
66
        # Remove it here -- the fact that the result is still escaped means
 
67
        # that the str() will not fail on valid input.
 
68
        x = request.SmartServerRequest.translate_client_path(self, relpath)
 
69
        return str(urlutils.unescape(x))
 
70
 
62
71
 
63
72
class HasRequest(VfsRequest):
64
73
 
65
74
    def do(self, relpath):
 
75
        relpath = self.translate_client_path(relpath)
66
76
        r = self._backing_transport.has(relpath) and 'yes' or 'no'
67
77
        return request.SuccessfulSmartServerResponse((r,))
68
78
 
70
80
class GetRequest(VfsRequest):
71
81
 
72
82
    def do(self, relpath):
73
 
        try:
74
 
            backing_bytes = self._backing_transport.get_bytes(relpath)
75
 
        except errors.ReadError:
76
 
            # cannot read the file
77
 
            return request.FailedSmartServerResponse(('ReadError', ))
 
83
        relpath = self.translate_client_path(relpath)
 
84
        backing_bytes = self._backing_transport.get_bytes(relpath)
78
85
        return request.SuccessfulSmartServerResponse(('ok',), backing_bytes)
79
86
 
80
87
 
81
88
class AppendRequest(VfsRequest):
82
89
 
83
90
    def do(self, relpath, mode):
 
91
        relpath = self.translate_client_path(relpath)
84
92
        self._relpath = relpath
85
93
        self._mode = _deserialise_optional_mode(mode)
86
 
    
 
94
 
87
95
    def do_body(self, body_bytes):
88
96
        old_length = self._backing_transport.append_bytes(
89
97
            self._relpath, body_bytes, self._mode)
93
101
class DeleteRequest(VfsRequest):
94
102
 
95
103
    def do(self, relpath):
 
104
        relpath = self.translate_client_path(relpath)
96
105
        self._backing_transport.delete(relpath)
97
106
        return request.SuccessfulSmartServerResponse(('ok', ))
98
107
 
100
109
class IterFilesRecursiveRequest(VfsRequest):
101
110
 
102
111
    def do(self, relpath):
 
112
        if not relpath.endswith('/'):
 
113
            relpath += '/'
 
114
        relpath = self.translate_client_path(relpath)
103
115
        transport = self._backing_transport.clone(relpath)
104
116
        filenames = transport.iter_files_recursive()
105
117
        return request.SuccessfulSmartServerResponse(('names',) + tuple(filenames))
108
120
class ListDirRequest(VfsRequest):
109
121
 
110
122
    def do(self, relpath):
 
123
        if not relpath.endswith('/'):
 
124
            relpath += '/'
 
125
        relpath = self.translate_client_path(relpath)
111
126
        filenames = self._backing_transport.list_dir(relpath)
112
127
        return request.SuccessfulSmartServerResponse(('names',) + tuple(filenames))
113
128
 
115
130
class MkdirRequest(VfsRequest):
116
131
 
117
132
    def do(self, relpath, mode):
 
133
        relpath = self.translate_client_path(relpath)
118
134
        self._backing_transport.mkdir(relpath,
119
135
                                      _deserialise_optional_mode(mode))
120
136
        return request.SuccessfulSmartServerResponse(('ok',))
123
139
class MoveRequest(VfsRequest):
124
140
 
125
141
    def do(self, rel_from, rel_to):
 
142
        rel_from = self.translate_client_path(rel_from)
 
143
        rel_to = self.translate_client_path(rel_to)
126
144
        self._backing_transport.move(rel_from, rel_to)
127
145
        return request.SuccessfulSmartServerResponse(('ok',))
128
146
 
130
148
class PutRequest(VfsRequest):
131
149
 
132
150
    def do(self, relpath, mode):
 
151
        relpath = self.translate_client_path(relpath)
133
152
        self._relpath = relpath
134
153
        self._mode = _deserialise_optional_mode(mode)
135
154
 
141
160
class PutNonAtomicRequest(VfsRequest):
142
161
 
143
162
    def do(self, relpath, mode, create_parent, dir_mode):
 
163
        relpath = self.translate_client_path(relpath)
144
164
        self._relpath = relpath
145
165
        self._dir_mode = _deserialise_optional_mode(dir_mode)
146
166
        self._mode = _deserialise_optional_mode(mode)
159
179
class ReadvRequest(VfsRequest):
160
180
 
161
181
    def do(self, relpath):
 
182
        relpath = self.translate_client_path(relpath)
162
183
        self._relpath = relpath
163
184
 
164
185
    def do_body(self, body_bytes):
182
203
class RenameRequest(VfsRequest):
183
204
 
184
205
    def do(self, rel_from, rel_to):
 
206
        rel_from = self.translate_client_path(rel_from)
 
207
        rel_to = self.translate_client_path(rel_to)
185
208
        self._backing_transport.rename(rel_from, rel_to)
186
209
        return request.SuccessfulSmartServerResponse(('ok', ))
187
210
 
189
212
class RmdirRequest(VfsRequest):
190
213
 
191
214
    def do(self, relpath):
 
215
        relpath = self.translate_client_path(relpath)
192
216
        self._backing_transport.rmdir(relpath)
193
217
        return request.SuccessfulSmartServerResponse(('ok', ))
194
218
 
196
220
class StatRequest(VfsRequest):
197
221
 
198
222
    def do(self, relpath):
 
223
        if not relpath.endswith('/'):
 
224
            relpath += '/'
 
225
        relpath = self.translate_client_path(relpath)
199
226
        stat = self._backing_transport.stat(relpath)
200
227
        return request.SuccessfulSmartServerResponse(
201
228
            ('stat', str(stat.st_size), oct(stat.st_mode)))