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