SFTP: change error code returned for ExistingChildError to FX_FAILURE (fixes gvfs with some picky programs such as gedit).

This commit is contained in:
david-sarah 2010-05-17 17:42:05 -07:00
parent 57699fd1eb
commit 8d118e28f1
2 changed files with 11 additions and 3 deletions

View File

@ -107,10 +107,18 @@ def _raise_error(err):
if err.check(NoSuchChildError):
childname = err.value.args[0].encode('utf-8')
raise SFTPError(FX_NO_SUCH_FILE, childname)
if err.check(ExistingChildError) or err.check(NotWriteableError):
# later versions of SFTP define FX_FILE_ALREADY_EXISTS, but version 3 doesn't
if err.check(NotWriteableError):
msg = err.value.args[0].encode('utf-8')
raise SFTPError(FX_PERMISSION_DENIED, msg)
if err.check(ExistingChildError):
# Versions of SFTP after v3 (which is what twisted.conch implements)
# define a specific error code for this case: FX_FILE_ALREADY_EXISTS.
# However v3 doesn't; instead, other servers such as sshd return
# FX_FAILURE. The gvfs SFTP backend, for example, depends on this
# to translate the error to the equivalent of POSIX EEXIST, which is
# necessary for some picky programs (such as gedit).
msg = err.value.args[0].encode('utf-8')
raise SFTPError(FX_FAILURE, msg)
if err.check(NotImplementedError):
raise SFTPError(FX_OP_UNSUPPORTED, str(err.value))
if err.check(EOFError):

View File

@ -234,7 +234,7 @@ class Handler(GridTestMixin, ShouldFailMixin, unittest.TestCase):
self.shouldFailWithSFTPError(sftp.FX_NO_SUCH_FILE, "_raise_error NoSuchChildError",
sftpd._raise_error, Failure(NoSuchChildError("foo"))))
d.addCallback(lambda ign:
self.shouldFailWithSFTPError(sftp.FX_PERMISSION_DENIED, "_raise_error ExistingChildError",
self.shouldFailWithSFTPError(sftp.FX_FAILURE, "_raise_error ExistingChildError",
sftpd._raise_error, Failure(ExistingChildError("foo"))))
d.addCallback(lambda ign:
self.shouldFailWithSFTPError(sftp.FX_PERMISSION_DENIED, "_raise_error NotWriteableError",