Fix readDir() (no exception on the end), hacky fix of st_nlink on directories.
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Thu, 10 Oct 2013 12:44:13 +0000 (14:44 +0200)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Thu, 10 Oct 2013 12:44:13 +0000 (14:44 +0200)
src/VfsNs.cpp

index 99584e1..3309244 100644 (file)
@@ -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<std::string> 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<struct dirent*>(wrapCall(readdir(privateDir->dir)));
+  return static_cast<struct dirent*>(readdir(privateDir->dir));
 }