From 30c0bd63bc416df36f97e7aff6182e19f34e7c00 Mon Sep 17 00:00:00 2001 From: Torbjörn Andersson Date: Mon, 8 May 2006 04:48:40 +0000 Subject: Fixed bug #1483450. Apparently, S_ISDIR() is undefined if stat() fails. The change to the POSIXFilesystemNode constructor is the one that matters to this bug. The changes to listDir() are made from paranoia. svn-id: r22382 --- backends/fs/posix/posix-fs.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'backends') diff --git a/backends/fs/posix/posix-fs.cpp b/backends/fs/posix/posix-fs.cpp index b9278fbb00..ea874c9d0e 100644 --- a/backends/fs/posix/posix-fs.cpp +++ b/backends/fs/posix/posix-fs.cpp @@ -131,7 +131,7 @@ POSIXFilesystemNode::POSIXFilesystemNode(const String &p, bool verify) { #else struct stat st; _isValid = (0 == stat(_path.c_str(), &st)); - _isDirectory = S_ISDIR(st.st_mode); + _isDirectory = _isValid ? S_ISDIR(st.st_mode) : false; #endif } } @@ -166,19 +166,21 @@ bool POSIXFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const { // add this #elif case, which tries to use stat() instead. struct stat st; entry._isValid = (0 == stat(entry._path.c_str(), &st)); - entry._isDirectory = S_ISDIR(st.st_mode); + entry._isDirectory = entry._isValid ? S_ISDIR(st.st_mode) : false; #else if (dp->d_type == DT_UNKNOWN) { // Fall back to stat() struct stat st; entry._isValid = (0 == stat(entry._path.c_str(), &st)); - entry._isDirectory = S_ISDIR(st.st_mode); + entry._isDirectory = entry._isValid ? S_ISDIR(st.st_mode) : false; } else { entry._isValid = (dp->d_type == DT_DIR) || (dp->d_type == DT_REG) || (dp->d_type == DT_LNK); if (dp->d_type == DT_LNK) { struct stat st; - stat(entry._path.c_str(), &st); - entry._isDirectory = S_ISDIR(st.st_mode); + if (stat(entry._path.c_str(), &st) == 0) + entry._isDirectory = S_ISDIR(st.st_mode); + else + entry._isDirectory = false; } else { entry._isDirectory = (dp->d_type == DT_DIR); } -- cgit v1.2.3