summaryrefslogtreecommitdiffstats
path: root/lib/Utils
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Utils')
-rw-r--r--lib/Utils/DebugDump.cpp14
-rw-r--r--lib/Utils/xfuncs.cpp19
2 files changed, 23 insertions, 10 deletions
diff --git a/lib/Utils/DebugDump.cpp b/lib/Utils/DebugDump.cpp
index 60564431..43eb3244 100644
--- a/lib/Utils/DebugDump.cpp
+++ b/lib/Utils/DebugDump.cpp
@@ -484,16 +484,10 @@ bool CDebugDump::GetNextFile(std::string& pFileName, std::string& pContent, bool
struct dirent *dent;
while ((dent = readdir(m_pGetNextFileDir)) != NULL)
{
- struct stat statbuf;
- std::string fullname = m_sDebugDumpDir + "/" + dent->d_name;
-
- /* some filesystems do not report the type! they report DT_UNKNOWN */
- if (dent->d_type == DT_REG
- || (dent->d_type == DT_UNKNOWN
- && lstat(fullname.c_str(), &statbuf) == 0
- && S_ISREG(statbuf.st_mode)
- )
- ) {
+ if (is_regular_file(dent, m_sDebugDumpDir.c_str()))
+ {
+ std::string fullname = m_sDebugDumpDir + "/" + dent->d_name;
+
pFileName = dent->d_name;
if (IsTextFile(fullname))
{
diff --git a/lib/Utils/xfuncs.cpp b/lib/Utils/xfuncs.cpp
index f447b8f4..d256c195 100644
--- a/lib/Utils/xfuncs.cpp
+++ b/lib/Utils/xfuncs.cpp
@@ -286,3 +286,22 @@ void xunlink(const char *pathname)
if (unlink(pathname))
perror_msg_and_die("can't remove file '%s'", pathname);
}
+
+/* Just testing dent->d_type == DT_REG is wrong: some filesystems
+ * do not report the type, they report DT_UNKNOWN for every dirent
+ * (and this is not a bug in filesystem, this is allowed by standards).
+ */
+int is_regular_file(struct dirent *dent, const char *dirname)
+{
+ if (dent->d_type == DT_REG)
+ return 1;
+ if (dent->d_type != DT_UNKNOWN)
+ return 0;
+
+ char *fullname = xasprintf("%s/%s", dirname, dent->d_name);
+ struct stat statbuf;
+ int r = lstat(fullname, &statbuf);
+ free(fullname);
+
+ return r == 0 && S_ISREG(statbuf.st_mode);
+}