diff options
author | btimby <btimby@67cdc799-7952-0410-af00-57a81ceafa0f> | 2012-10-18 03:03:25 +0000 |
---|---|---|
committer | btimby <btimby@67cdc799-7952-0410-af00-57a81ceafa0f> | 2012-10-18 03:03:25 +0000 |
commit | b4e858df0e66579d1bf298e53dc13b00fa3bf90e (patch) | |
tree | 54e91c773eabe2ba3904a50aafed4f81ae450689 /fs/expose/ftp.py | |
parent | d913814dd969892f2e3025f160fe4e488b3a98b5 (diff) | |
download | pyfilesystem-b4e858df0e66579d1bf298e53dc13b00fa3bf90e.tar.gz |
Be less heavy-handed, setting the reference to None will do.
Ensure that pyfs file systems are closed when use with ftp and sftp daemons.
git-svn-id: http://pyfilesystem.googlecode.com/svn/trunk@824 67cdc799-7952-0410-af00-57a81ceafa0f
Diffstat (limited to 'fs/expose/ftp.py')
-rw-r--r-- | fs/expose/ftp.py | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/fs/expose/ftp.py b/fs/expose/ftp.py index 55f9ce5..b2dcb42 100644 --- a/fs/expose/ftp.py +++ b/fs/expose/ftp.py @@ -78,6 +78,12 @@ class FTPFS(ftpserver.AbstractedFS): self.encoding = encoding super(FTPFS, self).__init__(root, cmd_channel) + def close(self): + # Close and dereference the pyfs file system. + if self.fs: + self.fs.close() + self.fs = None + def validpath(self, path): try: normpath(path) @@ -207,6 +213,19 @@ class FTPFS(ftpserver.AbstractedFS): return True +class FTPFSHandler(ftpserver.FTPHandler): + """ + An FTPHandler class that closes the filesystem when done. + """ + + def close(self): + # Close the FTPFS instance, it will close the pyfs file system. + if self.fs: + self.fs.close() + super(FTPFSHandler, self).close() + + + class FTPFSFactory(object): """ A factory class which can hold a reference to a file system object and @@ -247,7 +266,7 @@ def serve_fs(fs, addr, port): combo. """ from pyftpdlib.contrib.authorizers import UnixAuthorizer - ftp_handler = ftpserver.FTPHandler + ftp_handler = FTPFSHandler ftp_handler.authorizer = ftpserver.DummyAuthorizer() ftp_handler.authorizer.add_anonymous('/') ftp_handler.abstracted_fs = FTPFSFactory(fs) |