]> git.mxchange.org Git - simgear.git/blobdiff - simgear/misc/sg_dir.cxx
Make get_subsystem safe during destruction of the manager.
[simgear.git] / simgear / misc / sg_dir.cxx
index 92e5af6f56799bbccd18278140b243e3bafdf8ba..b8a6899119520040db94c7d7ae53febef4af8960 100644 (file)
@@ -29,8 +29,6 @@
 #  include <dirent.h>
 #endif
 
-#include <sys/stat.h>
-
 #include <simgear/debug/logstream.hxx>
 
 #include <cstring>
@@ -80,6 +78,12 @@ PathList Dir::children(int types, const std::string& nameFilter) const
     }
     
     if (fData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
+         if (types & NO_DOT_OR_DOTDOT) {
+               if (!strcmp(fData.cFileName,".") || !strcmp(fData.cFileName,"..")) {
+                 continue;
+               }
+         }
+
       if (!(types & TYPE_DIR)) {
         continue;
       }
@@ -113,25 +117,13 @@ PathList Dir::children(int types, const std::string& nameFilter) const
       continue;
     }
     
-    int type = entry->d_type;
-    if (type == DT_LNK) {
-      // find symlink target type using stat()
-      struct stat s;
-      if (stat(file(entry->d_name).c_str(), &s)) {
-        continue; // stat() failed
-      }
-      
-      if (S_ISDIR(s.st_mode)) {
-        type = DT_DIR;
-      } else if (S_ISREG(s.st_mode)) {
-        type = DT_REG;
-      } else {
-        // symlink to block/fifo/char file, ignore
-        continue;
-      }
-    } // of symlink look-through
+    SGPath f = file(entry->d_name);
+    if (!f.exists()) {
+      continue; // stat() failed
+    }
     
-    if (type == DT_DIR) {
+    if (f.isDir()) {
+      // directory handling
       if (!(types & TYPE_DIR)) {
         continue;
       }
@@ -141,14 +133,16 @@ PathList Dir::children(int types, const std::string& nameFilter) const
           continue;
         }
       }
-    } else if (type == DT_REG) {
+    } else if (f.isFile()) {
+      // regular file handling
       if (!(types & TYPE_FILE)) {
         continue;
       }
     } else {
-      continue; // ignore char/block devices, fifos, etc
+      // block device /fifo/char file, ignore
+      continue;
     }
-    
+
     if (!nameFilter.empty()) {
       if (strstr(entry->d_name, nameFilter.c_str()) == NULL) {
         continue;
@@ -164,6 +158,11 @@ PathList Dir::children(int types, const std::string& nameFilter) const
   return result;
 }
 
+bool Dir::exists() const
+{
+  return _path.isDir();
+}
+
 SGPath Dir::file(const std::string& name) const
 {
   SGPath childPath = _path;