Run command idempotently when hostname cannot be resolved

This commit is contained in:
Joran Dirk Greef 2018-09-11 15:20:05 +02:00
parent ad291f7bd0
commit 8c1a3022f3

View file

@ -10,33 +10,10 @@ var Node = {
function Attempt(instance, end) { function Attempt(instance, end) {
var platform = Node.process.platform; var platform = Node.process.platform;
if (platform === 'darwin') return Mac(instance, end);
if (platform === 'linux') return Linux(instance, end);
if (platform === 'win32') return Windows(instance, end); if (platform === 'win32') return Windows(instance, end);
// The -n (non-interactive) option prevents sudo from prompting the user for
// a password. If a password is required, sudo will return an error and exit.
var command = [];
command.push('/usr/bin/sudo');
command.push('-n');
// Preserve user environment:
command.push('-E');
// Stop parsing command options:
command.push('--');
command.push(instance.command);
command = command.join(' ');
Node.child.exec(command, { maxBuffer: MAX_BUFFER },
function(error, stdout, stderr) {
if (/sudo: /i.test(stderr)) {
if (platform === 'linux') {
return Linux(instance, end);
} else if (platform === 'darwin') {
return Mac(instance, end);
} else {
end(new Error('Platform not yet supported.')); end(new Error('Platform not yet supported.'));
}
} else {
end(error, stdout, stderr);
}
}
);
} }
function EscapeDoubleQuotes(string) { function EscapeDoubleQuotes(string) {