Advertisement
Guest User

sftp unsupported operation patch

a guest
Jul 27th, 2012
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.25 KB | None | 0 0
  1. === modified file 'bzrlib/errors.py'
  2. --- bzrlib/errors.py    2012-07-19 19:27:22 +0000
  3. +++ bzrlib/errors.py    2012-07-26 12:16:40 +0000
  4. @@ -1618,6 +1618,14 @@
  5.                  self.exc_type, self.exc_value, self.exc_tb)
  6.          self.traceback_text = ''.join(traceback_strings)
  7.  
  8. +class TransportOperationNotSupported(TransportError):
  9. +
  10. +    _fmt = "Transport operation is not supported: %(operation)s%(msg)s"
  11. +
  12. +    def __init__(self, operation, msg=None):
  13. +        if msg != None:
  14. +            self.msg = "\n" + msg
  15. +        self.operation = operation
  16.  
  17.  # A set of semi-meaningful errors which can be thrown
  18.  class TransportNotPossible(TransportError):
  19.  
  20. === modified file 'bzrlib/tests/test_sftp_transport.py'
  21. --- bzrlib/tests/test_sftp_transport.py 2012-02-23 23:26:35 +0000
  22. +++ bzrlib/tests/test_sftp_transport.py 2012-07-27 14:04:34 +0000
  23. @@ -497,3 +497,18 @@
  24.          # No prompts should've been printed, stdin shouldn't have been read
  25.          self.assertEquals("", stdout.getvalue())
  26.          self.assertEquals(0, ui.ui_factory.stdin.tell())
  27. +
  28. +class TestUnsupportedOperationExceptionTranslation(TestCaseWithSFTPServer):
  29. +    """Test that unsupported operation exception from Paramiko is correctly
  30. +    translated into TransportOperationNotSupported."""
  31. +
  32. +    def test_sftp_unsupported_rename_operation(self):
  33. +        t = self.get_transport()
  34. +
  35. +        e = self.assertRaises(
  36. +            errors.TransportOperationNotSupported("rename",
  37. +                          "unable to rename"),
  38. +                          t._translate_io_exception,
  39. +                          IOError("Operation unsupported"),
  40. +                          "unable to rename", operation="rename")
  41. +        self.assertEquals(e, "TransportOperationNotSupported: Transport operation is not supported: rename")
  42. \ No newline at end of file
  43.  
  44. === modified file 'bzrlib/transport/sftp.py'
  45. --- bzrlib/transport/sftp.py    2011-12-19 13:23:58 +0000
  46. +++ bzrlib/transport/sftp.py    2012-07-27 14:10:00 +0000
  47. @@ -671,7 +671,7 @@
  48.          return FileFileStream(self, relpath, handle)
  49.  
  50.      def _translate_io_exception(self, e, path, more_info='',
  51. -                                failure_exc=PathError):
  52. +                                failure_exc=PathError, operation=None):
  53.          """Translate a paramiko or IOError into a friendlier exception.
  54.  
  55.         :param e: The original exception
  56. @@ -683,6 +683,7 @@
  57.                            no more information.
  58.                            If this parameter is set, it defines the exception
  59.                            to raise in these cases.
  60. +        :param operation: Operation that failed (needs to check if it's supported)
  61.         """
  62.          # paramiko seems to generate detailless errors.
  63.          self._translate_error(e, path, raise_generic=False)
  64. @@ -703,7 +704,8 @@
  65.                  or getattr(e, 'errno', None) == errno.ENOTEMPTY):
  66.                  raise errors.DirectoryNotEmpty(path, str(e))
  67.              if e.args == ('Operation unsupported',):
  68. -                raise errors.TransportNotPossible()
  69. +                raise errors.TransportOperationNotSupported(operation, more_info)
  70. +                # raise errors.TransportNotPossible(more_info)
  71.              mutter('Raising exception with args %s', e.args)
  72.          if getattr(e, 'errno', None) is not None:
  73.              mutter('Raising exception with errno %s', e.errno)
  74. @@ -732,7 +734,7 @@
  75.                                self._remote_path(rel_to))
  76.          except (IOError, paramiko.SSHException), e:
  77.              self._translate_io_exception(e, rel_from,
  78. -                    ': unable to rename to %r' % (rel_to))
  79. +                    ': unable to rename to %r' % (rel_to), "rename")
  80.  
  81.      def _rename_and_overwrite(self, abs_from, abs_to):
  82.          """Do a fancy rename on the remote server.
  83. @@ -746,7 +748,7 @@
  84.                          unlink_func=sftp.remove)
  85.         except (IOError, paramiko.SSHException), e:
  86.             self._translate_io_exception(e, abs_from,
  87. -                                         ': unable to rename to %r' % (abs_to))
  88. +                    ': unable to rename to %r' % (abs_to), operation="rename")
  89.  
  90.     def move(self, rel_from, rel_to):
  91.         """Move the item at rel_from to the location at rel_to"""
  92. @@ -760,7 +762,8 @@
  93.         try:
  94.             self._get_sftp().remove(path)
  95.         except (IOError, paramiko.SSHException), e:
  96. -            self._translate_io_exception(e, path, ': unable to delete')
  97. +            self._translate_io_exception(e, path, ': unable to delete',
  98. +                         operation="delete")
  99.  
  100.     def external_url(self):
  101.         """See bzrlib.transport.Transport.external_url."""
  102. @@ -793,7 +796,8 @@
  103.         try:
  104.             return self._get_sftp().rmdir(path)
  105.         except (IOError, paramiko.SSHException), e:
  106. -            self._translate_io_exception(e, path, ': failed to rmdir')
  107. +            self._translate_io_exception(e, path, ': failed to rmdir',
  108. +                        operation="rmdir")
  109.  
  110.     def stat(self, relpath):
  111.         """Return the stat information for a file."""
  112. @@ -809,7 +813,8 @@
  113.         try:
  114.             return self._get_sftp().readlink(path)
  115.         except (IOError, paramiko.SSHException), e:
  116. -            self._translate_io_exception(e, path, ': unable to readlink')
  117. +            self._translate_io_exception(e, path, ': unable to readlink',
  118. +                    operation="readlink")
  119.  
  120.     def symlink(self, source, link_name):
  121.         """See Transport.symlink."""
  122. @@ -823,7 +828,8 @@
  123.                 )
  124.         except (IOError, paramiko.SSHException), e:
  125.             self._translate_io_exception(e, link_name,
  126. -                                         ': unable to create symlink to %r' % (source))
  127. +                    ': unable to create symlink to %r' % (source),
  128. +                    operation="symlink")
  129.  
  130.     def lock_read(self, relpath):
  131.         """
  132. @@ -884,7 +890,7 @@
  133.              return SFTPFile(self._get_sftp(), handle, 'wb', -1)
  134.          except (paramiko.SSHException, IOError), e:
  135.              self._translate_io_exception(e, abspath, ': unable to open',
  136. -                failure_exc=FileExists)
  137. +                failure_exc=FileExists, operation="open")
  138.  
  139.      def _can_roundtrip_unix_modebits(self):
  140.          if sys.platform == 'win32':
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement