function registerVfs() { // var vfs = require('vfs-local')({root: process.env.HOME + "/"}); var Parent = require('vfs-child').Parent; var httpTransport = require('vfs-http-transport/server'); var child = new Parent({root: process.env.HOME + "/"}); console.log("Spawning vfs instance in child process"); child.connect(function (err, vfs) { if (err) throw err; console.log("vfs-child instance initialized"); // Serve the vfs-child instance over REST for easy testing. routes.push(httpAdapter("/child/", vfs)); console.log("child vfs at http://localhost:8080/child/"); // Serve the vfs over the http transport. We have to pass in the http server // instance to give socket.io access to the "upgrade" event on it. console.log("creating http-transport instance"); httpTransport(vfs, server, "/home/"); console.log("http transport listening at ws://localhost:8080/home/"); startClient(); }); }
function connect(user, pid, callback) { var projectOptions = api.getVfsOptions ? api.getVfsOptions(user, pid) : { workspaceDir: options.workspaceDir, extendOptions: options.extendOptions }; var vfsOptions = { root: "/", metapath: "/.c9/metadata", wsmetapath: "/.c9/metadata/workspace", local: false, readOnly: false, debug: options.debug, homeDir: process.env.HOME, projectDir: projectOptions.workspaceDir, nakBin: options.nakBin || (process.env.HOME + "/.c9/node_modules/.bin/nak"), nodeBin: options.nodeBin, tmuxBin: options.tmuxBin }; for (var key in options.vfs) vfsOptions[key] = options.vfs[key]; vfsOptions.readOnly = options.readonly; var master = new Parent(vfsOptions); master.connect(function(err, vfs) { if (err) return callback(err); callback(null, new Vfs(vfs, master, { debug: options.debug || false, homeDir: vfsOptions.homeDir, projectDir: vfsOptions.projectDir, extendDirectory: options.extendDirectory, extendOptions: projectOptions.extendOptions, extendToken: "token", collab: options.collab, vfsOptions: vfsOptions, readonly: options.readonly, public: true })); }); return function cancel() {}; }
setTimeout(function () { parent.connect(); }, 500);
var Parent = require('vfs-child').Parent; var parent = new Parent({root: __dirname + "/"}); parent.connect(); parent.once("connect", function (vfs) { require('http').createServer(require('stack')( require('vfs-http-adapter')("/child/", vfs) )).listen(8080, function () { console.log("child filesystem listening at http://localhost:8080/child/"); }); }); parent.on("connect", function () { console.log("Child spawned and connected"); }); parent.on("disconnect", function () { console.log("Child died, spawning new child in 500ms"); setTimeout(function () { parent.connect(); }, 500); });
// var vfs = require('vfs-local')({ // root: __dirname + "/" // }); // watch(vfs); // changed(vfs); var Parent = require('vfs-child').Parent; var parent = new Parent({root: __dirname + "/"}); parent.connect(function (err, vfs) { if (err) throw err; watch(vfs); // changed(vfs); }); function watch(vfs) { // vfs.watch(".", {}, onWatch); vfs.watch("vfs-watch-example.js", {file:true}, onWatch); function onWatch(err, meta) { if (err) throw err; var watcher = meta.watcher; watcher.on("change", function (event, filename) { console.log("change", event, filename); }); setTimeout(function () { console.log("Closing..."); watcher.close() }, 10000); } }