~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/sftp.py

  • Committer: Martin
  • Date: 2011-08-04 00:17:53 UTC
  • mto: This revision was merged to the branch mainline in revision 6055.
  • Revision ID: gzlist@googlemail.com-20110804001753-plgpwcpsxcum16yb
Make tests raising KnownFailure use the knownFailure method instead

Show diffs side-by-side

added added

removed removed

Lines of Context:
114
114
        except FileExists:
115
115
            raise LockError('File %r already locked' % (self.path,))
116
116
 
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
117
    def unlock(self):
124
118
        if not self.lock_file:
125
119
            return
281
275
                    buffered = buffered[buffered_offset:]
282
276
                    buffered_data = [buffered]
283
277
                    buffered_len = len(buffered)
 
278
        # now that the data stream is done, close the handle
 
279
        fp.close()
284
280
        if buffered_len:
285
281
            buffered = ''.join(buffered_data)
286
282
            del buffered_data[:]
341
337
    # up the request itself, rather than us having to worry about it
342
338
    _max_request_size = 32768
343
339
 
344
 
    def __init__(self, base, _from_transport=None):
345
 
        super(SFTPTransport, self).__init__(base,
346
 
                                            _from_transport=_from_transport)
347
 
 
348
340
    def _remote_path(self, relpath):
349
341
        """Return the path to be passed along the sftp protocol for relpath.
350
342
 
389
381
                                         self._host, self._port)
390
382
        return connection, (user, password)
391
383
 
 
384
    def disconnect(self):
 
385
        connection = self._get_connection()
 
386
        if connection is not None:
 
387
            connection.close()
 
388
 
392
389
    def _get_sftp(self):
393
390
        """Ensures that a connection is established"""
394
391
        connection = self._get_connection()
416
413
        :param relpath: The relative path to the file
417
414
        """
418
415
        try:
419
 
            # FIXME: by returning the file directly, we don't pass this
420
 
            # through to report_activity.  We could try wrapping the object
421
 
            # before it's returned.  For readv and get_bytes it's handled in
422
 
            # the higher-level function.
423
 
            # -- mbp 20090126
424
416
            path = self._remote_path(relpath)
425
417
            f = self._get_sftp().file(path, mode='rb')
426
418
            if self._do_prefetch and (getattr(f, 'prefetch', None) is not None):
715
707
            if (e.args[0].startswith('Directory not empty: ')
716
708
                or getattr(e, 'errno', None) == errno.ENOTEMPTY):
717
709
                raise errors.DirectoryNotEmpty(path, str(e))
 
710
            if e.args == ('Operation unsupported',):
 
711
                raise errors.TransportNotPossible()
718
712
            mutter('Raising exception with args %s', e.args)
719
713
        if getattr(e, 'errno', None) is not None:
720
714
            mutter('Raising exception with errno %s', e.errno)