59
60
if not vfs_enabled():
60
61
raise errors.DisabledMethod(self.__class__.__name__)
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))
63
72
class HasRequest(VfsRequest):
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
return request.SmartServerResponse((r,))
77
return request.SuccessfulSmartServerResponse((r,))
70
80
class GetRequest(VfsRequest):
72
82
def do(self, relpath):
83
relpath = self.translate_client_path(relpath)
73
84
backing_bytes = self._backing_transport.get_bytes(relpath)
74
return request.SmartServerResponse(('ok',), backing_bytes)
85
return request.SuccessfulSmartServerResponse(('ok',), backing_bytes)
77
88
class AppendRequest(VfsRequest):
79
90
def do(self, relpath, mode):
91
relpath = self.translate_client_path(relpath)
80
92
self._relpath = relpath
81
93
self._mode = _deserialise_optional_mode(mode)
83
95
def do_body(self, body_bytes):
84
96
old_length = self._backing_transport.append_bytes(
85
97
self._relpath, body_bytes, self._mode)
86
return request.SmartServerResponse(('appended', '%d' % old_length))
98
return request.SuccessfulSmartServerResponse(('appended', '%d' % old_length))
89
101
class DeleteRequest(VfsRequest):
91
103
def do(self, relpath):
104
relpath = self.translate_client_path(relpath)
92
105
self._backing_transport.delete(relpath)
93
return request.SmartServerResponse(('ok', ))
106
return request.SuccessfulSmartServerResponse(('ok', ))
96
109
class IterFilesRecursiveRequest(VfsRequest):
98
111
def do(self, relpath):
112
if not relpath.endswith('/'):
114
relpath = self.translate_client_path(relpath)
99
115
transport = self._backing_transport.clone(relpath)
100
116
filenames = transport.iter_files_recursive()
101
return request.SmartServerResponse(('names',) + tuple(filenames))
117
return request.SuccessfulSmartServerResponse(('names',) + tuple(filenames))
104
120
class ListDirRequest(VfsRequest):
106
122
def do(self, relpath):
123
if not relpath.endswith('/'):
125
relpath = self.translate_client_path(relpath)
107
126
filenames = self._backing_transport.list_dir(relpath)
108
return request.SmartServerResponse(('names',) + tuple(filenames))
127
return request.SuccessfulSmartServerResponse(('names',) + tuple(filenames))
111
130
class MkdirRequest(VfsRequest):
113
132
def do(self, relpath, mode):
133
relpath = self.translate_client_path(relpath)
114
134
self._backing_transport.mkdir(relpath,
115
135
_deserialise_optional_mode(mode))
116
return request.SmartServerResponse(('ok',))
136
return request.SuccessfulSmartServerResponse(('ok',))
119
139
class MoveRequest(VfsRequest):
121
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)
122
144
self._backing_transport.move(rel_from, rel_to)
123
return request.SmartServerResponse(('ok',))
145
return request.SuccessfulSmartServerResponse(('ok',))
126
148
class PutRequest(VfsRequest):
128
150
def do(self, relpath, mode):
151
relpath = self.translate_client_path(relpath)
129
152
self._relpath = relpath
130
153
self._mode = _deserialise_optional_mode(mode)
132
155
def do_body(self, body_bytes):
133
156
self._backing_transport.put_bytes(self._relpath, body_bytes, self._mode)
134
return request.SmartServerResponse(('ok',))
157
return request.SuccessfulSmartServerResponse(('ok',))
137
160
class PutNonAtomicRequest(VfsRequest):
139
162
def do(self, relpath, mode, create_parent, dir_mode):
163
relpath = self.translate_client_path(relpath)
140
164
self._relpath = relpath
141
165
self._dir_mode = _deserialise_optional_mode(dir_mode)
142
166
self._mode = _deserialise_optional_mode(mode)
178
203
class RenameRequest(VfsRequest):
180
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)
181
208
self._backing_transport.rename(rel_from, rel_to)
182
return request.SmartServerResponse(('ok', ))
209
return request.SuccessfulSmartServerResponse(('ok', ))
185
212
class RmdirRequest(VfsRequest):
187
214
def do(self, relpath):
215
relpath = self.translate_client_path(relpath)
188
216
self._backing_transport.rmdir(relpath)
189
return request.SmartServerResponse(('ok', ))
217
return request.SuccessfulSmartServerResponse(('ok', ))
192
220
class StatRequest(VfsRequest):
194
222
def do(self, relpath):
223
if not relpath.endswith('/'):
225
relpath = self.translate_client_path(relpath)
195
226
stat = self._backing_transport.stat(relpath)
196
return request.SmartServerResponse(
227
return request.SuccessfulSmartServerResponse(
197
228
('stat', str(stat.st_size), oct(stat.st_mode)))