diff --git a/ftp-sync_2.0.4.zip b/ftp-sync_2.0.4.zip index 4a9c7dc..929face 100644 Binary files a/ftp-sync_2.0.4.zip and b/ftp-sync_2.0.4.zip differ diff --git a/src/main.js b/src/main.js index ed8ecf2..2edf1fe 100644 --- a/src/main.js +++ b/src/main.js @@ -56,6 +56,7 @@ define(function (require, exports, module) { var projectRoot = ProjectManager.getProjectRoot().fullPath; var file = FileSystem.getFileForPath(projectRoot + '.ftpsync_settings'); + // Replace date object with equivalent time since function replacePwd(key, value) { if (key === "pwd") return undefined; return value; @@ -77,6 +78,10 @@ define(function (require, exports, module) { // settings file exists so parse console.log('[ftp-sync] parsed .ftpsync_settings'); ftpSettings = $.parseJSON(text); + if (ftpSettings.lastSyncDate === undefined) { + ftpSettings.lastSyncDate = 0; + } + if (ftpSettings.connect === undefined) ftpSettings.connect = 'FTP'; callback(); }); @@ -89,6 +94,7 @@ define(function (require, exports, module) { }); } + // handle FTP-SFTP select function handleSelect() { @@ -168,6 +174,19 @@ define(function (require, exports, module) { }); } + function handleDisconnect (event, completed) { + // close dialog on disconnect + console.log ("Disconnect called with completed status " + completed); + + if (completed) { + ftpSettings.lastSyncDate = new Date().getTime(); + saveSettings(); + } + + Dialogs.cancelModalDialogIfOpen("ftp-dialog"); + + } + // general event handler of node-side events function handleEvent(event, msg) { @@ -191,7 +210,7 @@ define(function (require, exports, module) { $dlg.find(".spinner").removeClass("spin"); inProcess = false; } - + if (msg) { // ignore when msg undefined var $status = $dlg.find("#status"); msg.split('\n').forEach(function (line) { @@ -201,11 +220,6 @@ define(function (require, exports, module) { $status.html(line); }); } - - // close dialog on disconnect - if (event.type == "ftpsync:disconnected") { - Dialogs.cancelModalDialogIfOpen("ftp-dialog"); - } } @@ -244,6 +258,9 @@ define(function (require, exports, module) { if (ftpSettings.connect === 'SFTP') $dlg.find('#sftp-btn').trigger('click'); }); + + // read document date cache on dialog box creation as the + // user may flip between projects } function getDefaultKeyPath() { @@ -294,7 +311,7 @@ define(function (require, exports, module) { // listen for events $(ftpDomain.connection).on("ftpsync:connected", handleEvent); - $(ftpDomain.connection).on("ftpsync:disconnected", handleEvent); + $(ftpDomain.connection).on("ftpsync:disconnected", handleDisconnect); $(ftpDomain.connection).on("ftpsync:uploaded", handleEvent); $(ftpDomain.connection).on("ftpsync:chkdir", handleEvent); $(ftpDomain.connection).on("ftpsync:mkdir", handleEvent); diff --git a/src/node/FTP.js b/src/node/FTP.js index f5a30b7..c7e0b18 100644 --- a/src/node/FTP.js +++ b/src/node/FTP.js @@ -19,6 +19,11 @@ function FTP(domainManager) { FTP.prototype.connect = function(opts, cb) { var self = this; this.ftp = new this.JSFtp(opts); + this.lastSyncDate = opts.lastSyncDate; + this.lastSyncDateAsDate = new Date(opts.lastSyncDate); + + console.log("Set last sync date to " + this.lastSyncDateAsDate); + this.ftp.auth(opts.user, opts.pwd, function(err, data) { if (err) { self._domainManager.emitEvent('ftpsync', 'error', err.toString()); @@ -49,17 +54,29 @@ FTP.prototype.stat = function(remotePath, cb) { }; FTP.prototype.exists = function(localPath, remotePath, cb) { + // Get information about the local file + var fsInfo = fs.statSync(localPath); + var size = fsInfo.size; + + // Treat the file as if it exists if it hasn't been modified since the last sync date + if (fsInfo.mtime.getTime() <= this.lastSyncDate) { + return cb(true); + } + else { + console.log("File " + localPath + " modified on " + fsInfo.mtime + "; after last sync on " + this.lastSyncDateAsDate); + return cb(false); + } + + /*var escapedRemotePath = remotePath.replace(/\s/g, "\\ "); // stat whether same size file exists or not - this.ftp.ls(remotePath, function(err, data) { + this.ftp.ls(escapedRemotePath, function(err, data) { if (err) return cb(err); // irrespective of FTP 200 code, data gives us file info if (data.length === 0) return cb(false) - - // return filesize whether filesize the same - var size = fs.statSync(localPath).size; + // Compare local and remote file sizes if (size === parseInt(data[0].size, 10)) return cb(true); cb(false); - }); + });*/ }; FTP.prototype.put = function(localPath, remotePath, cb) { diff --git a/src/node/core.js b/src/node/core.js index c943280..fb3107c 100644 --- a/src/node/core.js +++ b/src/node/core.js @@ -63,7 +63,7 @@ maxerr: 50, node: true, white: true */ // console.log('final called'); if (emitOK === undefined) emitOK = true; ftp.disconnect(); - if (emitOK) _domainManager.emitEvent("ftpsync", "disconnected"); + _domainManager.emitEvent("ftpsync", "disconnected", emitOK) console.log('disconnected'); // reset flags processOps = false; @@ -76,7 +76,7 @@ maxerr: 50, node: true, white: true */ if (op) { if (haltCalled) { ops = []; - return final(); + return final(false); } var func = op[0]; func(op[1], op[2]);