63
63
class HasRequest(VfsRequest):
65
65
def do(self, relpath):
66
relpath = self.translate_client_path(relpath)
67
66
r = self._backing_transport.has(relpath) and 'yes' or 'no'
68
return request.SuccessfulSmartServerResponse((r,))
67
return request.SmartServerResponse((r,))
71
70
class GetRequest(VfsRequest):
73
72
def do(self, relpath):
74
relpath = self.translate_client_path(relpath)
75
73
backing_bytes = self._backing_transport.get_bytes(relpath)
76
return request.SuccessfulSmartServerResponse(('ok',), backing_bytes)
74
return request.SmartServerResponse(('ok',), backing_bytes)
79
77
class AppendRequest(VfsRequest):
81
79
def do(self, relpath, mode):
82
relpath = self.translate_client_path(relpath)
83
80
self._relpath = relpath
84
81
self._mode = _deserialise_optional_mode(mode)
86
83
def do_body(self, body_bytes):
87
84
old_length = self._backing_transport.append_bytes(
88
85
self._relpath, body_bytes, self._mode)
89
return request.SuccessfulSmartServerResponse(('appended', '%d' % old_length))
86
return request.SmartServerResponse(('appended', '%d' % old_length))
92
89
class DeleteRequest(VfsRequest):
94
91
def do(self, relpath):
95
relpath = self.translate_client_path(relpath)
96
92
self._backing_transport.delete(relpath)
97
return request.SuccessfulSmartServerResponse(('ok', ))
93
return request.SmartServerResponse(('ok', ))
100
96
class IterFilesRecursiveRequest(VfsRequest):
102
98
def do(self, relpath):
103
if not relpath.endswith('/'):
105
relpath = self.translate_client_path(relpath)
106
99
transport = self._backing_transport.clone(relpath)
107
100
filenames = transport.iter_files_recursive()
108
return request.SuccessfulSmartServerResponse(('names',) + tuple(filenames))
101
return request.SmartServerResponse(('names',) + tuple(filenames))
111
104
class ListDirRequest(VfsRequest):
113
106
def do(self, relpath):
114
if not relpath.endswith('/'):
116
relpath = self.translate_client_path(relpath)
117
107
filenames = self._backing_transport.list_dir(relpath)
118
return request.SuccessfulSmartServerResponse(('names',) + tuple(filenames))
108
return request.SmartServerResponse(('names',) + tuple(filenames))
121
111
class MkdirRequest(VfsRequest):
123
113
def do(self, relpath, mode):
124
relpath = self.translate_client_path(relpath)
125
114
self._backing_transport.mkdir(relpath,
126
115
_deserialise_optional_mode(mode))
127
return request.SuccessfulSmartServerResponse(('ok',))
116
return request.SmartServerResponse(('ok',))
130
119
class MoveRequest(VfsRequest):
132
121
def do(self, rel_from, rel_to):
133
rel_from = self.translate_client_path(rel_from)
134
rel_to = self.translate_client_path(rel_to)
135
122
self._backing_transport.move(rel_from, rel_to)
136
return request.SuccessfulSmartServerResponse(('ok',))
123
return request.SmartServerResponse(('ok',))
139
126
class PutRequest(VfsRequest):
141
128
def do(self, relpath, mode):
142
relpath = self.translate_client_path(relpath)
143
129
self._relpath = relpath
144
130
self._mode = _deserialise_optional_mode(mode)
146
132
def do_body(self, body_bytes):
147
133
self._backing_transport.put_bytes(self._relpath, body_bytes, self._mode)
148
return request.SuccessfulSmartServerResponse(('ok',))
134
return request.SmartServerResponse(('ok',))
151
137
class PutNonAtomicRequest(VfsRequest):
153
139
def do(self, relpath, mode, create_parent, dir_mode):
154
relpath = self.translate_client_path(relpath)
155
140
self._relpath = relpath
156
141
self._dir_mode = _deserialise_optional_mode(dir_mode)
157
142
self._mode = _deserialise_optional_mode(mode)
194
178
class RenameRequest(VfsRequest):
196
180
def do(self, rel_from, rel_to):
197
rel_from = self.translate_client_path(rel_from)
198
rel_to = self.translate_client_path(rel_to)
199
181
self._backing_transport.rename(rel_from, rel_to)
200
return request.SuccessfulSmartServerResponse(('ok', ))
182
return request.SmartServerResponse(('ok', ))
203
185
class RmdirRequest(VfsRequest):
205
187
def do(self, relpath):
206
relpath = self.translate_client_path(relpath)
207
188
self._backing_transport.rmdir(relpath)
208
return request.SuccessfulSmartServerResponse(('ok', ))
189
return request.SmartServerResponse(('ok', ))
211
192
class StatRequest(VfsRequest):
213
194
def do(self, relpath):
214
if not relpath.endswith('/'):
216
relpath = self.translate_client_path(relpath)
217
195
stat = self._backing_transport.stat(relpath)
218
return request.SuccessfulSmartServerResponse(
196
return request.SmartServerResponse(
219
197
('stat', str(stat.st_size), oct(stat.st_mode)))