mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-25 15:56:15 +02:00
Removed special case handling for !(showDirectories || showFiles)
The special case is not necessary for correctness. It would help performance in theory, but it seems very unlikely that any code would request a directory scan when it interested in neither the subdirs nor the files in that directory.
This commit is contained in:
parent
46c64ea984
commit
2c76ddae50
@ -83,83 +83,81 @@ void FileLister::browse(const string& path, bool clean)
|
|||||||
directories.clear();
|
directories.clear();
|
||||||
files.clear();
|
files.clear();
|
||||||
|
|
||||||
if (showDirectories || showFiles) {
|
DIR *dirp;
|
||||||
DIR *dirp;
|
string slashedPath = path;
|
||||||
string slashedPath = path;
|
if (path[path.length() - 1] != '/')
|
||||||
if (path[path.length() - 1] != '/')
|
slashedPath.push_back('/');
|
||||||
slashedPath.push_back('/');
|
|
||||||
|
|
||||||
if ((dirp = opendir(slashedPath.c_str())) == NULL) {
|
if ((dirp = opendir(slashedPath.c_str())) == NULL) {
|
||||||
ERROR("Unable to open directory: %s\n", slashedPath.c_str());
|
ERROR("Unable to open directory: %s\n", slashedPath.c_str());
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string filepath, file;
|
||||||
|
struct stat st;
|
||||||
|
struct dirent *dptr;
|
||||||
|
|
||||||
|
while ((dptr = readdir(dirp))) {
|
||||||
|
file = dptr->d_name;
|
||||||
|
|
||||||
|
if (file[0] == '.' && file != "..")
|
||||||
|
continue;
|
||||||
|
|
||||||
|
filepath = slashedPath + file;
|
||||||
|
int statRet = stat(filepath.c_str(), &st);
|
||||||
|
if (statRet == -1) {
|
||||||
|
ERROR("Stat failed on '%s' with error '%s'\n", filepath.c_str(), strerror(errno));
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
if (find(excludes.begin(), excludes.end(), file) != excludes.end())
|
||||||
|
continue;
|
||||||
|
|
||||||
string filepath, file;
|
if (S_ISDIR(st.st_mode)) {
|
||||||
struct stat st;
|
if (!showDirectories)
|
||||||
struct dirent *dptr;
|
|
||||||
|
|
||||||
while ((dptr = readdir(dirp))) {
|
|
||||||
file = dptr->d_name;
|
|
||||||
|
|
||||||
if (file[0] == '.' && file != "..")
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
filepath = slashedPath + file;
|
directorySet.insert(file);
|
||||||
int statRet = stat(filepath.c_str(), &st);
|
} else {
|
||||||
if (statRet == -1) {
|
if (!showFiles)
|
||||||
ERROR("Stat failed on '%s' with error '%s'\n", filepath.c_str(), strerror(errno));
|
continue;
|
||||||
|
|
||||||
|
if (filter.empty()) {
|
||||||
|
fileSet.insert(file);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (find(excludes.begin(), excludes.end(), file) != excludes.end())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (S_ISDIR(st.st_mode)) {
|
for (vector<string>::iterator it = filter.begin(); it != filter.end(); ++it) {
|
||||||
if (!showDirectories)
|
if (file.find('.') == string::npos) {
|
||||||
continue;
|
if (!it->empty())
|
||||||
|
continue;
|
||||||
|
|
||||||
directorySet.insert(file);
|
|
||||||
} else {
|
|
||||||
if (!showFiles)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (filter.empty()) {
|
|
||||||
fileSet.insert(file);
|
fileSet.insert(file);
|
||||||
continue;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (vector<string>::iterator it = filter.begin(); it != filter.end(); ++it) {
|
if (it->length() < file.length()) {
|
||||||
if (file.find('.') == string::npos) {
|
if (file[file.length() - it->length() - 1] != '.')
|
||||||
if (!it->empty())
|
continue;
|
||||||
continue;
|
|
||||||
|
|
||||||
|
string file_lowercase =
|
||||||
|
file.substr(file.length() - it->length());
|
||||||
|
|
||||||
|
/* XXX: This won't accept UTF-8 codes.
|
||||||
|
* Thanksfully file extensions shouldn't contain any. */
|
||||||
|
transform(file_lowercase.begin(), file_lowercase.end(),
|
||||||
|
file_lowercase.begin(), ::tolower);
|
||||||
|
|
||||||
|
if (file_lowercase.compare(0, it->length(), *it) == 0) {
|
||||||
fileSet.insert(file);
|
fileSet.insert(file);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (it->length() < file.length()) {
|
|
||||||
if (file[file.length() - it->length() - 1] != '.')
|
|
||||||
continue;
|
|
||||||
|
|
||||||
string file_lowercase =
|
|
||||||
file.substr(file.length() - it->length());
|
|
||||||
|
|
||||||
/* XXX: This won't accept UTF-8 codes.
|
|
||||||
* Thanksfully file extensions shouldn't contain any. */
|
|
||||||
transform(file_lowercase.begin(), file_lowercase.end(),
|
|
||||||
file_lowercase.begin(), ::tolower);
|
|
||||||
|
|
||||||
if (file_lowercase.compare(0, it->length(), *it) == 0) {
|
|
||||||
fileSet.insert(file);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir(dirp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
closedir(dirp);
|
||||||
|
|
||||||
moveNames(move(directorySet), directories);
|
moveNames(move(directorySet), directories);
|
||||||
moveNames(move(fileSet), files);
|
moveNames(move(fileSet), files);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user