Care specially for the parent of the root (owned by root and 0755 permissions).
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Sat, 19 Oct 2013 19:17:29 +0000 (21:17 +0200)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Mon, 10 Feb 2014 14:07:32 +0000 (15:07 +0100)
src/VfsNs.cpp

index 7685650..fd25f64 100644 (file)
@@ -921,12 +921,13 @@ ExtendedStat VfsCatalog::getParent(const std::string& path,
                                        std::string* parentPath,
                                        std::string* name) throw (DmException)
 {
+  std::vector<std::string> components;
   bool absPath;
 
   if (path.empty())
     vfsThrow(EINVAL, "empty path");
 
-  std::vector<std::string> components = Url::splitPath(path);
+  components = Url::splitPath(path);
 
   *name = components.back();
   components.pop_back();
@@ -938,10 +939,23 @@ ExtendedStat VfsCatalog::getParent(const std::string& path,
     //   /
     //   name
     //
-    // We can't check parent of root.
+
+    // Root directory is special case.
+    if (absPath) {
+      ExtendedStat xStat;
+
+      memset(&xStat.stat, 0, sizeof xStat.stat);
+      xStat.stat.st_mode = S_IFDIR | 0755;
+      xStat.name = "/..";
+
+      *parentPath = xStat.name;
+
+      debug("parent of root directory, owner %u, group %u, permissions %06o", xStat.stat.st_uid, xStat.stat.st_gid, xStat.stat.st_mode);
+      return xStat;
+    }
+
     // Single name is relative path with parent ".".
-    //
-    *parentPath = absPath ? "/" : this->getWorkingDir();
+    *parentPath = this->getWorkingDir();
   } else {
     //
     // At least one directory: