~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/vfs.py

  • Committer: Naoki INADA
  • Date: 2009-10-29 10:01:19 UTC
  • mto: (4634.97.3 2.0)
  • mto: This revision was merged to the branch mainline in revision 4798.
  • Revision ID: inada-n@klab.jp-20091029100119-uckv9t7ej2qrghw3
import doc-ja rev90

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
51
51
 
52
52
class VfsRequest(request.SmartServerRequest):
53
53
    """Base class for VFS requests.
54
 
    
 
54
 
55
55
    VFS requests are disabled if vfs_enabled() returns False.
56
56
    """
57
57
 
63
63
class HasRequest(VfsRequest):
64
64
 
65
65
    def do(self, relpath):
 
66
        relpath = self.translate_client_path(relpath)
66
67
        r = self._backing_transport.has(relpath) and 'yes' or 'no'
67
68
        return request.SuccessfulSmartServerResponse((r,))
68
69
 
70
71
class GetRequest(VfsRequest):
71
72
 
72
73
    def do(self, 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', ))
 
74
        relpath = self.translate_client_path(relpath)
 
75
        backing_bytes = self._backing_transport.get_bytes(relpath)
78
76
        return request.SuccessfulSmartServerResponse(('ok',), backing_bytes)
79
77
 
80
78
 
81
79
class AppendRequest(VfsRequest):
82
80
 
83
81
    def do(self, relpath, mode):
 
82
        relpath = self.translate_client_path(relpath)
84
83
        self._relpath = relpath
85
84
        self._mode = _deserialise_optional_mode(mode)
86
 
    
 
85
 
87
86
    def do_body(self, body_bytes):
88
87
        old_length = self._backing_transport.append_bytes(
89
88
            self._relpath, body_bytes, self._mode)
93
92
class DeleteRequest(VfsRequest):
94
93
 
95
94
    def do(self, relpath):
 
95
        relpath = self.translate_client_path(relpath)
96
96
        self._backing_transport.delete(relpath)
97
97
        return request.SuccessfulSmartServerResponse(('ok', ))
98
98
 
100
100
class IterFilesRecursiveRequest(VfsRequest):
101
101
 
102
102
    def do(self, relpath):
 
103
        if not relpath.endswith('/'):
 
104
            relpath += '/'
 
105
        relpath = self.translate_client_path(relpath)
103
106
        transport = self._backing_transport.clone(relpath)
104
107
        filenames = transport.iter_files_recursive()
105
108
        return request.SuccessfulSmartServerResponse(('names',) + tuple(filenames))
108
111
class ListDirRequest(VfsRequest):
109
112
 
110
113
    def do(self, relpath):
 
114
        if not relpath.endswith('/'):
 
115
            relpath += '/'
 
116
        relpath = self.translate_client_path(relpath)
111
117
        filenames = self._backing_transport.list_dir(relpath)
112
118
        return request.SuccessfulSmartServerResponse(('names',) + tuple(filenames))
113
119
 
115
121
class MkdirRequest(VfsRequest):
116
122
 
117
123
    def do(self, relpath, mode):
 
124
        relpath = self.translate_client_path(relpath)
118
125
        self._backing_transport.mkdir(relpath,
119
126
                                      _deserialise_optional_mode(mode))
120
127
        return request.SuccessfulSmartServerResponse(('ok',))
123
130
class MoveRequest(VfsRequest):
124
131
 
125
132
    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)
126
135
        self._backing_transport.move(rel_from, rel_to)
127
136
        return request.SuccessfulSmartServerResponse(('ok',))
128
137
 
130
139
class PutRequest(VfsRequest):
131
140
 
132
141
    def do(self, relpath, mode):
 
142
        relpath = self.translate_client_path(relpath)
133
143
        self._relpath = relpath
134
144
        self._mode = _deserialise_optional_mode(mode)
135
145
 
141
151
class PutNonAtomicRequest(VfsRequest):
142
152
 
143
153
    def do(self, relpath, mode, create_parent, dir_mode):
 
154
        relpath = self.translate_client_path(relpath)
144
155
        self._relpath = relpath
145
156
        self._dir_mode = _deserialise_optional_mode(dir_mode)
146
157
        self._mode = _deserialise_optional_mode(mode)
159
170
class ReadvRequest(VfsRequest):
160
171
 
161
172
    def do(self, relpath):
 
173
        relpath = self.translate_client_path(relpath)
162
174
        self._relpath = relpath
163
175
 
164
176
    def do_body(self, body_bytes):
182
194
class RenameRequest(VfsRequest):
183
195
 
184
196
    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)
185
199
        self._backing_transport.rename(rel_from, rel_to)
186
200
        return request.SuccessfulSmartServerResponse(('ok', ))
187
201
 
189
203
class RmdirRequest(VfsRequest):
190
204
 
191
205
    def do(self, relpath):
 
206
        relpath = self.translate_client_path(relpath)
192
207
        self._backing_transport.rmdir(relpath)
193
208
        return request.SuccessfulSmartServerResponse(('ok', ))
194
209
 
196
211
class StatRequest(VfsRequest):
197
212
 
198
213
    def do(self, relpath):
 
214
        if not relpath.endswith('/'):
 
215
            relpath += '/'
 
216
        relpath = self.translate_client_path(relpath)
199
217
        stat = self._backing_transport.stat(relpath)
200
218
        return request.SuccessfulSmartServerResponse(
201
219
            ('stat', str(stat.st_size), oct(stat.st_mode)))