~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/sftp.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-06-30 15:05:50 UTC
  • mfrom: (1711.4.38 win32-accepted)
  • Revision ID: pqm@pqm.ubuntu.com-20060630150550-7c698ee2cf8678d8
(jam) fix sftp tests for win32, fix drive letter inconsistency

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
                           PathError,
42
42
                           ParamikoNotPresent,
43
43
                           )
44
 
from bzrlib.osutils import pathjoin, fancy_rename
 
44
from bzrlib.osutils import pathjoin, fancy_rename, getcwd
45
45
from bzrlib.trace import mutter, warning, error
46
46
from bzrlib.transport import (
47
47
    register_urlparse_netloc_protocol,
102
102
                }
103
103
 
104
104
 
105
 
# don't use prefetch unless paramiko version >= 1.5.2 (there were bugs earlier)
106
 
_default_do_prefetch = False
107
 
if getattr(paramiko, '__version_info__', (0, 0, 0)) >= (1, 5, 5):
108
 
    _default_do_prefetch = True
 
105
_paramiko_version = getattr(paramiko, '__version_info__', (0, 0, 0))
 
106
# don't use prefetch unless paramiko version >= 1.5.5 (there were bugs earlier)
 
107
_default_do_prefetch = (_paramiko_version >= (1, 5, 5))
 
108
 
 
109
# Paramiko 1.5 tries to open a socket.AF_UNIX in order to connect
 
110
# to ssh-agent. That attribute doesn't exist on win32 (it does in cygwin)
 
111
# so we get an AttributeError exception. So we will not try to
 
112
# connect to an agent if we are on win32 and using Paramiko older than 1.6
 
113
_use_ssh_agent = (sys.platform != 'win32' or _paramiko_version >= (1, 6, 0)) 
109
114
 
110
115
 
111
116
_ssh_vendor = None
376
381
                basepath.append(p)
377
382
 
378
383
        path = '/'.join(basepath)
 
384
        # mutter('relpath => remotepath %s => %s', relpath, path)
379
385
        return path
380
386
 
381
387
    def relpath(self, abspath):
499
505
 
500
506
    def mkdir(self, relpath, mode=None):
501
507
        """Create a directory at the given path."""
 
508
        path = self._remote_path(relpath)
502
509
        try:
503
 
            path = self._remote_path(relpath)
504
510
            # In the paramiko documentation, it says that passing a mode flag 
505
511
            # will filtered against the server umask.
506
512
            # StubSFTPServer does not do this, which would be nice, because it is
774
780
        # Also, it would mess up the self.relpath() functionality
775
781
        username = self._username or getpass.getuser()
776
782
 
777
 
        # Paramiko tries to open a socket.AF_UNIX in order to connect
778
 
        # to ssh-agent. That attribute doesn't exist on win32 (it does in cygwin)
779
 
        # so we get an AttributeError exception. For now, just don't try to
780
 
        # connect to an agent if we are on win32
781
 
        if sys.platform != 'win32':
 
783
        if _use_ssh_agent:
782
784
            agent = paramiko.Agent()
783
785
            for key in agent.get_keys():
784
786
                mutter('Trying SSH agent key %s' % paramiko.util.hexify(key.get_fingerprint()))
851
853
        :param mode: The mode permissions bits for the new file
852
854
        """
853
855
        path = self._sftp._adjust_cwd(abspath)
 
856
        # mutter('sftp abspath %s => %s', abspath, path)
854
857
        attr = SFTPAttributes()
855
858
        if mode is not None:
856
859
            attr.st_mode = mode
960
963
 
961
964
    def _run_server(self, s):
962
965
        ssh_server = paramiko.Transport(s)
963
 
        key_file = os.path.join(self._homedir, 'test_rsa.key')
 
966
        key_file = pathjoin(self._homedir, 'test_rsa.key')
964
967
        f = open(key_file, 'w')
965
968
        f.write(STUB_SERVER_KEY)
966
969
        f.close()
978
981
        global _ssh_vendor
979
982
        self._original_vendor = _ssh_vendor
980
983
        _ssh_vendor = self._vendor
981
 
        self._homedir = os.getcwd()
 
984
        if sys.platform == 'win32':
 
985
            # Win32 needs to use the UNICODE api
 
986
            self._homedir = getcwd()
 
987
        else:
 
988
            # But Linux SFTP servers should just deal in bytestreams
 
989
            self._homedir = os.getcwd()
982
990
        if self._server_homedir is None:
983
991
            self._server_homedir = self._homedir
984
992
        self._root = '/'
985
 
        # FIXME WINDOWS: _root should be _server_homedir[0]:/
 
993
        if sys.platform == 'win32':
 
994
            self._root = ''
986
995
        self._listener = SocketListener(self._run_server)
987
996
        self._listener.setDaemon(True)
988
997
        self._listener.start()
1050
1059
 
1051
1060
    def get_url(self):
1052
1061
        """See bzrlib.transport.Server.get_url."""
1053
 
        return self._get_sftp_url(urlutils.escape(self._homedir[1:]))
 
1062
        if sys.platform == 'win32':
 
1063
            return self._get_sftp_url(urlutils.escape(self._homedir))
 
1064
        else:
 
1065
            return self._get_sftp_url(urlutils.escape(self._homedir[1:]))
1054
1066
 
1055
1067
 
1056
1068
class SFTPHomeDirServer(SFTPServerWithoutSSH):