From ee2348cc33d5cff02e7eaebe6dcb943cebbd6ef4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Acun=CC=83a?= Date: Tue, 5 Sep 2017 16:54:37 -0300 Subject: [PATCH] Location, webcam and wipe fixes --- lib/agent/actions/wipe/index.js | 19 ++++++++++--------- lib/agent/providers/webcam/windows/index.js | 4 +++- lib/agent/triggers/location/index.js | 6 +++--- test/lib/agent/providers/geo/wifi_strategy.js | 2 +- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/lib/agent/actions/wipe/index.js b/lib/agent/actions/wipe/index.js index fa1f2c2bb..e8d61c70a 100644 --- a/lib/agent/actions/wipe/index.js +++ b/lib/agent/actions/wipe/index.js @@ -49,14 +49,16 @@ exports.start = function(opts, cb) { removed = 0; // runs it within this context, unlike the spawn option - var queue = function(method) { + var queue = function(error, method) { queued++; - wipe[method](function(err, removed) { - if (err) last_err = err; + if (typeof wipe[method] == 'function') { + wipe[method](function(err, removed) { + if (err) last_err = err; - removed += removed; - --queued || finished(last_err); - }) + removed += removed; + --queued || finished(last_err); + }) + } else return finished(error); } // run it as another process, using impersonation (to avoid permission errors) @@ -67,10 +69,9 @@ exports.start = function(opts, cb) { if (err) { if (err.toString().includes('No logged user') && os_name == 'windows') { logger.warn('Not logged user found, proceding without impersonation') - queue(items); + return queue(err, items); } - else - return finished(err); + else return finished(err); } child.stdout.on('data', function(str) { diff --git a/lib/agent/providers/webcam/windows/index.js b/lib/agent/providers/webcam/windows/index.js index 0a8b3fb0c..be4a5cafb 100644 --- a/lib/agent/providers/webcam/windows/index.js +++ b/lib/agent/providers/webcam/windows/index.js @@ -21,6 +21,8 @@ exports.get_picture = function(file, callback){ }) } - take_picture(0); + fs.unlink(file, function() { + take_picture(0); + }) } \ No newline at end of file diff --git a/lib/agent/triggers/location/index.js b/lib/agent/triggers/location/index.js index 688031dd2..c0c90ac90 100644 --- a/lib/agent/triggers/location/index.js +++ b/lib/agent/triggers/location/index.js @@ -15,7 +15,6 @@ var trigger_event = function(type, new_location) { if (Object.keys(current).length == 0) { current = new_location; - return emitter.emit(event, new_location); } @@ -26,7 +25,7 @@ var trigger_event = function(type, new_location) { new_location.delta = distance; current = new_location; - emitter.emit(event, new_location); + hooks.emit(event, new_location); } var fetch_location = function(type, callback) { @@ -43,7 +42,8 @@ var fetch_location = function(type, callback) { checking = true; geo.fetch_location(function(err, coords) { - if (err || !coords || !emitter) return done(err); + if (err || !coords || !emitter) + return done(new Error('Unable to get location')); done(null, coords); trigger_event(type, coords); diff --git a/test/lib/agent/providers/geo/wifi_strategy.js b/test/lib/agent/providers/geo/wifi_strategy.js index dfa31f925..525af870f 100644 --- a/test/lib/agent/providers/geo/wifi_strategy.js +++ b/test/lib/agent/providers/geo/wifi_strategy.js @@ -124,7 +124,7 @@ describe('location', function() { it('works', function(done) { provider_stub.restore(); - this.timeout(5000); // response may take longer + this.timeout(6000); // response may take longer wifi_strat(function(err, data) { if (err) {