/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/smart/vfs.py

  • Committer: Robert Collins
  • Date: 2010-05-04 06:22:51 UTC
  • mto: This revision was merged to the branch mainline in revision 5206.
  • Revision ID: robertc@robertcollins.net-20100504062251-1ocjhrl53mum9ehw
Minor local_abspath docstring improvement.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2006-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""VFS operations for the smart server.
18
18
 
27
27
import os
28
28
 
29
29
from bzrlib import errors
 
30
from bzrlib import urlutils
30
31
from bzrlib.smart import request
31
32
 
32
33
 
51
52
 
52
53
class VfsRequest(request.SmartServerRequest):
53
54
    """Base class for VFS requests.
54
 
    
 
55
 
55
56
    VFS requests are disabled if vfs_enabled() returns False.
56
57
    """
57
58
 
59
60
        if not vfs_enabled():
60
61
            raise errors.DisabledMethod(self.__class__.__name__)
61
62
 
 
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))
 
70
 
62
71
 
63
72
class HasRequest(VfsRequest):
64
73
 
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,))
68
78
 
69
79
 
70
80
class GetRequest(VfsRequest):
71
81
 
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)
75
86
 
76
87
 
77
88
class AppendRequest(VfsRequest):
78
89
 
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)
82
 
    
 
94
 
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))
87
99
 
88
100
 
89
101
class DeleteRequest(VfsRequest):
90
102
 
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', ))
94
107
 
95
108
 
96
109
class IterFilesRecursiveRequest(VfsRequest):
97
110
 
98
111
    def do(self, relpath):
 
112
        if not relpath.endswith('/'):
 
113
            relpath += '/'
 
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))
102
118
 
103
119
 
104
120
class ListDirRequest(VfsRequest):
105
121
 
106
122
    def do(self, relpath):
 
123
        if not relpath.endswith('/'):
 
124
            relpath += '/'
 
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))
109
128
 
110
129
 
111
130
class MkdirRequest(VfsRequest):
112
131
 
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',))
117
137
 
118
138
 
119
139
class MoveRequest(VfsRequest):
120
140
 
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',))
124
146
 
125
147
 
126
148
class PutRequest(VfsRequest):
127
149
 
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)
131
154
 
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',))
135
158
 
136
159
 
137
160
class PutNonAtomicRequest(VfsRequest):
138
161
 
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)
149
173
                mode=self._mode,
150
174
                create_parent_dir=self._create_parent,
151
175
                dir_mode=self._dir_mode)
152
 
        return request.SmartServerResponse(('ok',))
 
176
        return request.SuccessfulSmartServerResponse(('ok',))
153
177
 
154
178
 
155
179
class ReadvRequest(VfsRequest):
156
180
 
157
181
    def do(self, relpath):
 
182
        relpath = self.translate_client_path(relpath)
158
183
        self._relpath = relpath
159
184
 
160
185
    def do_body(self, body_bytes):
162
187
        offsets = self._deserialise_offsets(body_bytes)
163
188
        backing_bytes = ''.join(bytes for offset, bytes in
164
189
            self._backing_transport.readv(self._relpath, offsets))
165
 
        return request.SmartServerResponse(('readv',), backing_bytes)
 
190
        return request.SuccessfulSmartServerResponse(('readv',), backing_bytes)
166
191
 
167
192
    def _deserialise_offsets(self, text):
168
193
        # XXX: FIXME this should be on the protocol object.
178
203
class RenameRequest(VfsRequest):
179
204
 
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', ))
183
210
 
184
211
 
185
212
class RmdirRequest(VfsRequest):
186
213
 
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', ))
190
218
 
191
219
 
192
220
class StatRequest(VfsRequest):
193
221
 
194
222
    def do(self, relpath):
 
223
        if not relpath.endswith('/'):
 
224
            relpath += '/'
 
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)))
198
229