]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
SFTP: change error code returned for ExistingChildError to FX_FAILURE (fixes gvfs...
authordavid-sarah <david-sarah@jacaranda.org>
Tue, 18 May 2010 00:42:05 +0000 (17:42 -0700)
committerdavid-sarah <david-sarah@jacaranda.org>
Tue, 18 May 2010 00:42:05 +0000 (17:42 -0700)
src/allmydata/frontends/sftpd.py
src/allmydata/test/test_sftp.py

index e978c508559662587c5884b543ec6cdddaad94d9..eb172c95508392509cf0aa568cbf17626a0a0819 100644 (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):
index 51a9f9624f6b297a4852f257b831638b66956a78..c6b1fa0600720078fd5f9e5ab624a9ed73de4ba0 100644 (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",