Skip to content
This repository was archived by the owner on Sep 2, 2021. It is now read-only.

Commit d311efc

Browse files
committed
Merge pull request #369 from adobe/rlim/readdir-issue
Use stat on file systems that do not support d_type in file entry record returned from readdir.
2 parents 30258cc + 132dc1c commit d311efc

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

appshell/appshell_extensions_gtk.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ int32 ReadDir(ExtensionString path, CefRefPtr<CefListValue>& directoryContents)
227227

228228
DIR *dp;
229229
struct dirent *files;
230+
struct stat statbuf;
231+
ExtensionString curFile;
230232

231233
/*struct dirent
232234
{
@@ -245,10 +247,27 @@ int32 ReadDir(ExtensionString path, CefRefPtr<CefListValue>& directoryContents)
245247
{
246248
if(!strcmp(files->d_name,".") || !strcmp(files->d_name,".."))
247249
continue;
250+
248251
if(files->d_type==DT_DIR)
249252
resultDirs.push_back(ExtensionString(files->d_name));
250253
else if(files->d_type==DT_REG)
251254
resultFiles.push_back(ExtensionString(files->d_name));
255+
else
256+
{
257+
// Some file systems do not support d_type we use
258+
// for faster type detection. So on these file systems
259+
// we may get DT_UNKNOWN for all file entries, but just
260+
// to be safe we will use slower stat call for all
261+
// file entries that are not DT_DIR or DT_REG.
262+
curFile = path + files->d_name;
263+
if(stat(curFile.c_str(), &statbuf) == -1)
264+
continue;
265+
266+
if(S_ISDIR(statbuf.st_mode))
267+
resultDirs.push_back(ExtensionString(files->d_name));
268+
else if(S_ISREG(statbuf.st_mode))
269+
resultFiles.push_back(ExtensionString(files->d_name));
270+
}
252271
}
253272

254273
closedir(dp);

0 commit comments

Comments
 (0)