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