~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: 2010-03-11 13:47:06 UTC
  • mfrom: (5051.3.16 use-branch-open)
  • Revision ID: pqm@pqm.ubuntu.com-20100311134706-kaerqhx3lf7xn6rh
(Jelmer) Pass colocated branch names further down the call stack.

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
 
72
81
 
73
82
    def do(self, relpath):
74
83
        relpath = self.translate_client_path(relpath)
75
 
        try:
76
 
            backing_bytes = self._backing_transport.get_bytes(relpath)
77
 
        except errors.ReadError:
78
 
            # cannot read the file
79
 
            return request.FailedSmartServerResponse(('ReadError', ))
80
 
        except errors.PermissionDenied:
81
 
            return request.FailedSmartServerResponse(('PermissionDenied',))
 
84
        backing_bytes = self._backing_transport.get_bytes(relpath)
82
85
        return request.SuccessfulSmartServerResponse(('ok',), backing_bytes)
83
86
 
84
87
 
88
91
        relpath = self.translate_client_path(relpath)
89
92
        self._relpath = relpath
90
93
        self._mode = _deserialise_optional_mode(mode)
91
 
    
 
94
 
92
95
    def do_body(self, body_bytes):
93
96
        old_length = self._backing_transport.append_bytes(
94
97
            self._relpath, body_bytes, self._mode)