Prevent resin-write infinite loop

This commit is contained in:
Juan Cruz Viotti 2015-03-03 12:38:45 -04:00
parent 4acc85abb8
commit 4aefb15c70
3 changed files with 19 additions and 9 deletions

View File

@ -1,10 +1,7 @@
#!/usr/bin/env node
// http://coffeescript.org/documentation/docs/register.html
require('coffee-script/register');
var os = require('../lib/actions/os.coffee');
var errors = require('../lib/errors');
var os = require('../build/actions/os');
var errors = require('../build/errors');
// TODO: Do some error handling when image or device are incorrect
@ -12,7 +9,8 @@ os.install.action({
image: process.argv[2],
device: process.argv[3]
}, {
yes: true
yes: true,
fromScript: true
}, function(error) {
return errors.handle(error);
});

View File

@ -120,7 +120,10 @@
}
], function(error) {
var resinWritePath, windosu;
if (os.platform() === 'win32' && (error != null) && (error.code === 'EPERM' || error.code === 'EACCES')) {
if (error == null) {
return done();
}
if (_.all([os.platform() === 'win32', error.code === 'EPERM' || error.code === 'EACCES', !options.fromScript])) {
windosu = require('windosu');
resinWritePath = "\"" + (path.join(__dirname, '..', '..', 'bin', 'resin-write')) + "\"";
return windosu.exec("\"" + process.argv[0] + "\" " + resinWritePath + " \"" + params.image + "\" \"" + params.device + "\"");

View File

@ -152,9 +152,18 @@ exports.install =
diskio.writeStream(params.device, imageFileStream, callback)
], (error) ->
if os.platform() is 'win32' and error? and (error.code is 'EPERM' or error.code is 'EACCES')
windosu = require('windosu')
return done() if not error?
if _.all [
os.platform() is 'win32'
error.code is 'EPERM' or error.code is 'EACCES'
# Prevent re-running resin-write infinitely
# If we have an EPERM or EACCES even after running
# windosu, we throw it as there is not much we can do
not options.fromScript
]
windosu = require('windosu')
# Need to escape every path to avoid errors
resinWritePath = "\"#{path.join(__dirname, '..', '..', 'bin', 'resin-write')}\""
windosu.exec("\"#{process.argv[0]}\" #{resinWritePath} \"#{params.image}\" \"#{params.device}\"")