mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-21 02:29:23 +00:00
refactor(commander) readDir -> getAllStats
This commit is contained in:
parent
0b1f69ba89
commit
bfff1224e0
1 changed files with 23 additions and 29 deletions
|
|
@ -24,42 +24,36 @@
|
|||
exports.getDirContent = function(path, callback) {
|
||||
Util.checkArgs(arguments, ['path', 'callback']);
|
||||
|
||||
fs.readdir(path, readDir.bind(null, {
|
||||
callback : callback,
|
||||
path : path
|
||||
}));
|
||||
fs.readdir(path, function(error, names) {
|
||||
if (error)
|
||||
callback(error);
|
||||
else
|
||||
getAllStats(path, names, callback);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Функция читает ссылку или выводит информацию об ошибке
|
||||
* @param pError
|
||||
* @param pFiles
|
||||
* @param path
|
||||
* @param names
|
||||
*/
|
||||
function readDir(params, error, names) {
|
||||
var length = names.length,
|
||||
funcs = {},
|
||||
p = params,
|
||||
dirPath = format.addSlashToEnd(p.path);
|
||||
function getAllStats(path, names, callback) {
|
||||
var length = names.length,
|
||||
funcs = {},
|
||||
dir = format.addSlashToEnd(path);
|
||||
|
||||
if (error) {
|
||||
p.callback(error);
|
||||
} else {
|
||||
|
||||
if (!length)
|
||||
funcs.exec = Util.exec.ret;
|
||||
else
|
||||
names.forEach(function(name) {
|
||||
var path = dirPath + name;
|
||||
|
||||
funcs[name] = Util.exec.with(getStat, name, path);
|
||||
});
|
||||
|
||||
Util.exec.parallel(funcs, function(error, files) {
|
||||
fillJSON(dirPath, files || {}, p.callback);
|
||||
if (!length)
|
||||
funcs.exec = Util.exec.ret;
|
||||
else
|
||||
names.forEach(function(name) {
|
||||
var path = dir + name;
|
||||
|
||||
funcs[name] = Util.exec.with(getStat, name, path);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
Util.exec.parallel(funcs, function(error, files) {
|
||||
fillJSON(dir, files || {}, callback);
|
||||
});
|
||||
}
|
||||
|
||||
function getStat(name, path, callback) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue