~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/sftp.py

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011, 2016, 2017 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
16
16
 
17
17
"""Implementation of Transport over SFTP, using paramiko."""
18
18
 
 
19
from __future__ import absolute_import
 
20
 
19
21
# TODO: Remove the transport-based lock_read and lock_write methods.  They'll
20
22
# then raise TransportNotPossible, which will break remote access to any
21
23
# formats which rely on OS-level locks.  That should be fine as those formats
408
410
        try:
409
411
            path = self._remote_path(relpath)
410
412
            f = self._get_sftp().file(path, mode='rb')
 
413
            size = f.stat().st_size
411
414
            if self._do_prefetch and (getattr(f, 'prefetch', None) is not None):
412
 
                f.prefetch()
 
415
                f.prefetch(size)
413
416
            return f
414
417
        except (IOError, paramiko.SSHException), e:
415
418
            self._translate_io_exception(e, path, ': error retrieving',
591
594
                                    create_parent_dir=create_parent_dir,
592
595
                                    dir_mode=dir_mode)
593
596
 
594
 
    def put_bytes_non_atomic(self, relpath, bytes, mode=None,
 
597
    def put_bytes_non_atomic(self, relpath, raw_bytes, mode=None,
595
598
                             create_parent_dir=False,
596
599
                             dir_mode=None):
 
600
        if not isinstance(raw_bytes, str):
 
601
            raise TypeError(
 
602
                'raw_bytes must be a plain string, not %s' % type(raw_bytes))
 
603
 
597
604
        def writer(fout):
598
 
            fout.write(bytes)
 
605
            fout.write(raw_bytes)
599
606
        self._put_non_atomic_helper(relpath, writer, mode=mode,
600
607
                                    create_parent_dir=create_parent_dir,
601
608
                                    dir_mode=dir_mode)