Check symlinks with stat() to know if they are directories or not

master
Perttu Ahola 2011-12-04 13:02:00 +02:00
parent ab67985d21
commit 520200d597
1 changed files with 7 additions and 6 deletions

View File

@ -196,18 +196,19 @@ std::vector<DirListNode> GetDirListing(std::string pathstring)
int isdir = -1; // -1 means unknown int isdir = -1; // -1 means unknown
/* /*
POSIX doesn't define d_type member of POSIX doesn't define d_type member of struct dirent and
struct dirent and certain filesystems on certain filesystems on glibc/Linux will only return
glibc/Linux will only return DT_UNKNOWN for DT_UNKNOWN for the d_type member.
the d_type member.
Also we don't know whether symlinks are directories or not.
*/ */
#ifdef _DIRENT_HAVE_D_TYPE #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); isdir = (dirp->d_type == DT_DIR);
#endif /* _DIRENT_HAVE_D_TYPE */ #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 so, try stat().
*/ */
if(isdir == -1) if(isdir == -1)