~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/sftp.py

  • Committer: Jelmer Vernooij
  • Date: 2011-12-16 19:18:39 UTC
  • mto: This revision was merged to the branch mainline in revision 6391.
  • Revision ID: jelmer@samba.org-20111216191839-eg681lxqibi1qxu1
Fix remaining tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
import stat
32
32
import sys
33
33
import time
34
 
import urllib
35
 
import urlparse
36
34
import warnings
37
35
 
38
36
from bzrlib import (
42
40
    urlutils,
43
41
    )
44
42
from bzrlib.errors import (FileExists,
45
 
                           NoSuchFile, PathNotChild,
 
43
                           NoSuchFile,
46
44
                           TransportError,
47
45
                           LockError,
48
46
                           PathError,
49
47
                           ParamikoNotPresent,
50
48
                           )
51
 
from bzrlib.osutils import pathjoin, fancy_rename, getcwd
52
 
from bzrlib.symbol_versioning import (
53
 
        deprecated_function,
54
 
        )
 
49
from bzrlib.osutils import fancy_rename
55
50
from bzrlib.trace import mutter, warning
56
51
from bzrlib.transport import (
57
52
    FileFileStream,
58
53
    _file_streams,
59
 
    local,
60
 
    Server,
61
54
    ssh,
62
55
    ConnectedTransport,
63
56
    )
114
107
        except FileExists:
115
108
            raise LockError('File %r already locked' % (self.path,))
116
109
 
117
 
    def __del__(self):
118
 
        """Should this warn, or actually try to cleanup?"""
119
 
        if self.lock_file:
120
 
            warning("SFTPLock %r not explicitly unlocked" % (self.path,))
121
 
            self.unlock()
122
 
 
123
110
    def unlock(self):
124
111
        if not self.lock_file:
125
112
            return
281
268
                    buffered = buffered[buffered_offset:]
282
269
                    buffered_data = [buffered]
283
270
                    buffered_len = len(buffered)
 
271
        # now that the data stream is done, close the handle
 
272
        fp.close()
284
273
        if buffered_len:
285
274
            buffered = ''.join(buffered_data)
286
275
            del buffered_data[:]
341
330
    # up the request itself, rather than us having to worry about it
342
331
    _max_request_size = 32768
343
332
 
344
 
    def __init__(self, base, _from_transport=None):
345
 
        super(SFTPTransport, self).__init__(base,
346
 
                                            _from_transport=_from_transport)
347
 
 
348
333
    def _remote_path(self, relpath):
349
334
        """Return the path to be passed along the sftp protocol for relpath.
350
335
 
351
336
        :param relpath: is a urlencoded string.
352
337
        """
353
 
        relative = urlutils.unescape(relpath).encode('utf-8')
354
 
        remote_path = self._combine_paths(self._path, relative)
 
338
        remote_path = self._parsed_url.clone(relpath).path
355
339
        # the initial slash should be removed from the path, and treated as a
356
340
        # homedir relative path (the path begins with a double slash if it is
357
341
        # absolute).  see draft-ietf-secsh-scp-sftp-ssh-uri-03.txt
376
360
        in base url at transport creation time.
377
361
        """
378
362
        if credentials is None:
379
 
            password = self._password
 
363
            password = self._parsed_url.password
380
364
        else:
381
365
            password = credentials
382
366
 
383
367
        vendor = ssh._get_ssh_vendor()
384
 
        user = self._user
 
368
        user = self._parsed_url.user
385
369
        if user is None:
386
370
            auth = config.AuthenticationConfig()
387
 
            user = auth.get_user('ssh', self._host, self._port)
388
 
        connection = vendor.connect_sftp(self._user, password,
389
 
                                         self._host, self._port)
 
371
            user = auth.get_user('ssh', self._parsed_url.host,
 
372
                self._parsed_url.port)
 
373
        connection = vendor.connect_sftp(self._parsed_url.user, password,
 
374
            self._parsed_url.host, self._parsed_url.port)
390
375
        return connection, (user, password)
391
376
 
392
377
    def disconnect(self):
421
406
        :param relpath: The relative path to the file
422
407
        """
423
408
        try:
424
 
            # FIXME: by returning the file directly, we don't pass this
425
 
            # through to report_activity.  We could try wrapping the object
426
 
            # before it's returned.  For readv and get_bytes it's handled in
427
 
            # the higher-level function.
428
 
            # -- mbp 20090126
429
409
            path = self._remote_path(relpath)
430
410
            f = self._get_sftp().file(path, mode='rb')
431
411
            if self._do_prefetch and (getattr(f, 'prefetch', None) is not None):