~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/sftp.py

  • Committer: John Arbash Meinel
  • Date: 2006-03-08 14:31:23 UTC
  • mfrom: (1598 +trunk)
  • mto: (1685.1.1 bzr-encoding)
  • mto: This revision was merged to the branch mainline in revision 1752.
  • Revision ID: john@arbash-meinel.com-20060308143123-448308b0db4de410
[merge] bzr.dev 1573, lots of updates

Show diffs side-by-side

added added

removed removed

Lines of Context:
417
417
                self._sftp.chmod(tmp_abspath, mode)
418
418
            fout.close()
419
419
            closed = True
420
 
            self._rename(tmp_abspath, abspath)
 
420
            self._rename_and_overwrite(tmp_abspath, abspath)
421
421
        except Exception, e:
422
422
            # If we fail, try to clean up the temporary file
423
423
            # before we throw the exception
501
501
        try:
502
502
            path = self._remote_path(relpath)
503
503
            fout = self._sftp.file(path, 'ab')
 
504
            result = fout.tell()
504
505
            self._pump(f, fout)
 
506
            return result
505
507
        except (IOError, paramiko.SSHException), e:
506
508
            self._translate_io_exception(e, relpath, ': unable to append')
507
509
 
508
 
    def _rename(self, abs_from, abs_to):
 
510
    def rename(self, rel_from, rel_to):
 
511
        """Rename without special overwriting"""
 
512
        try:
 
513
            self._sftp.rename(self._remote_path(rel_from),
 
514
                              self._remote_path(rel_to))
 
515
        except (IOError, paramiko.SSHException), e:
 
516
            self._translate_io_exception(e, rel_from,
 
517
                    ': unable to rename to %r' % (rel_to))
 
518
 
 
519
    def _rename_and_overwrite(self, abs_from, abs_to):
509
520
        """Do a fancy rename on the remote server.
510
521
        
511
522
        Using the implementation provided by osutils.
521
532
        """Move the item at rel_from to the location at rel_to"""
522
533
        path_from = self._remote_path(rel_from)
523
534
        path_to = self._remote_path(rel_to)
524
 
        self._rename(path_from, path_to)
 
535
        self._rename_and_overwrite(path_from, path_to)
525
536
 
526
537
    def delete(self, relpath):
527
538
        """Delete the item at relpath"""
938
949
        _ssh_vendor = self._original_vendor
939
950
 
940
951
 
 
952
class SFTPFullAbsoluteServer(SFTPServer):
 
953
    """A test server for sftp transports, using absolute urls and ssh."""
 
954
 
 
955
    def get_url(self):
 
956
        """See bzrlib.transport.Server.get_url."""
 
957
        return self._get_sftp_url(urlescape(self._homedir[1:]))
 
958
 
 
959
 
941
960
class SFTPServerWithoutSSH(SFTPServer):
942
 
    """
943
 
    Common code for an SFTP server over a clear TCP loopback socket,
944
 
    instead of over an SSH secured socket.
945
 
    """
 
961
    """An SFTP server that uses a simple TCP socket pair rather than SSH."""
946
962
 
947
963
    def __init__(self):
948
964
        super(SFTPServerWithoutSSH, self).__init__()