All stat fields updates to separate function (vfsUpdateExtendedStat()), use it in...
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Thu, 17 Oct 2013 19:58:01 +0000 (21:58 +0200)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Sun, 23 Feb 2014 13:16:18 +0000 (14:16 +0100)
src/VfsNs.cpp
src/VfsNs.h

index fa903ca..35a7867 100644 (file)
@@ -171,6 +171,45 @@ void VfsCatalog::vfsUpdateStat(ExtendedStat &xStat, Extensible xattrs) throw (Dm
 
 
 ///
+/// Update all ExtendedStat fields.
+/// Requires user extended attributes retrieved with VFS_XATTR_TYPE_ALL.
+///
+/// @param xStat   Updated ExtendedStat class.
+/// @param xattrs  User extended attributes (requires all).
+///
+void VfsCatalog::vfsUpdateExtendedStat(ExtendedStat &xStat, Extensible xattrs) throw (DmException) {
+  Extensible::const_iterator it;
+  std::string key;
+
+  // ownership and permissions parts
+  vfsUpdateStat(xStat, xattrs);
+
+  // copy non-VFS attributes
+  for (it = xattrs.begin(); it != xattrs.end(); it++) {
+    key = it->first;
+    if (!IS_VFS_XATTR(key.c_str()))
+      xStat[key] = xattrs[key];
+  }
+
+  // use VFS attributes
+  xStat.stat.st_size = xattrs.getU64(VFS_XATTR "size", 0);
+  if (xStat.hasField("checksum.md5")) {
+    xStat.csumtype = "MD";
+    xStat.csumvalue = xStat.getString("checksum.md5");
+  } else if (xStat.hasField("checksum.adler32")) {
+    xStat.csumtype = "AD";
+    xStat.csumvalue = xStat.getString("checksum.adler32");
+  } else if (xStat.hasField("checksum.crc32")) {
+    xStat.csumtype = "CS";
+    xStat.csumvalue = xStat.getString("checksum.crc32");
+  }
+
+  xStat["pool"] = std::string("vfs");
+}
+
+
+
+///
 /// Do simple stat()/lstat() without setting st_nlink and checking permissions.
 /// Optionally retrieves also the information related to permissions in
 /// optimized way (using only attributes related to permissions).
@@ -270,27 +309,8 @@ ExtendedStat VfsCatalog::extendedStat(const std::string& path, bool follow) thro
     // ignore - default owner and no ACLs
   }
 
-  // copy non-VFS attributes
-  for (it = xattrs.begin(); it != xattrs.end(); it++) {
-    key = it->first;
-    if (!IS_VFS_XATTR(key.c_str()))
-      meta[key] = xattrs[key];
-  }
-
-  vfsUpdateStat(meta, xattrs);
-  meta.stat.st_size = xattrs.getU64(VFS_XATTR "size", 0);
-  if (meta.hasField("checksum.md5")) {
-    meta.csumtype = "MD";
-    meta.csumvalue = meta.getString("checksum.md5");
-  } else if (meta.hasField("checksum.adler32")) {
-    meta.csumtype = "AD";
-    meta.csumvalue = meta.getString("checksum.adler32");
-  } else if (meta.hasField("checksum.crc32")) {
-    meta.csumtype = "CS";
-    meta.csumvalue = meta.getString("checksum.crc32");
-  }
-
-  meta["pool"] = std::string("vfs");
+  // use the retrieved xattrs
+  vfsUpdateExtendedStat(meta, xattrs);
 
 #if 0
   // XXX: black magic
@@ -939,6 +959,7 @@ struct dirent* VfsCatalog::readDir(Directory* dir) throw (DmException)
 ExtendedStat* VfsCatalog::readDirx(Directory* dir) throw (DmException)
 {
   PrivateDir *privateDir = static_cast<PrivateDir*>(dir);
+  Extensible xattrs;
   
   struct dirent *ent = this->readDir(dir);
   if (ent == NULL) return NULL;
@@ -954,6 +975,13 @@ ExtendedStat* VfsCatalog::readDirx(Directory* dir) throw (DmException)
   privateDir->stat.status = ExtendedStat::kOnline;
   privateDir->stat.parent = 0;
   
+  try {
+    xattrs = vfsGetXattrs(privateDir->path + '/' + ent->d_name, privateDir->lpath + '/' + ent->d_name, false, VFS_XATTR_TYPE_ALL);
+  } catch (DmException& e) {
+    // ignore - default owner and no ACLs
+  }
+  vfsUpdateExtendedStat(privateDir->stat, xattrs);
+
   return &(privateDir->stat);
 }
 
index dc31577..7f830d5 100644 (file)
@@ -107,6 +107,7 @@ namespace dmlite {
     /// Relative paths are unchanged.
     const std::string getLocalPath(const std::string &path);
     void vfsUpdateStat(ExtendedStat &xStat, Extensible xattrs) throw (DmException);
+    void vfsUpdateExtendedStat(ExtendedStat &xStat, Extensible xattrs) throw (DmException);
     ExtendedStat vfsSimpleStat(const std::string& name, const std::string& path, const std::string& lpath, bool follow, bool perms) throw (DmException);
     ExtendedStat vfsExtendedStat(const std::string& path, bool follow = true, bool perms = true) throw (DmException);
     PrivateDir* vfsOpenDir(const std::string& lpath, const std::string& path) throw (DmException);