Преглед на файлове

Batched elevated Tasks for Windows

production
pb преди 2 години
родител
ревизия
ee0e72d755
променени са 3 файла, в които са добавени 76 реда и са изтрити 33 реда
  1. 67
    31
      index.js
  2. 1
    1
      lin_verse.js
  3. 8
    1
      win_verse.js

+ 67
- 31
index.js Целия файл

@@ -358,10 +358,24 @@ var getPullCmd = (repo, branch) => {
}

// PB : TODO -- Use queueing with async tasks..
var performPull = (repodef, branch, repoowner, errHandler) => {
var performPull = (repodef, branch, repoowner, errHandler, elevatedBatch, regularBatch) => {
var __inelevatedBatch = elevatedBatch, __inregularBatch = regularBatch;
var pT = getPullTask(repodef, branch, repoowner, errHandler, elevatedBatch, regularBatch)
// var waitForBatchAdditions = function(){
// return pT;
// }
// Execute is implied.
// if(false && (__inelevatedBatch || __inregularBatch) ) return waitForBatchAdditions() // PB : Todo Implemnt a trigger which starts execution.
// else
return pT() // Execute it.
}

var getPullTask = (repodef, branch, repoowner, errHandler, elevatedBatch, regularBatch) => {
// PB : TODO -- Handle no branch passed in case.
// if(!branch) { throw 'No branch specified' }
var repo = repodef.repo;
elevatedBatch = elevatedBatch || [];
regularBatch = regularBatch || [];
try{
var exists = existsSync(instanceroot + '/' + repo)
}
@@ -370,6 +384,24 @@ var performPull = (repodef, branch, repoowner, errHandler) => {
console.log(e)
}

function initTask(etask){
etask.info = { repo }
etask.errHandler = errHandler
etask.statuslog = statuslog
etask.processedArgs = processedArgs
etask.selectedinstance = selectedinstance
etask.runtimestamp = runtimestamp
etask.ENV = ENV

elevatedBatch.info = { repo }
elevatedBatch.errHandler = errHandler
elevatedBatch.statuslog = statuslog
elevatedBatch.processedArgs = processedArgs
elevatedBatch.selectedinstance = selectedinstance
elevatedBatch.runtimestamp = runtimestamp
elevatedBatch.ENV = ENV
}

if (exists) {
var branchprint = branch ? ' branch :' + branch : '';
console.log('pulling ' + instanceroot + '/' + repo + branchprint )
@@ -378,20 +410,21 @@ var performPull = (repodef, branch, repoowner, errHandler) => {
return true;
})
}
initTask(task)

task.info = { repo }
task.errHandler = errHandler
task.statuslog = statuslog
task.processedArgs = processedArgs
task.selectedinstance = selectedinstance
task.runtimestamp = runtimestamp
task.ENV = ENV
if(repodef.requiresElevation) return shell_verse.runElevated( task )
else return shell_verse.runTask( task )
if(repodef.requiresElevation) {
elevatedBatch.push(shell_verse.getElevatedTask( task ));
return elevatedBatch[elevatedBatch.length-1]
}
else {
regularBatch.push(shell_verse.getNonElevatedTask( task ))
return regularBatch[regularBatch.length-1]
}
}
else {
console.log('cloning ' + repo)
// PB : TODO -- detect if a clonable repo exists in currentGitAuthUser
var task = ()=>{
return nodeShellExec('git', ['clone', '-c', 'core.symlinks=true', selectedinstance.reposerver + `/${repoowner || defaultRepoOwner}/` + repo + '.git'],
{
@@ -411,27 +444,29 @@ var performPull = (repodef, branch, repoowner, errHandler) => {
, title: `'git', ${['config', '--replace-all', 'core.symlinks', selectedinstance.username].join(' ')}`
})
}
task.info = { repo }
task.errHandler = errHandler
task.statuslog = statuslog
task.processedArgs = processedArgs
task.selectedinstance = selectedinstance
task.runtimestamp = runtimestamp
task.ENV = ENV
if(repodef.requiresElevation) return shell_verse.runElevated( task )
else return shell_verse.runTask( task )

initTask(task)

if(repodef.requiresElevation) {
elevatedBatch.push(shell_verse.getElevatedTask( task ));
return elevatedBatch[elevatedBatch.length-1]
}
else {
regularBatch.push(shell_verse.getNonElevatedTask( task ))
return regularBatch[regularBatch.length-1]
}
})
}
initTask(task)
if(repodef.requiresElevation) {
elevatedBatch.push(shell_verse.getElevatedTask( task ));
return elevatedBatch[elevatedBatch.length-1]
}
else {
regularBatch.push(shell_verse.getNonElevatedTask( task ))
return regularBatch[regularBatch.length-1]
}
task.info = { repo }
task.errHandler = errHandler
task.statuslog = statuslog
task.processedArgs = processedArgs
task.selectedinstance = selectedinstance
task.runtimestamp = runtimestamp
task.ENV = ENV
if(repodef.requiresElevation) return shell_verse.runElevated( task )
else return shell_verse.runTask( task )
}
}

@@ -2287,7 +2322,6 @@ var elxr = {
if(def.repo) {
// Single repo case.
if(def.repo.requiresElevation) {
getElevatedTask
var t1 = function() {
return performPull(def).then(() => {
return true;
@@ -2337,7 +2371,9 @@ var elxr = {
if(def.elevated){
elevatedpulltasks = function() {
// shell_verse.getElevatedTask( t1 )
return any(def.elevated.map((def) => performPull(def))).then(() => {
var eBatch = []
def.elevated.map((def) => getPullTask(def, null, null, null, eBatch))
return shell_verse.runElevated(eBatch).then(() => {
return true;
}).catch((e) => {
console.error(e)

+ 1
- 1
lin_verse.js Целия файл

@@ -35,7 +35,7 @@ var shell_verse = {
// getCommonTask is agnostic of whether we are running in an elevated shell or not. It runs in either case.
getCommonTask( taskToRun ){ return ()=>{ return shell_verse.runTask(taskToRun) }}
, runTask : ( taskToRun ) => {
if (__isElevated) return shell_verse.elevatedRunner()
if (__isElevated) return shell_verse.runElevated( taskToRun )
else return shell_verse.runNonElevated( taskToRun )
}


+ 8
- 1
win_verse.js Целия файл

@@ -8,7 +8,7 @@ var shell_verse = {
// getCommonTask is agnostic of whether we are running in an elevated shell or not. It runs in either case.
getCommonTask( taskToRun ){ return ()=>{ return shell_verse.runTask(taskToRun) }}
, runTask : ( taskToRun ) => {
if (__isElevated) return shell_verse.elevatedRunner()
if (__isElevated) return shell_verse.elevatedRunner( taskToRun )
else return shell_verse.runNonElevated( taskToRun )
}

@@ -57,6 +57,11 @@ var shell_verse = {
return shell_verse.requestElevation(shell_verse.elevatedRunner, taskToRun)
}
}
, runElevatedBatch( batchToRun ){
// 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.
return runElevated(batchToRun[0])
}

, getNonElevatedTask : function( taskToRun ){ return ()=>{ return shell_verse.runNonElevated(taskToRun) } }
, runNonElevated : ( taskToRun ) => {
@@ -124,6 +129,8 @@ var shell_verse = {
}

, requestElevation(elevatedRunner, taskToRun) {
// PB : TODO -- Multiple parallel request elevations should be queued into a promise.

var processedArgs = taskToRun.processedArgs, selectedinstance = taskToRun.selectedinstance , statuslog = taskToRun.statuslog
// Wait for the runas to complete before we read it.
try {

Loading…
Отказ
Запис