@@ -104,13 +104,16 @@ http.createServer(function(request, response) {
104
104
} ;
105
105
106
106
if ( cfg . user ) {
107
+ //id -u {cfg.user}
107
108
spawn_options . uid = cfg . user ;
108
109
}
109
110
110
- if ( ! fs . readdirSync ( cfg . path ) ) {
111
+ try {
112
+ fs . readdirSync ( cfg . path ) ;
113
+ spawn_options . cwd = cfg . path ;
114
+ } catch ( e ) {
111
115
return log ( 'Invalid path "' + cfg . path + '" in config "' + request . url + '"' , request . url + '.error' ) ;
112
116
}
113
- spawn_options . cwd = cfg . path ;
114
117
115
118
if ( cfg . refs ) {
116
119
var refsType = typeof cfg . refs ;
@@ -127,23 +130,21 @@ http.createServer(function(request, response) {
127
130
if ( cfg . commands . length ) {
128
131
var currentCommands = JSON . parse ( JSON . stringify ( cfg . commands ) ) ;
129
132
130
- var processCommand = function ( cmd ) {
133
+ var spawnCommand = function ( cmd ) {
131
134
var commandString = cmd . join ( ' ' ) ;
132
135
var result = child_process . spawn ( cmd . shift ( ) , cmd , spawn_options ) ;
133
136
134
- result . stdout . on ( 'data' , resultCallback ( commandString , 'Data from "{command}": {data}' , request . url + '.info' ) ) ;
135
- result . stderr . on ( 'data' , resultCallback ( commandString , 'Error in "{command}": {data}' , request . url + '.error' ) ) ;
136
- result . on ( 'exit' , ( function ( cmd_string ) {
137
- return function ( code , signal ) {
137
+ result . stdout . on ( 'data' , stdioCallback ( commandString , 'Data from "{command}": {data}' , request . url + '.info' ) ) ;
138
+ result . stderr . on ( 'data' , stdioCallback ( commandString , 'Error in "{command}": {data}' , request . url + '.error' ) ) ;
139
+ result . on ( 'exit' , function ( code , signal ) {
138
140
var next = currentCommands . shift ( ) ;
139
141
if ( next ) {
140
- processCommand ( next ) ;
142
+ spawnCommand ( next ) ;
141
143
}
142
- } ;
143
- } ) ( commandString ) ) ;
144
+ } ) ;
144
145
} ;
145
146
146
- var resultCallback = function ( cmd_string , format , file ) {
147
+ var stdioCallback = function ( cmd_string , format , file ) {
147
148
return function ( data ) {
148
149
log ( format . fmt ( {
149
150
command : cmd_string ,
@@ -152,7 +153,7 @@ http.createServer(function(request, response) {
152
153
} ;
153
154
} ;
154
155
155
- processCommand ( currentCommands . shift ( ) ) ;
156
+ spawnCommand ( currentCommands . shift ( ) ) ;
156
157
} else {
157
158
return log ( 'No commands to execute.' , request . url + '.info' ) ;
158
159
}
0 commit comments