refactor(commander) readDir: params -> error, files, params

This commit is contained in:
coderaiser 2014-01-31 06:01:46 -05:00
parent aa60da9c57
commit 7aea0483a6

View file

@ -22,13 +22,15 @@
exports.getDirContent = function(path, callback) {
var ret = Util.isString(path);
if (ret)
fs.readdir(path, Util.call(readDir, {
callback: callback,
path : path
}));
else
if (!ret)
Util.exec(callback, "First parameter should be a string");
else
fs.readdir(path, function(error, files) {
readDir(error, files, {
callback : callback,
path : path
});
});
return ret;
};
@ -39,49 +41,43 @@
* @param pError
* @param pFiles
*/
function readDir(params) {
function readDir(error, files, params) {
var i, n, stats, filesData, fill, name, fileParams,
p, c, files, dirPath,
ret = checkParams(params);
ret = ret && Util.checkObj(params.params, ['path']);
p = params,
dirPath = getDirPath(p.path);
if (ret) {
p = params,
c = params.params,
files = p.data,
dirPath = getDirPath(c.path);
if (error)
Util.exec(p.callback, error.toString());
else {
/* Получаем информацию о файлах */
n = files.length,
stats = {},
if (!p.error && files) {
/* Получаем информацию о файлах */
n = files.length,
stats = {},
filesData = {
files : files,
stats : stats,
callback : c.callback,
path : c.path
},
fill = Util.retFunc(fillJSON, filesData);
if (n)
for (i = 0; i < n; i++) {
name = dirPath + files[i],
fileParams = {
callback : fill,
count : n,
name : files[i],
stats : stats,
};
fs.stat(name, Util.call(getFilesStat, fileParams));
}
else
fillJSON(filesData);
} else
Util.exec(c.callback, p.error.toString());
filesData = {
files : files,
stats : stats,
callback : p.callback,
path : p.path
},
fill = Util.retFunc(fillJSON, filesData);
if (n)
for (i = 0; i < n; i++) {
name = dirPath + files[i],
fileParams = {
callback : fill,
count : n,
name : files[i],
stats : stats,
};
fs.stat(name, Util.call(getFilesStat, fileParams));
}
else
fillJSON(filesData);
}
}