Commit 893466ec authored by Leo Iannacone's avatar Leo Iannacone

watch on filesystem changes

parent 9d2950d5
...@@ -8,6 +8,7 @@ var express = require('express') ...@@ -8,6 +8,7 @@ var express = require('express')
, config = require('./config.js') , config = require('./config.js')
, send = require('./send.js') , send = require('./send.js')
, fs = require('fs') , fs = require('fs')
, path = require('path')
var app = module.exports = express.createServer(); var app = module.exports = express.createServer();
...@@ -40,8 +41,47 @@ app.get('/', routes.index); ...@@ -40,8 +41,47 @@ app.get('/', routes.index);
io.sockets.on('connection', function(socket) { io.sockets.on('connection', function(socket) {
send.distributions(socket); send.distributions(socket);
socket.on('get-view', function(data) { socket.on('get-view', function(data) {
socket.get('view', function(err, view) {
if (!view || view != data) {
socket.get('watchers', function(err, watchers) {
if (watchers) watchers.forEach(function(w){
w.close()
});
watchers = []
socket.set('view', data, function() {
packages_path = path.join(config.debomatic_path, data.distribution.name, 'pool')
try {
watchIncomingPackages = fs.watch(packages_path, { persistent: true}, function(event, fileName) {
send.view(socket, data);
});
watchers.push(watchIncomingPackages);
} catch (err) {}
if (data.package && data.package.name && data.package.version) {
pack_path = path.join(packages_path, data.package.name + '_' + data.package.version);
try {
watchPackageFiles = fs.watch(pack_path, {persistent: true}, function (event, filename) {
send.view(socket, data); send.view(socket, data);
}); });
watchers.push(watchPackageFiles)
} catch (err) {}
}
socket.set('watchers', watchers);
});
});
send.view(socket, data);
};
});
});
});
io.sockets.on('disconnect', function(socket){
socket.get('watchers', function(err, watchers) {
if (watchers) watchers.forEach(function(w){
w.close()
});
socket.set('watchers', []);
});
}); });
fs.watch(config.debomatic_path, { persistent: true }, function (event, fileName) { fs.watch(config.debomatic_path, { persistent: true }, function (event, fileName) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment