forked from svrjs/svrjs
Optimize portions from directory listing function
This commit is contained in:
parent
d789fea921
commit
3a4cefa67a
1 changed files with 9 additions and 23 deletions
32
svr.js
32
svr.js
|
@ -3860,28 +3860,15 @@ if (!cluster.isPrimary) {
|
||||||
fs.stat((prefix + "/" + fileList[index]).replace(/\/+/g, "/"), function (err, stats) {
|
fs.stat((prefix + "/" + fileList[index]).replace(/\/+/g, "/"), function (err, stats) {
|
||||||
if (err) {
|
if (err) {
|
||||||
fs.lstat((prefix + "/" + fileList[index]).replace(/\/+/g, "/"), function (err, stats) {
|
fs.lstat((prefix + "/" + fileList[index]).replace(/\/+/g, "/"), function (err, stats) {
|
||||||
if (err) {
|
pushArray.push({
|
||||||
pushArray.push({
|
name: fileList[index],
|
||||||
name: fileList[index],
|
stats: err ? null : stats,
|
||||||
stats: null,
|
errored: true
|
||||||
errored: true
|
});
|
||||||
});
|
if (index < fileList.length - 1) {
|
||||||
if (index < fileList.length - 1) {
|
getStatsForAllFilesI(fileList, callback, prefix, pushArray, index + 1);
|
||||||
getStatsForAllFilesI(fileList, callback, prefix, pushArray, index + 1);
|
|
||||||
} else {
|
|
||||||
callback(pushArray);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
pushArray.push({
|
callback(pushArray);
|
||||||
name: fileList[index],
|
|
||||||
stats: stats,
|
|
||||||
errored: true
|
|
||||||
});
|
|
||||||
if (index < fileList.length - 1) {
|
|
||||||
getStatsForAllFilesI(fileList, callback, prefix, pushArray, index + 1);
|
|
||||||
} else {
|
|
||||||
callback(pushArray);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
@ -3913,8 +3900,7 @@ if (!cluster.isPrimary) {
|
||||||
var estats = filelist[i].stats;
|
var estats = filelist[i].stats;
|
||||||
var ename = filelist[i].name;
|
var ename = filelist[i].name;
|
||||||
var eext = ename.match(/\.([^.]+)$/);
|
var eext = ename.match(/\.([^.]+)$/);
|
||||||
if (eext) eext = eext[1];
|
eext = eext ? eext[1] : "";
|
||||||
else eext = "";
|
|
||||||
var emime = eext ? mime.contentType(eext) : false;
|
var emime = eext ? mime.contentType(eext) : false;
|
||||||
if (filelist[i].errored) {
|
if (filelist[i].errored) {
|
||||||
directoryListingRows.push(
|
directoryListingRows.push(
|
||||||
|
|
Reference in a new issue