diff --git a/lib/DAV/tree/ftp.js b/lib/DAV/tree/ftp.js index c3b26b06..19fb5c7c 100644 --- a/lib/DAV/tree/ftp.js +++ b/lib/DAV/tree/ftp.js @@ -11,14 +11,10 @@ var jsDAV = require("../../jsdav"); var jsDAV_Tree = require("../tree").jsDAV_Tree; var jsDAV_Ftp_Directory = require("../ftp/directory").jsDAV_Ftp_Directory; var jsDAV_Ftp_File = require("../ftp/file").jsDAV_Ftp_File; - var Ftp = require("../../../support/jsftp/jsftp"); -var Util = require("../util"); var Exc = require("../exceptions"); var Path = require('path'); -var PWD_RE = /.*"(.*)".*/; - /** * jsDAV_Tree_Ftp * @@ -45,16 +41,16 @@ exports.jsDAV_Tree_Ftp = jsDAV_Tree_Ftp; var ftp = this.ftp = new Ftp(this.options); this.ftp.$cache = {}; this.ftpCmdListeners.forEach(function(listener) { - ftp.addCmdListener(listener) + ftp.addCmdListener(listener); }); }; this.addFtpCmdListener = function(listener) { if (this.ftp) - this.ftp.addCmdListener(listener) + this.ftp.addCmdListener(listener); else this.ftpCmdListeners.push(listener); - } + }; /** * Returns a new node for the given path @@ -63,15 +59,17 @@ exports.jsDAV_Tree_Ftp = jsDAV_Tree_Ftp; * @return void */ this.getNodeForPath = function(path, next) { - if (!path || path.match(/^\s+$/) || path.match(/^\/+$/)) + if (!path || path.match(/^\s+$/) || path.match(/^[\/]+$/)) path = this.basePath; if (!this.ftp) this.setup(); var ftp = this.ftp; - if (ftp.$cache[path]) + + if (ftp.$cache[path]) { return next(null, ftp.$cache[path]); + } // Root node requires special treatment because it will not be listed if (path === this.basePath) { @@ -82,7 +80,9 @@ exports.jsDAV_Tree_Ftp = jsDAV_Tree_Ftp; var self = this; var baseName = Path.basename(path).replace("/", ""); - ftp.ls(Path.dirname(path), function(err, res) { + path = this.getRealPath(path); + var parentDir = Path.resolve(path + "/.."); + ftp.ls(parentDir, function(err, res) { if (err) { if (res.code === 530) // Not logged in ftp.auth(self.options.user, self.options.pass, function(err, res) { @@ -98,7 +98,6 @@ exports.jsDAV_Tree_Ftp = jsDAV_Tree_Ftp; var file; for (var i = 0; i < res.length; i++) { var stat = res[i]; - if (stat.name === baseName) { file = stat; break; @@ -149,8 +148,8 @@ exports.jsDAV_Tree_Ftp = jsDAV_Tree_Ftp; */ this.copy = function(source, destination, next) { next(new Exc.jsDAV_Exception_NotImplemented( - "Could not copy from " + source + " to " + destination + ". " + - + "COPY/DUPLICATE not implemented.") + "Could not copy from " + source + " to " + destination + + ". COPY/DUPLICATE not implemented.") ); }; @@ -206,42 +205,6 @@ exports.jsDAV_Tree_Ftp = jsDAV_Tree_Ftp; } }; - /** - * Caches a path's parent path and its children, then goes back to the caller function with the - * same previous arguments. - * - * @param string path - * @return void - */ - this.$getParentNodeRecall = function(path) { - var caller = arguments.callee.caller; - var callerArgs = caller.arguments; - var callback; - var next = callback = callerArgs[callerArgs.length-1]; - var parentPath = Util.splitPath(path)[0]; - var self = this; - - this.getNodeForPath(parentPath.substring(this.basePath.length), function(err, node) { - if (err) - return next(err); - - node.getChildren(function(err, nodes) { - if (err) - return next(err); - - if (nodes.length && typeof caller === 'function') { - nodes.forEach(function(child) { - if (child.path === path) - callback = caller.bind.apply(caller, [self].concat([].slice.call(callerArgs))); - }); - callback(); - } else { - next(); - } - }); - }); - }; - this.unmount = function() { console.log("Closed connection to the server. Unmounting FTP tree."); if (this.ftp) { diff --git a/support/jsftp b/support/jsftp index f93b4eeb..e3f10c89 160000 --- a/support/jsftp +++ b/support/jsftp @@ -1 +1 @@ -Subproject commit f93b4eeb6d96ffebbc378c8c040684cf82a63885 +Subproject commit e3f10c8927347c170cdd0150ef38e18272acf942