~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-06-18 03:33:56 UTC
  • mfrom: (2527.1.1 breakin)
  • Revision ID: pqm@pqm.ubuntu.com-20070618033356-q24jtmuwbf03ojvd
Fix race in test_breakin_harder that can cause test suite hang.

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
73
        backing_bytes = self._backing_transport.get_bytes(relpath)
85
74
        return request.SuccessfulSmartServerResponse(('ok',), backing_bytes)
86
75
 
88
77
class AppendRequest(VfsRequest):
89
78
 
90
79
    def do(self, relpath, mode):
91
 
        relpath = self.translate_client_path(relpath)
92
80
        self._relpath = relpath
93
81
        self._mode = _deserialise_optional_mode(mode)
94
 
 
 
82
    
95
83
    def do_body(self, body_bytes):
96
84
        old_length = self._backing_transport.append_bytes(
97
85
            self._relpath, body_bytes, self._mode)
101
89
class DeleteRequest(VfsRequest):
102
90
 
103
91
    def do(self, relpath):
104
 
        relpath = self.translate_client_path(relpath)
105
92
        self._backing_transport.delete(relpath)
106
93
        return request.SuccessfulSmartServerResponse(('ok', ))
107
94
 
109
96
class IterFilesRecursiveRequest(VfsRequest):
110
97
 
111
98
    def do(self, relpath):
112
 
        if not relpath.endswith('/'):
113
 
            relpath += '/'
114
 
        relpath = self.translate_client_path(relpath)
115
99
        transport = self._backing_transport.clone(relpath)
116
100
        filenames = transport.iter_files_recursive()
117
101
        return request.SuccessfulSmartServerResponse(('names',) + tuple(filenames))
120
104
class ListDirRequest(VfsRequest):
121
105
 
122
106
    def do(self, relpath):
123
 
        if not relpath.endswith('/'):
124
 
            relpath += '/'
125
 
        relpath = self.translate_client_path(relpath)
126
107
        filenames = self._backing_transport.list_dir(relpath)
127
108
        return request.SuccessfulSmartServerResponse(('names',) + tuple(filenames))
128
109
 
130
111
class MkdirRequest(VfsRequest):
131
112
 
132
113
    def do(self, relpath, mode):
133
 
        relpath = self.translate_client_path(relpath)
134
114
        self._backing_transport.mkdir(relpath,
135
115
                                      _deserialise_optional_mode(mode))
136
116
        return request.SuccessfulSmartServerResponse(('ok',))
139
119
class MoveRequest(VfsRequest):
140
120
 
141
121
    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
122
        self._backing_transport.move(rel_from, rel_to)
145
123
        return request.SuccessfulSmartServerResponse(('ok',))
146
124
 
148
126
class PutRequest(VfsRequest):
149
127
 
150
128
    def do(self, relpath, mode):
151
 
        relpath = self.translate_client_path(relpath)
152
129
        self._relpath = relpath
153
130
        self._mode = _deserialise_optional_mode(mode)
154
131
 
160
137
class PutNonAtomicRequest(VfsRequest):
161
138
 
162
139
    def do(self, relpath, mode, create_parent, dir_mode):
163
 
        relpath = self.translate_client_path(relpath)
164
140
        self._relpath = relpath
165
141
        self._dir_mode = _deserialise_optional_mode(dir_mode)
166
142
        self._mode = _deserialise_optional_mode(mode)
179
155
class ReadvRequest(VfsRequest):
180
156
 
181
157
    def do(self, relpath):
182
 
        relpath = self.translate_client_path(relpath)
183
158
        self._relpath = relpath
184
159
 
185
160
    def do_body(self, body_bytes):
203
178
class RenameRequest(VfsRequest):
204
179
 
205
180
    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
181
        self._backing_transport.rename(rel_from, rel_to)
209
182
        return request.SuccessfulSmartServerResponse(('ok', ))
210
183
 
212
185
class RmdirRequest(VfsRequest):
213
186
 
214
187
    def do(self, relpath):
215
 
        relpath = self.translate_client_path(relpath)
216
188
        self._backing_transport.rmdir(relpath)
217
189
        return request.SuccessfulSmartServerResponse(('ok', ))
218
190
 
220
192
class StatRequest(VfsRequest):
221
193
 
222
194
    def do(self, relpath):
223
 
        if not relpath.endswith('/'):
224
 
            relpath += '/'
225
 
        relpath = self.translate_client_path(relpath)
226
195
        stat = self._backing_transport.stat(relpath)
227
196
        return request.SuccessfulSmartServerResponse(
228
197
            ('stat', str(stat.st_size), oct(stat.st_mode)))