From: Brian Warner Date: Thu, 26 Mar 2015 01:23:33 +0000 (-0700) Subject: Fix ftp 'ls' to work with current Twisted-15.0.0 X-Git-Tag: allmydata-tahoe-1.10.1a1~49^2~3 X-Git-Url: https://git.rkrishnan.org/vdrive/quickstart.html?a=commitdiff_plain;h=26c8abadece8de68c6e905d47ea31a479788ce47;p=tahoe-lafs%2Ftahoe-lafs.git Fix ftp 'ls' to work with current Twisted-15.0.0 refs ticket:2394 It's kind of a hack, but Twisted changed the API and I couldn't find a cleaner way to detect which form of "permissions" value the Twisted FTP server wants. I've manually tested it against 14.0.2 and 15.0.0. --- diff --git a/src/allmydata/frontends/ftpd.py b/src/allmydata/frontends/ftpd.py index 9922a86a..dbcb8318 100644 --- a/src/allmydata/frontends/ftpd.py +++ b/src/allmydata/frontends/ftpd.py @@ -6,6 +6,7 @@ from twisted.application import service, strports from twisted.internet import defer from twisted.internet.interfaces import IConsumer from twisted.cred import portal +from twisted.python import filepath from twisted.protocols import ftp from allmydata.interfaces import IDirectoryNode, ExistingChildError, \ @@ -61,6 +62,19 @@ class WriteFile: class NoParentError(Exception): pass +if hasattr(filepath, "Permissions"): + # filepath.Permissions was added in Twisted-11.1.0, but we're compatible + # back to 11.0.0 (on windows). Fortunately we don't really need to + # provide anything more than an int until Twisted-15.0.0 . + class IntishPermissions(filepath.Permissions): + def __init__(self, statModeInt): + self.statModeInt = statModeInt + filepath.Permissions.__init__(self, statModeInt) + def __and__(self, other): + return self.statModeInt & other +else: + IntishPermissions = lambda statModeInt: statModeInt + class Handler: implements(ftp.IFTPShell) def __init__(self, client, rootnode, username, convergence): @@ -200,7 +214,11 @@ class Handler: elif key == "directory": value = isdir elif key == "permissions": - value = 0600 + # Twisted-14.0.2 expected an int, and used it in a rendering + # function that did (mode & NUMBER). Twisted-15.0.0 expects a + # twisted.python.filepath.Permissions , and calls its + # .shorthand() method. Try to provide both. + value = IntishPermissions(0600) elif key == "hardlinks": value = 1 elif key == "modified":