Check symlinks with stat() to know if they are directories or not
authorPerttu Ahola <celeron55@gmail.com>
Sun, 4 Dec 2011 11:02:00 +0000 (13:02 +0200)
committerPerttu Ahola <celeron55@gmail.com>
Sun, 4 Dec 2011 11:02:00 +0000 (13:02 +0200)
src/filesys.cpp

index 4a01becbfbc1f66a33cd78a7aeae6ea4310bb3e6..a65515d0351dc12f1a6e7236254922a652743cdb 100644 (file)
@@ -196,18 +196,19 @@ std::vector<DirListNode> GetDirListing(std::string pathstring)
                        int isdir = -1; // -1 means unknown
 
                        /*
-                               POSIX doesn't define d_type member of
-                               struct dirent and certain filesystems on
-                               glibc/Linux will only return DT_UNKNOWN for
-                               the d_type member.
+                               POSIX doesn't define d_type member of struct dirent and
+                               certain filesystems on glibc/Linux will only return
+                               DT_UNKNOWN for the d_type member.
+
+                               Also we don't know whether symlinks are directories or not.
                        */
 #ifdef _DIRENT_HAVE_D_TYPE
-                       if(dirp->d_type != DT_UNKNOWN)
+                       if(dirp->d_type != DT_UNKNOWN && dirp->d_type != DT_LNK)
                                isdir = (dirp->d_type == DT_DIR);
 #endif /* _DIRENT_HAVE_D_TYPE */
 
                        /*
-                               Was d_type DT_UNKNOWN (or nonexistent)?
+                               Was d_type DT_UNKNOWN, DT_LNK or nonexistent?
                                If so, try stat().
                        */
                        if(isdir == -1)