From 61b09c7fc9be040308c7d1fdb73bed9818aa6827 Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Tue, 6 Jul 2010 15:10:50 +0300 Subject: [PATCH] Document ftp: fix NLST, path resolution. bzr revid: p_christ@hol.gr-20100706121050-5u0i2hsm2phz0i30 --- addons/document_ftp/ftpserver/abstracted_fs.py | 12 ++++++++---- addons/document_ftp/ftpserver/ftpserver.py | 12 +++++++++--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/addons/document_ftp/ftpserver/abstracted_fs.py b/addons/document_ftp/ftpserver/abstracted_fs.py index b5465c9873d..6731908d1cf 100644 --- a/addons/document_ftp/ftpserver/abstracted_fs.py +++ b/addons/document_ftp/ftpserver/abstracted_fs.py @@ -275,8 +275,8 @@ class abstracted_fs(object): if not os.path.isabs(path): path = os.path.join(self.root, path) - if path == '/' and mode in ('list', 'cwd'): - return (None, None, None ) + if path == '/' and mode in ('list', 'cwd'): + return (None, None, None ) path = os.path.normpath(path) # again, for '/db/../ss' if path == '.': path = '' @@ -299,12 +299,14 @@ class abstracted_fs(object): if os.path.isabs(path): # we have to start from root, again - p_parts = p_parts[1:] + while p_parts[0] == '': + p_parts = p_parts[1:] + # self._log.debug("Path parts: %r ", p_parts) if not p_parts: raise IOError(errno.EPERM, 'Cannot perform operation at root dir') dbname = p_parts[0] if dbname not in self.db_list(): - return IOError(errno.ENOENT,'Invalid database path') + raise IOError(errno.ENOENT,'Invalid database path') try: db = pooler.get_db(dbname) except Exception: @@ -320,6 +322,7 @@ class abstracted_fs(object): raise OSError(2, 'Authentification Required.') n = get_node_context(cr, uid, {}) node = n.get_uri(cr, p_parts[1:]) + # self._log.debug("get_crdata(abs): %r" % ( (cr, node, rem_path),)) return (cr, node, rem_path) else: # we never reach here if cwd_node is not set @@ -333,6 +336,7 @@ class abstracted_fs(object): if node is False and mode not in ('???'): cr.close() raise IOError(errno.ENOENT, 'Path does not exist') + # self._log.debug("get_crdata(rel): %r" % ( (cr, node, rem_path),)) return (cr, node, rem_path) def get_node_cr_uid(self, node): diff --git a/addons/document_ftp/ftpserver/ftpserver.py b/addons/document_ftp/ftpserver/ftpserver.py index f92fbb34613..75ad5b00883 100644 --- a/addons/document_ftp/ftpserver/ftpserver.py +++ b/addons/document_ftp/ftpserver/ftpserver.py @@ -2043,11 +2043,17 @@ class FTPHandler(asynchat.async_chat): if not datacr: datacr = ( None, None, None ) if self.fs.isdir(datacr[1]): - listing = self.run_as_current_user(self.fs.listdir, datacr) - listing = [ x.path[-1] for x in listing ] + nodelist = self.run_as_current_user(self.fs.listdir, datacr) else: # if path is a file we just list its name - listing = [datacr[1].path[-1],] + nodelist = [datacr[1],] + + listing = [] + for nl in nodelist: + if isinstance(nl.path, (list, tuple)): + listing.append(nl.path[-1]) + else: + listing.append(nl.path) # assume string except IOError, err: self.fs.close_cr(datacr) self.respond('550 %s.'% err.strerror)