kopia lustrzana https://github.com/c9/core
Merge pull request +10237 from c9/fix-vfs
Fix VFS not always connecting (particularly in dogfooding standalone)pull/223/head
commit
dd33232a0a
|
@ -1,6 +1,7 @@
|
|||
var Consumer = require('vfs-socket/consumer').Consumer;
|
||||
var inherits = require('util').inherits;
|
||||
var spawn = require('child_process').spawn;
|
||||
var fs = require("fs");
|
||||
|
||||
exports.Parent = Parent;
|
||||
|
||||
|
@ -23,30 +24,36 @@ function Parent(fsOptions) {
|
|||
// Override Consumer's connect since the transport logic is internal to this module
|
||||
this.connect = connect.bind(this);
|
||||
function connect(callback) {
|
||||
var _self = this;
|
||||
try {
|
||||
if (!fs.existsSync(nodeBin[0]))
|
||||
return tryNext(new Error("Couldn't find valid node binary"));
|
||||
child = spawn(nodeBin[0], args, options).on("error", tryNext);
|
||||
}
|
||||
catch (e) {
|
||||
return tryNext(e);
|
||||
return done(e);
|
||||
}
|
||||
child.stdin.readable = true;
|
||||
Consumer.prototype.connect.call(this, [child.stdout, child.stdin], tryNext);
|
||||
Consumer.prototype.connect.call(this, [child.stdout, child.stdin], done);
|
||||
child.on("exit", disconnect);
|
||||
child.stdin.resume();
|
||||
var _self = this;
|
||||
// try all possible locations of node before giving up
|
||||
function tryNext(err, vfs) {
|
||||
if (!child) return;
|
||||
child.removeListener("error", tryNext);
|
||||
child.on("error", function ignore() {});
|
||||
if (err && err.code == "ENOENT" && nodeBin.length > 1) {
|
||||
child = null;
|
||||
|
||||
function tryNext(err) {
|
||||
if (nodeBin.length > 1) {
|
||||
nodeBin.shift();
|
||||
_self.emit("error", err);
|
||||
_self.connect(callback);
|
||||
} else {
|
||||
callback(err, vfs);
|
||||
}
|
||||
} else {
|
||||
return done(err);
|
||||
}
|
||||
}
|
||||
|
||||
function done(err, vfs) {
|
||||
if (!callback) return;
|
||||
child.removeListener("error", done);
|
||||
child.on("error", function ignore(err) {});
|
||||
callback(err, vfs);
|
||||
callback = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue