~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/sftp.py

  • Committer: Robert Collins
  • Date: 2007-08-05 02:57:45 UTC
  • mto: (2592.3.77 repository)
  • mto: This revision was merged to the branch mainline in revision 2741.
  • Revision ID: robertc@robertcollins.net-20070805025745-eg2qmr8jzsky39y2
StartĀ open_file_streamĀ logic.

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
        )
54
54
from bzrlib.trace import mutter, warning
55
55
from bzrlib.transport import (
 
56
    _file_streams,
56
57
    local,
57
58
    register_urlparse_netloc_protocol,
58
59
    Server,
156
157
        super(SFTPTransport, self).__init__(base,
157
158
                                            _from_transport=_from_transport)
158
159
 
 
160
    def close_file_stream(self, relpath):
 
161
        """See Transport.close_file_stream."""
 
162
        handle = _file_streams.pop(self.abspath(relpath))
 
163
        handle.close()
 
164
 
159
165
    def _remote_path(self, relpath):
160
166
        """Return the path to be passed along the sftp protocol for relpath.
161
167
        
533
539
        """Create a directory at the given path."""
534
540
        self._mkdir(self._remote_path(relpath), mode=mode)
535
541
 
 
542
    def open_file_stream(self, relpath):
 
543
        """See Transport.open_file_stream."""
 
544
        # initialise the file to zero-length
 
545
        # this is three round trips, but we don't use this 
 
546
        # api more than once per write_group at the moment so 
 
547
        # it is a tolerable overhead. Better would be to truncate
 
548
        # the file after opening. RBC 20070805
 
549
        self.put_bytes_non_atomic(relpath, "")
 
550
        abspath = self._remote_path(relpath)
 
551
        # TODO: jam 20060816 paramiko doesn't publicly expose a way to
 
552
        #       set the file mode at create time. If it does, use it.
 
553
        #       But for now, we just chmod later anyway.
 
554
        handle = None
 
555
        try:
 
556
            handle = self._get_sftp().file(abspath, mode='wb')
 
557
            handle.set_pipelined(True)
 
558
        except (paramiko.SSHException, IOError), e:
 
559
            self._translate_io_exception(e, abspath,
 
560
                                         ': unable to open')
 
561
        _file_streams[self.abspath(relpath)] = handle
 
562
        return handle.write
 
563
 
536
564
    def _translate_io_exception(self, e, path, more_info='',
537
565
                                failure_exc=PathError):
538
566
        """Translate a paramiko or IOError into a friendlier exception.