From 3de829c69376242b7ad94b75c62945ec0468f109 Mon Sep 17 00:00:00 2001 From: johnnyman727 Date: Thu, 1 Oct 2015 00:08:11 -0700 Subject: [PATCH] Fixes tessel erase --- lib/tessel/commands.js | 3 +++ lib/tessel/deploy.js | 8 +++----- lib/tessel/erase.js | 39 +++++++++++++++++++++------------------ lib/tessel/tessel.js | 3 +++ 4 files changed, 30 insertions(+), 23 deletions(-) diff --git a/lib/tessel/commands.js b/lib/tessel/commands.js index 24bb17ae..9760a092 100644 --- a/lib/tessel/commands.js +++ b/lib/tessel/commands.js @@ -7,6 +7,9 @@ module.exports.scanWiFi = function() { module.exports.stopRunningScript = function() { return ['/etc/init.d/tessel-app', 'stop']; }; +module.exports.disablePushedScript = function() { + return ['/etc/init.d/tessel-app', 'disable']; +} module.exports.deleteFolder = function(filepath) { return ['rm', '-rf', filepath]; }; diff --git a/lib/tessel/deploy.js b/lib/tessel/deploy.js index 7d4877ec..e5724331 100644 --- a/lib/tessel/deploy.js +++ b/lib/tessel/deploy.js @@ -6,8 +6,6 @@ var path = require('path'); var tar = require('tar'); var Ignore = require('fstream-ignore'); -var RUN_PATH = '/tmp/remote-script/'; -var PUSH_PATH = '/app/'; var PUSH_START_SCRIPT_NAME = 'start'; var NODE_PUSH_SCRIPT = __dirname + '/../../resources/start_node_script.sh'; @@ -25,7 +23,7 @@ Tessel.prototype.deployScript = function(opts) { var isPush = opts.push === true; return new Promise(function(resolve, reject) { - var filepath = isPush ? PUSH_PATH : RUN_PATH; + var filepath = isPush ? Tessel.PUSH_PATH : Tessel.RUN_PATH; // Stop running any existing scripts return actions.execRemoteCommand(self, 'stopRunningScript', filepath) @@ -65,7 +63,7 @@ Tessel.prototype.deployScript = function(opts) { Tessel.prototype.restartScript = function(opts) { var self = this; var isPush = opts.type === 'flash'; - var filepath = isPush ? PUSH_PATH : RUN_PATH; + var filepath = isPush ? Tessel.PUSH_PATH : Tessel.RUN_PATH; return new Promise(function(resolve, reject) { return self.simpleExec(commands.readFile(filepath + opts.entryPoint)) @@ -286,7 +284,7 @@ actions.pushScript = function(t, entryPoint) { actions.writeToFile = function(t) { return new Promise(function(resolve, reject) { // Path of the script to run a Node project - var executablePath = PUSH_PATH + PUSH_START_SCRIPT_NAME; + var executablePath = Tessel.PUSH_PATH + PUSH_START_SCRIPT_NAME; // Open a stdin pipe tp the file return t.connection.exec(commands.openStdinToFile(executablePath)) // If it was opened successfully diff --git a/lib/tessel/erase.js b/lib/tessel/erase.js index 6f7cb932..62657d24 100644 --- a/lib/tessel/erase.js +++ b/lib/tessel/erase.js @@ -4,23 +4,26 @@ var Tessel = require('./tessel'), Tessel.prototype.eraseScript = function() { var self = this; - return new Promise(function(resolve, reject) { - logs.info('Erasing files from Flash...'); - return self.simpleExec(commands.stopRunningScript()) - .then(function stopped() { - logs.info('Files erased.'); - return resolve(); - }) - .catch(function(error) { - // If we get a notice that the command failed - if (error.message.indexOf('Command failed') !== -1) { - // Let the user know what went wrong - return reject('No files have been pushed. Run `tessel push FILE` to push to Flash.'); - } else { - // Otherwise this is an unexpected error - return reject('An unexpected error occurred:' + error.message); - } - }); - }); + logs.info('Erasing files from Flash...'); + return self.simpleExec(commands.stopRunningScript()) + .then(function stopped() { + return self.simpleExec(commands.disablePushedScript()) + }) + .then(function disabled() { + return self.simpleExec(commands.deleteFolder(Tessel.PUSH_PATH)) + .then(function erased() { + logs.info('Files erased.'); + }) + }) + .catch(function(error) { + // If we get a notice that the command failed + if (error.message.indexOf('Command failed') !== -1) { + // Let the user know what went wrong + return Promise.reject('No files have been pushed. Run `tessel push FILE` to push to Flash.'); + } else { + // Otherwise this is an unexpected error + return Promise.reject('An unexpected error occurred:' + error.message); + } + }); }; diff --git a/lib/tessel/tessel.js b/lib/tessel/tessel.js index 29dee72d..10bacd5a 100644 --- a/lib/tessel/tessel.js +++ b/lib/tessel/tessel.js @@ -107,6 +107,9 @@ Tessel.prototype.simpleExec = function(command) { }); }; +Tessel.PUSH_PATH = '/app'; +Tessel.RUN_PATH = '/tmp/remote-script'; + module.exports = Tessel; require('./provision');