Commit 9917f213 authored by Leo Iannacone's avatar Leo Iannacone

moved send_distributions to utils and watch for changes again in index

parent 1cb0763d
...@@ -47,6 +47,11 @@ io.sockets.on('disconnect', function(socket){ ...@@ -47,6 +47,11 @@ io.sockets.on('disconnect', function(socket){
}); });
// watch for new distributions
fs.watch(config.debomatic.path, { persistent: true }, function (event, fileName) {
utils.send_distributions(io.sockets);
});
var server = app.listen(config.port, function(){ var server = app.listen(config.port, function(){
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env); console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
}); });
...@@ -71,11 +71,7 @@ function __send_file (event_name, socket, data) { ...@@ -71,11 +71,7 @@ function __send_file (event_name, socket, data) {
}); });
} }
function __send_distributions(event_name, socket, data) {
utils.get_files_list(config.debomatic.path, true, function(distros){
socket.emit(event_name, distros);
});
}
function __handler_get_file (socket, data) { function __handler_get_file (socket, data) {
file_path = utils.get_file_path(data) file_path = utils.get_file_path(data)
...@@ -92,8 +88,8 @@ function __handler_file_newcontent(event_name, socket, data) { ...@@ -92,8 +88,8 @@ function __handler_file_newcontent(event_name, socket, data) {
Client = function (socket) { Client = function (socket) {
utils.generic_handler_watcher('distributions', socket, null, config.debomatic.path, __send_distributions) utils.send_distributions(socket)
socket.on('get_distribution_packages', function (data) { socket.on('get_distribution_packages', function (data) {
if (! utils.check_data_distribution(data)) if (! utils.check_data_distribution(data))
return return
......
...@@ -91,6 +91,12 @@ function __generic_handler_watcher(event_name, socket, data, watch_path, callbac ...@@ -91,6 +91,12 @@ function __generic_handler_watcher(event_name, socket, data, watch_path, callbac
callback(event_name, socket, data) callback(event_name, socket, data)
} }
function __send_distributions(event_name, socket) {
__get_files_list(config.debomatic.path, true, function(distros){
socket.emit(event_name, distros);
});
}
utils = { utils = {
check_data_distribution: function(data) { check_data_distribution: function(data) {
return __check_data_distribution(data) return __check_data_distribution(data)
...@@ -118,8 +124,12 @@ utils = { ...@@ -118,8 +124,12 @@ utils = {
}, },
generic_handler_watcher: function(event_name, socket, data, watch_path, callback) { generic_handler_watcher: function(event_name, socket, data, watch_path, callback) {
return __generic_handler_watcher(event_name, socket, data, watch_path, callback); return __generic_handler_watcher(event_name, socket, data, watch_path, callback);
},
send_distributions: function (socket, event_name) {
if (! event_name)
event_name = 'distributions'
return __send_distributions(event_name, socket);
} }
} }
module.exports = utils module.exports = utils
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