mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-29 16:54:04 +02:00
menu.cpp: Don't use stat() to know if a FS entry is a directory
The pointer returned by readdir() already informs us of the type of the FS entry.
This commit is contained in:
parent
16d66d0dbc
commit
4070644cc6
26
src/menu.cpp
26
src/menu.cpp
@ -61,25 +61,21 @@ uint Menu::firstDispRow() {
|
|||||||
void Menu::readSections(std::string parentDir)
|
void Menu::readSections(std::string parentDir)
|
||||||
{
|
{
|
||||||
DIR *dirp;
|
DIR *dirp;
|
||||||
struct stat st;
|
|
||||||
struct dirent *dptr;
|
struct dirent *dptr;
|
||||||
|
|
||||||
dirp = opendir(parentDir.c_str());
|
dirp = opendir(parentDir.c_str());
|
||||||
if (!dirp) return;
|
if (!dirp) return;
|
||||||
|
|
||||||
while ((dptr = readdir(dirp))) {
|
while ((dptr = readdir(dirp))) {
|
||||||
int statret;
|
if (dptr->d_name[0] == '.' || dptr->d_type != DT_DIR)
|
||||||
if (dptr->d_name[0]=='.') continue;
|
continue;
|
||||||
|
|
||||||
string filepath = parentDir + "/" + dptr->d_name;
|
string filepath = parentDir + "/" + dptr->d_name;
|
||||||
statret = stat(filepath.c_str(), &st);
|
|
||||||
if (!S_ISDIR(st.st_mode)) continue;
|
if (find(sections.begin(), sections.end(), (string)dptr->d_name) == sections.end()) {
|
||||||
if (statret != -1) {
|
sections.push_back((string)dptr->d_name);
|
||||||
if (find(sections.begin(), sections.end(), (string)dptr->d_name) == sections.end()) {
|
vector<Link*> ll;
|
||||||
sections.push_back((string)dptr->d_name);
|
links.push_back(ll);
|
||||||
vector<Link*> ll;
|
|
||||||
links.push_back(ll);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -425,18 +421,14 @@ void Menu::setLinkIndex(int i) {
|
|||||||
void Menu::readLinksOfSection(std::string path, std::vector<std::string> &linkfiles)
|
void Menu::readLinksOfSection(std::string path, std::vector<std::string> &linkfiles)
|
||||||
{
|
{
|
||||||
DIR *dirp;
|
DIR *dirp;
|
||||||
struct stat st;
|
|
||||||
struct dirent *dptr;
|
struct dirent *dptr;
|
||||||
|
|
||||||
if ((dirp = opendir(path.c_str())) == NULL) return;
|
if ((dirp = opendir(path.c_str())) == NULL) return;
|
||||||
|
|
||||||
while ((dptr = readdir(dirp))) {
|
while ((dptr = readdir(dirp))) {
|
||||||
if (dptr->d_name[0] == '.') continue;
|
if (dptr->d_type != DT_REG) continue;
|
||||||
string filepath = path + "/" + dptr->d_name;
|
string filepath = path + "/" + dptr->d_name;
|
||||||
int statret = stat(filepath.c_str(), &st);
|
linkfiles.push_back(filepath);
|
||||||
if (S_ISDIR(st.st_mode)) continue;
|
|
||||||
if (statret != -1)
|
|
||||||
linkfiles.push_back(filepath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir(dirp);
|
closedir(dirp);
|
||||||
|
Loading…
Reference in New Issue
Block a user