|
|
|
|
|
|
|
|
else return shell_verse.runNonElevated( taskToRun ) |
|
|
else return shell_verse.runNonElevated( taskToRun ) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
, elevatedRunner( taskToRun ){ |
|
|
|
|
|
|
|
|
, elevatedRunner( taskToRun, inBatch ){ |
|
|
// PB : TODO -- Should be called only when we are in an elevated shell that was already requested from an unelevated shell with a batch of tasks. |
|
|
// PB : TODO -- Should be called only when we are in an elevated shell that was already requested from an unelevated shell with a batch of tasks. |
|
|
try { |
|
|
try { |
|
|
var __runasresult = null; |
|
|
var __runasresult = null; |
|
|
return taskToRun().then((r)=>{ |
|
|
return taskToRun().then((r)=>{ |
|
|
// PB : TODO -- Every elevation should have its own messaging file. Async writes from multiple processes are a problem here... |
|
|
// PB : TODO -- Every elevation should have its own messaging file. Async writes from multiple processes are a problem here... |
|
|
fs.writeFileSync('run.log', ', ' + JSON.stringify( { info : taskToRun.info, success: true }), { 'flag': 'a+' }) |
|
|
fs.writeFileSync('run.log', ', ' + JSON.stringify( { info : taskToRun.info, success: true }), { 'flag': 'a+' }) |
|
|
fs.writeFileSync('run.done', 'success') // PB : TODO -- This should be done conditionally if we are running inproc. |
|
|
|
|
|
|
|
|
if(!inBatch) fs.writeFileSync('run.done', 'success') // PB : TODO -- This should be done conditionally if we are running inproc. |
|
|
return __runasresult = r; |
|
|
return __runasresult = r; |
|
|
}) |
|
|
}) |
|
|
.catch((e) => { |
|
|
.catch((e) => { |
|
|
fs.writeFileSync('run.log', ', ' + JSON.stringify(e), { 'flag': 'a+' }) |
|
|
fs.writeFileSync('run.log', ', ' + JSON.stringify(e), { 'flag': 'a+' }) |
|
|
fs.writeFileSync('run.done', 'failure') |
|
|
|
|
|
|
|
|
if(!inBatch)fs.writeFileSync('run.done', 'failure') |
|
|
console.error(e) |
|
|
console.error(e) |
|
|
}) |
|
|
}) |
|
|
.finally(() => { |
|
|
.finally(() => { |
|
|
if(__runasresult && !__runasresult.skipped) fs.unlinkSync('run.done') |
|
|
|
|
|
|
|
|
// if(__runasresult && !__runasresult.skipped) fs.unlinkSync('run.done') |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
catch (e) { |
|
|
catch (e) { |
|
|
console.error('Error Invalid command : ' + e) |
|
|
console.error('Error Invalid command : ' + e) |
|
|
fs.writeFileSync('run.done', 'error') |
|
|
|
|
|
|
|
|
if(!inBatch) fs.writeFileSync('run.done', 'error') |
|
|
} |
|
|
} |
|
|
finally { |
|
|
finally { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
, getElevatedTask : function( taskToRun ){ return ()=>{ return shell_verse.runElevated(taskToRun) }} |
|
|
, getElevatedTask : function( taskToRun ){ return ()=>{ return shell_verse.runElevated(taskToRun) }} |
|
|
|
|
|
, getElevatedTaskInBatch : function( taskToRun ){ return ()=>{ return shell_verse.runElevatedInBatch(taskToRun) }} |
|
|
|
|
|
, runElevatedInBatch : ( taskToRun ) => { |
|
|
|
|
|
if (__isElevated) return shell_verse.elevatedRunner(taskToRun, true) |
|
|
|
|
|
else return shell_verse.requestElevation(shell_verse.elevatedRunner, taskToRun) |
|
|
|
|
|
} |
|
|
, runElevated : ( taskToRun ) => { |
|
|
, runElevated : ( taskToRun ) => { |
|
|
// Let shell_verse decide whether to Elevate Out of Proc or In Proc |
|
|
// Let shell_verse decide whether to Elevate Out of Proc or In Proc |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// In windows we don't need to run each task. We hand over to another shell which in elevated state rebuilds the whole batch and runs. |
|
|
// In windows we don't need to run each task. We hand over to another shell which in elevated state rebuilds the whole batch and runs. |
|
|
// Irrespective of the batch we just call runElevated once. |
|
|
// Irrespective of the batch we just call runElevated once. |
|
|
if (__isElevated) { |
|
|
if (__isElevated) { |
|
|
return any(batchToRun); |
|
|
|
|
|
|
|
|
return any(batchToRun).then((r)=>{ |
|
|
|
|
|
// PB : TODO -- Every elevation should have its own messaging file. Async writes from multiple processes are a problem here... |
|
|
|
|
|
// fs.writeFileSync('run.log', ', ' + JSON.stringify( { info : taskToRun.info, success: true }), { 'flag': 'a+' }) |
|
|
|
|
|
fs.writeFileSync('run.done', 'success') // PB : TODO -- This should be done conditionally if we are running inproc. |
|
|
|
|
|
return __runasresult = r; |
|
|
|
|
|
}) |
|
|
|
|
|
.catch((e) => { |
|
|
|
|
|
// fs.writeFileSync('run.log', ', ' + JSON.stringify(e), { 'flag': 'a+' }) |
|
|
|
|
|
fs.writeFileSync('run.done', 'failure') |
|
|
|
|
|
console.error(e) |
|
|
|
|
|
}) |
|
|
|
|
|
// .finally(() => { |
|
|
|
|
|
// if(__runasresult && !__runasresult.skipped) fs.unlinkSync('run.done') |
|
|
|
|
|
// }); |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
return this.runElevated(batchToRun[0]) |
|
|
return this.runElevated(batchToRun[0]) |