From 3733eb61ff63a1daa92a64e799a588f65e4367cd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= Date: Thu, 10 Oct 2013 14:44:13 +0200 Subject: [PATCH] Fix readDir() (no exception on the end), hacky fix of st_nlink on directories. --- src/VfsNs.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/VfsNs.cpp b/src/VfsNs.cpp index 99584e1..3309244 100644 --- a/src/VfsNs.cpp +++ b/src/VfsNs.cpp @@ -80,6 +80,22 @@ ExtendedStat VfsCatalog::extendedStat(const std::string& path, bool follow) thro wrapCall(stat(path.c_str(), &fstat)); else wrapCall(lstat(path.c_str(), &fstat)); + + // black magic - dmlite tests require proper count in st_nlink + if (S_ISDIR(fstat.st_mode)) { + Directory *dir; + struct dirent *entry; + int count = 0; + + dir = openDir(path); + while ((entry = readDir(dir)) != NULL) { + if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) + continue; + count++; + } + closeDir(dir); + fstat.st_nlink = count; + } std::vector components = Url::splitPath(path); @@ -328,7 +344,7 @@ struct dirent* VfsCatalog::readDir(Directory* dir) throw (DmException) throw DmException(DMLITE_SYSERR(EFAULT), "Tried to read a null directory"); - return static_cast(wrapCall(readdir(privateDir->dir))); + return static_cast(readdir(privateDir->dir)); } -- 1.8.2.3