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

Commit

Permalink
Merge pull request #369 from adobe/rlim/readdir-issue
Browse files Browse the repository at this point in the history
Use stat on file systems that do not support d_type in file entry record returned from readdir.
  • Loading branch information
ingorichter committed Nov 6, 2013
2 parents 30258cc + 132dc1c commit d311efc
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions appshell/appshell_extensions_gtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ int32 ReadDir(ExtensionString path, CefRefPtr<CefListValue>& directoryContents)

DIR *dp;
struct dirent *files;
struct stat statbuf;
ExtensionString curFile;

/*struct dirent
{
Expand All @@ -245,10 +247,27 @@ int32 ReadDir(ExtensionString path, CefRefPtr<CefListValue>& directoryContents)
{
if(!strcmp(files->d_name,".") || !strcmp(files->d_name,".."))
continue;

if(files->d_type==DT_DIR)
resultDirs.push_back(ExtensionString(files->d_name));
else if(files->d_type==DT_REG)
resultFiles.push_back(ExtensionString(files->d_name));
else
{
// Some file systems do not support d_type we use
// for faster type detection. So on these file systems
// we may get DT_UNKNOWN for all file entries, but just
// to be safe we will use slower stat call for all
// file entries that are not DT_DIR or DT_REG.
curFile = path + files->d_name;
if(stat(curFile.c_str(), &statbuf) == -1)
continue;

if(S_ISDIR(statbuf.st_mode))
resultDirs.push_back(ExtensionString(files->d_name));
else if(S_ISREG(statbuf.st_mode))
resultFiles.push_back(ExtensionString(files->d_name));
}
}

closedir(dp);
Expand Down

0 comments on commit d311efc

Please sign in to comment.