Commit f6f16d2f authored by Leo Iannacone's avatar Leo Iannacone

moved get_files_list to utils

parent 33d2dda1
......@@ -4,35 +4,9 @@ var fs = require('fs')
, config = require('./config.js')
, utils = require('./utils.js')
function __get_files_list(dir, onlyDirectories, callback) {
fs.readdir(dir, function(err, files){
result = [];
if (err) {
console.error(err);
return;
}
files.forEach( function(f) {
try {
complete_path = path.join(dir, f);
if (onlyDirectories) {
if (fs.statSync(complete_path).isDirectory()) {
result.push(f);
}
}
else {
if (fs.statSync(complete_path).isFile()) {
result.push(f);
}
}
} catch (fs_error) {}
});
callback(result);
});
}
function __get_files_list_from_package(data, callback) {
package_path = utils.get_package_path(data)
__get_files_list(package_path, false, function(files) {
utils.get_files_list(package_path, false, function(files) {
data.package.files = []
data.package.debs = []
data.package.archives = []
......@@ -68,7 +42,7 @@ function __send_package_files_list (event_name, socket, data) {
function __send_distribution_packages (event_name, socket, data) {
distro_path = utils.get_distribution_pool_path(data)
__get_files_list(distro_path, true, function (packages) {
utils.get_files_list(distro_path, true, function (packages) {
data.distribution.packages = []
packages.forEach( function (p) {
pack = {}
......@@ -99,7 +73,7 @@ function __send_file (event_name, socket, data) {
}
function __send_distributions(event_name, socket, data) {
__get_files_list(config.debomatic.path, true, function(distros){
utils.get_files_list(config.debomatic.path, true, function(distros){
socket.emit(event_name, distros);
});
}
......@@ -137,8 +111,6 @@ function __watch_path_onsocket(event_name, socket, data, watch_path, updater) {
})
}
function __generic_handler(event_name, socket, data, watch_path, callback) {
__watch_path_onsocket(event_name, socket, data, config.debomatic.path, callback)
callback(event_name, socket, data)
......
var path = require('path')
, fs = require('fs')
, config = require('./config.js')
function __check_data_distribution(data) {
......@@ -25,6 +26,32 @@ function __get_file_path(data) {
return path.join(__get_package_path(data), data.package.name + '_' + data.package.version + '.' + data.file.name)
}
function __get_files_list(dir, onlyDirectories, callback) {
fs.readdir(dir, function(err, files){
result = [];
if (err) {
console.error(err);
return;
}
files.forEach( function(f) {
try {
complete_path = path.join(dir, f);
if (onlyDirectories) {
if (fs.statSync(complete_path).isDirectory()) {
result.push(f);
}
}
else {
if (fs.statSync(complete_path).isFile()) {
result.push(f);
}
}
} catch (fs_error) {}
});
callback(result);
});
}
utils = {
check_data_distribution: function(data) {
return __check_data_distribution(data)
......@@ -44,6 +71,9 @@ utils = {
get_file_path: function(data) {
return __get_file_path(data)
},
get_files_list: function(dir, onlyDirectories, callback) {
return __get_files_list(dir, onlyDirectories, callback)
}
}
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