~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/vfs.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-08-28 08:23:40 UTC
  • mfrom: (2757.1.1 ianc-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20070828082340-2byilw23kzl3cjx4
(Daniel Watkins) Better explanation of -r in uncommit help

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006, 2007 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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
31
30
from bzrlib.smart import request
32
31
 
33
32
 
52
51
 
53
52
class VfsRequest(request.SmartServerRequest):
54
53
    """Base class for VFS requests.
55
 
 
 
54
    
56
55
    VFS requests are disabled if vfs_enabled() returns False.
57
56
    """
58
57
 
60
59
        if not vfs_enabled():
61
60
            raise errors.DisabledMethod(self.__class__.__name__)
62
61
 
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
 
 
71
62
 
72
63
class HasRequest(VfsRequest):
73
64
 
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
67
        return request.SuccessfulSmartServerResponse((r,))
78
68
 
80
70
class GetRequest(VfsRequest):
81
71
 
82
72
    def do(self, relpath):
83
 
        relpath = self.translate_client_path(relpath)
84
 
        backing_bytes = self._backing_transport.get_bytes(relpath)
 
73
        try:
 
74
            backing_bytes = self._backing_transport.get_bytes(relpath)
 
75
        except errors.ReadError:
 
76
            # cannot read the file
 
77
            return request.FailedSmartServerResponse(('ReadError', ))
85
78
        return request.SuccessfulSmartServerResponse(('ok',), backing_bytes)
86
79
 
87
80
 
88
81
class AppendRequest(VfsRequest):
89
82
 
90
83
    def do(self, relpath, mode):
91
 
        relpath = self.translate_client_path(relpath)
92
84
        self._relpath = relpath
93
85
        self._mode = _deserialise_optional_mode(mode)
94
 
 
 
86
    
95
87
    def do_body(self, body_bytes):
96
88
        old_length = self._backing_transport.append_bytes(
97
89
            self._relpath, body_bytes, self._mode)
101
93
class DeleteRequest(VfsRequest):
102
94
 
103
95
    def do(self, relpath):
104
 
        relpath = self.translate_client_path(relpath)
105
96
        self._backing_transport.delete(relpath)
106
97
        return request.SuccessfulSmartServerResponse(('ok', ))
107
98
 
109
100
class IterFilesRecursiveRequest(VfsRequest):
110
101
 
111
102
    def do(self, relpath):
112
 
        if not relpath.endswith('/'):
113
 
            relpath += '/'
114
 
        relpath = self.translate_client_path(relpath)
115
103
        transport = self._backing_transport.clone(relpath)
116
104
        filenames = transport.iter_files_recursive()
117
105
        return request.SuccessfulSmartServerResponse(('names',) + tuple(filenames))
120
108
class ListDirRequest(VfsRequest):
121
109
 
122
110
    def do(self, relpath):
123
 
        if not relpath.endswith('/'):
124
 
            relpath += '/'
125
 
        relpath = self.translate_client_path(relpath)
126
111
        filenames = self._backing_transport.list_dir(relpath)
127
112
        return request.SuccessfulSmartServerResponse(('names',) + tuple(filenames))
128
113
 
130
115
class MkdirRequest(VfsRequest):
131
116
 
132
117
    def do(self, relpath, mode):
133
 
        relpath = self.translate_client_path(relpath)
134
118
        self._backing_transport.mkdir(relpath,
135
119
                                      _deserialise_optional_mode(mode))
136
120
        return request.SuccessfulSmartServerResponse(('ok',))
139
123
class MoveRequest(VfsRequest):
140
124
 
141
125
    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
126
        self._backing_transport.move(rel_from, rel_to)
145
127
        return request.SuccessfulSmartServerResponse(('ok',))
146
128
 
148
130
class PutRequest(VfsRequest):
149
131
 
150
132
    def do(self, relpath, mode):
151
 
        relpath = self.translate_client_path(relpath)
152
133
        self._relpath = relpath
153
134
        self._mode = _deserialise_optional_mode(mode)
154
135
 
160
141
class PutNonAtomicRequest(VfsRequest):
161
142
 
162
143
    def do(self, relpath, mode, create_parent, dir_mode):
163
 
        relpath = self.translate_client_path(relpath)
164
144
        self._relpath = relpath
165
145
        self._dir_mode = _deserialise_optional_mode(dir_mode)
166
146
        self._mode = _deserialise_optional_mode(mode)
179
159
class ReadvRequest(VfsRequest):
180
160
 
181
161
    def do(self, relpath):
182
 
        relpath = self.translate_client_path(relpath)
183
162
        self._relpath = relpath
184
163
 
185
164
    def do_body(self, body_bytes):
203
182
class RenameRequest(VfsRequest):
204
183
 
205
184
    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
185
        self._backing_transport.rename(rel_from, rel_to)
209
186
        return request.SuccessfulSmartServerResponse(('ok', ))
210
187
 
212
189
class RmdirRequest(VfsRequest):
213
190
 
214
191
    def do(self, relpath):
215
 
        relpath = self.translate_client_path(relpath)
216
192
        self._backing_transport.rmdir(relpath)
217
193
        return request.SuccessfulSmartServerResponse(('ok', ))
218
194
 
220
196
class StatRequest(VfsRequest):
221
197
 
222
198
    def do(self, relpath):
223
 
        if not relpath.endswith('/'):
224
 
            relpath += '/'
225
 
        relpath = self.translate_client_path(relpath)
226
199
        stat = self._backing_transport.stat(relpath)
227
200
        return request.SuccessfulSmartServerResponse(
228
201
            ('stat', str(stat.st_size), oct(stat.st_mode)))