From 2666b03f1394b86f6306c37c6071823a52eb2c4b Mon Sep 17 00:00:00 2001 From: RaymondLim Date: Tue, 15 Oct 2013 05:04:23 -0700 Subject: [PATCH 1/2] Use stat call to distinguish between files and directories for file systems that do not support d_type. --- appshell/appshell_extensions_gtk.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/appshell/appshell_extensions_gtk.cpp b/appshell/appshell_extensions_gtk.cpp index 86d48af88..77f36669c 100644 --- a/appshell/appshell_extensions_gtk.cpp +++ b/appshell/appshell_extensions_gtk.cpp @@ -227,6 +227,8 @@ int32 ReadDir(ExtensionString path, CefRefPtr& directoryContents) DIR *dp; struct dirent *files; + struct stat statbuf; + ExtensionString curFile; /*struct dirent { @@ -245,10 +247,26 @@ int32 ReadDir(ExtensionString path, CefRefPtr& 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 if (files->d_type==DT_UNKNOWN) + { + // Some Linux file systems do not support d_type. + // So we get DT_UNKNOWN on these file systems and + // we need to use stat call for each file entry to + // distinguish between files and directories. + 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); From 132dc1c9dad1bd00d938bb8b0fdeddcc5d21a1ce Mon Sep 17 00:00:00 2001 From: RaymondLim Date: Fri, 1 Nov 2013 17:52:10 -0700 Subject: [PATCH 2/2] Use stat for all unknown file entries --- appshell/appshell_extensions_gtk.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/appshell/appshell_extensions_gtk.cpp b/appshell/appshell_extensions_gtk.cpp index 77f36669c..71479df86 100644 --- a/appshell/appshell_extensions_gtk.cpp +++ b/appshell/appshell_extensions_gtk.cpp @@ -252,12 +252,13 @@ int32 ReadDir(ExtensionString path, CefRefPtr& directoryContents) resultDirs.push_back(ExtensionString(files->d_name)); else if(files->d_type==DT_REG) resultFiles.push_back(ExtensionString(files->d_name)); - else if (files->d_type==DT_UNKNOWN) + else { - // Some Linux file systems do not support d_type. - // So we get DT_UNKNOWN on these file systems and - // we need to use stat call for each file entry to - // distinguish between files and directories. + // 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;