~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/vfs.py

  • Committer: John Arbash Meinel
  • Author(s): Mark Hammond
  • Date: 2008-09-09 17:02:21 UTC
  • mto: This revision was merged to the branch mainline in revision 3697.
  • Revision ID: john@arbash-meinel.com-20080909170221-svim3jw2mrz0amp3
An updated transparent icon for bzr.

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
 
24
24
protocol, as implemented in bzr 0.11 and later.
25
25
"""
26
26
 
27
 
from __future__ import absolute_import
28
 
 
29
27
import os
30
28
 
31
29
from bzrlib import errors
32
 
from bzrlib import urlutils
33
30
from bzrlib.smart import request
34
31
 
35
32
 
54
51
 
55
52
class VfsRequest(request.SmartServerRequest):
56
53
    """Base class for VFS requests.
57
 
 
 
54
    
58
55
    VFS requests are disabled if vfs_enabled() returns False.
59
56
    """
60
57
 
62
59
        if not vfs_enabled():
63
60
            raise errors.DisabledMethod(self.__class__.__name__)
64
61
 
65
 
    def translate_client_path(self, relpath):
66
 
        # VFS requests are made with escaped paths so the escaping done in
67
 
        # SmartServerRequest.translate_client_path leads to double escaping.
68
 
        # Remove it here -- the fact that the result is still escaped means
69
 
        # that the str() will not fail on valid input.
70
 
        x = request.SmartServerRequest.translate_client_path(self, relpath)
71
 
        return str(urlutils.unescape(x))
72
 
 
73
62
 
74
63
class HasRequest(VfsRequest):
75
64
 
83
72
 
84
73
    def do(self, relpath):
85
74
        relpath = self.translate_client_path(relpath)
86
 
        backing_bytes = self._backing_transport.get_bytes(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',))
87
82
        return request.SuccessfulSmartServerResponse(('ok',), backing_bytes)
88
83
 
89
84
 
93
88
        relpath = self.translate_client_path(relpath)
94
89
        self._relpath = relpath
95
90
        self._mode = _deserialise_optional_mode(mode)
96
 
 
 
91
    
97
92
    def do_body(self, body_bytes):
98
93
        old_length = self._backing_transport.append_bytes(
99
94
            self._relpath, body_bytes, self._mode)