sort files and directories when reading CSV and use BFS
This commit is contained in:
+20
-9
@@ -474,7 +474,7 @@ static result_t readConfigFiles(const string path, const string extension, DataF
|
|||||||
return RESULT_ERR_NOTFOUND;
|
return RESULT_ERR_NOTFOUND;
|
||||||
|
|
||||||
dirent* d;
|
dirent* d;
|
||||||
|
vector<string> files, dirs;
|
||||||
while ((d = readdir(dir)) != NULL) {
|
while ((d = readdir(dir)) != NULL) {
|
||||||
string fn = d->d_name;
|
string fn = d->d_name;
|
||||||
|
|
||||||
@@ -488,21 +488,32 @@ static result_t readConfigFiles(const string path, const string extension, DataF
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (S_ISDIR(stat_buf.st_mode)) {
|
if (S_ISDIR(stat_buf.st_mode)) {
|
||||||
result_t result = readConfigFiles(p, extension, templates, messages, verbose);
|
dirs.push_back(p);
|
||||||
if (result != RESULT_OK)
|
} else if (S_ISREG(stat_buf.st_mode)) {
|
||||||
return result;
|
|
||||||
}
|
|
||||||
else if (S_ISREG(stat_buf.st_mode)) {
|
|
||||||
if (fn.find(extension, (fn.length() - extension.length())) != string::npos
|
if (fn.find(extension, (fn.length() - extension.length())) != string::npos
|
||||||
&& fn != "_templates" + extension) {
|
&& fn != "_templates" + extension) {
|
||||||
result_t result = messages->readFromFile(p, templates, verbose);
|
files.push_back(p);
|
||||||
if (result != RESULT_OK)
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
|
|
||||||
|
sort(files.begin(), files.end());
|
||||||
|
for (vector<string>::iterator it = files.begin(); it != files.end(); it++) {
|
||||||
|
string name = *it;
|
||||||
|
logInfo(lf_main, "reading file %s", name.c_str());
|
||||||
|
result_t result = messages->readFromFile(name, templates, verbose);
|
||||||
|
if (result != RESULT_OK)
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
sort(dirs.begin(), dirs.end());
|
||||||
|
for (vector<string>::iterator it = dirs.begin(); it != dirs.end(); it++) {
|
||||||
|
string name = *it;
|
||||||
|
logInfo(lf_main, "reading dir %s", name.c_str());
|
||||||
|
result_t result = readConfigFiles(name, extension, templates, messages, verbose);
|
||||||
|
if (result != RESULT_OK)
|
||||||
|
return result;
|
||||||
|
}
|
||||||
return RESULT_OK;
|
return RESULT_OK;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user