mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-22 12:36:17 +02:00
Skip stat() call when the d_type field can tell us the file type
This is a BSD extension also present in glibc and uClibc. Not all libc implementations and not all file systems support it, so we keep the stat-based code as a fallback.
This commit is contained in:
parent
a505d3e494
commit
b6f6bb387c
@ -94,14 +94,24 @@ void FileLister::browse(const string& path, bool clean)
|
||||
}
|
||||
|
||||
string file = dptr->d_name;
|
||||
string filepath = slashedPath + file;
|
||||
struct stat st;
|
||||
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;
|
||||
bool isDir;
|
||||
#ifdef DT_DIR
|
||||
if (dptr->d_type != DT_UNKNOWN) {
|
||||
isDir = dptr->d_type == DT_DIR;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
string filepath = slashedPath + file;
|
||||
struct stat st;
|
||||
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;
|
||||
}
|
||||
isDir = S_ISDIR(st.st_mode);
|
||||
}
|
||||
if (S_ISDIR(st.st_mode)) {
|
||||
|
||||
if (isDir) {
|
||||
if (!showDirectories)
|
||||
continue;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user