59
62
if not vfs_enabled():
60
63
raise errors.DisabledMethod(self.__class__.__name__)
65
def translate_client_path(self, relpath):
66
# VFS requests are made with escaped paths so the escaping done in
67
# SmartServerRequest.translate_client_path leads to double escaping.
68
# Remove it here -- the fact that the result is still escaped means
69
# that the str() will not fail on valid input.
70
x = request.SmartServerRequest.translate_client_path(self, relpath)
71
return str(urlutils.unescape(x))
63
74
class HasRequest(VfsRequest):
65
76
def do(self, relpath):
77
relpath = self.translate_client_path(relpath)
66
78
r = self._backing_transport.has(relpath) and 'yes' or 'no'
67
return request.SmartServerResponse((r,))
79
return request.SuccessfulSmartServerResponse((r,))
70
82
class GetRequest(VfsRequest):
72
84
def do(self, relpath):
85
relpath = self.translate_client_path(relpath)
73
86
backing_bytes = self._backing_transport.get_bytes(relpath)
74
return request.SmartServerResponse(('ok',), backing_bytes)
87
return request.SuccessfulSmartServerResponse(('ok',), backing_bytes)
77
90
class AppendRequest(VfsRequest):
79
92
def do(self, relpath, mode):
93
relpath = self.translate_client_path(relpath)
80
94
self._relpath = relpath
81
95
self._mode = _deserialise_optional_mode(mode)
83
97
def do_body(self, body_bytes):
84
98
old_length = self._backing_transport.append_bytes(
85
99
self._relpath, body_bytes, self._mode)
86
return request.SmartServerResponse(('appended', '%d' % old_length))
100
return request.SuccessfulSmartServerResponse(('appended', '%d' % old_length))
89
103
class DeleteRequest(VfsRequest):
91
105
def do(self, relpath):
106
relpath = self.translate_client_path(relpath)
92
107
self._backing_transport.delete(relpath)
93
return request.SmartServerResponse(('ok', ))
108
return request.SuccessfulSmartServerResponse(('ok', ))
96
111
class IterFilesRecursiveRequest(VfsRequest):
98
113
def do(self, relpath):
114
if not relpath.endswith('/'):
116
relpath = self.translate_client_path(relpath)
99
117
transport = self._backing_transport.clone(relpath)
100
118
filenames = transport.iter_files_recursive()
101
return request.SmartServerResponse(('names',) + tuple(filenames))
119
return request.SuccessfulSmartServerResponse(('names',) + tuple(filenames))
104
122
class ListDirRequest(VfsRequest):
106
124
def do(self, relpath):
125
if not relpath.endswith('/'):
127
relpath = self.translate_client_path(relpath)
107
128
filenames = self._backing_transport.list_dir(relpath)
108
return request.SmartServerResponse(('names',) + tuple(filenames))
129
return request.SuccessfulSmartServerResponse(('names',) + tuple(filenames))
111
132
class MkdirRequest(VfsRequest):
113
134
def do(self, relpath, mode):
135
relpath = self.translate_client_path(relpath)
114
136
self._backing_transport.mkdir(relpath,
115
137
_deserialise_optional_mode(mode))
116
return request.SmartServerResponse(('ok',))
138
return request.SuccessfulSmartServerResponse(('ok',))
119
141
class MoveRequest(VfsRequest):
121
143
def do(self, rel_from, rel_to):
144
rel_from = self.translate_client_path(rel_from)
145
rel_to = self.translate_client_path(rel_to)
122
146
self._backing_transport.move(rel_from, rel_to)
123
return request.SmartServerResponse(('ok',))
147
return request.SuccessfulSmartServerResponse(('ok',))
126
150
class PutRequest(VfsRequest):
128
152
def do(self, relpath, mode):
153
relpath = self.translate_client_path(relpath)
129
154
self._relpath = relpath
130
155
self._mode = _deserialise_optional_mode(mode)
132
157
def do_body(self, body_bytes):
133
158
self._backing_transport.put_bytes(self._relpath, body_bytes, self._mode)
134
return request.SmartServerResponse(('ok',))
159
return request.SuccessfulSmartServerResponse(('ok',))
137
162
class PutNonAtomicRequest(VfsRequest):
139
164
def do(self, relpath, mode, create_parent, dir_mode):
165
relpath = self.translate_client_path(relpath)
140
166
self._relpath = relpath
141
167
self._dir_mode = _deserialise_optional_mode(dir_mode)
142
168
self._mode = _deserialise_optional_mode(mode)
178
205
class RenameRequest(VfsRequest):
180
207
def do(self, rel_from, rel_to):
208
rel_from = self.translate_client_path(rel_from)
209
rel_to = self.translate_client_path(rel_to)
181
210
self._backing_transport.rename(rel_from, rel_to)
182
return request.SmartServerResponse(('ok', ))
211
return request.SuccessfulSmartServerResponse(('ok', ))
185
214
class RmdirRequest(VfsRequest):
187
216
def do(self, relpath):
217
relpath = self.translate_client_path(relpath)
188
218
self._backing_transport.rmdir(relpath)
189
return request.SmartServerResponse(('ok', ))
219
return request.SuccessfulSmartServerResponse(('ok', ))
192
222
class StatRequest(VfsRequest):
194
224
def do(self, relpath):
225
if not relpath.endswith('/'):
227
relpath = self.translate_client_path(relpath)
195
228
stat = self._backing_transport.stat(relpath)
196
return request.SmartServerResponse(
229
return request.SuccessfulSmartServerResponse(
197
230
('stat', str(stat.st_size), oct(stat.st_mode)))