Implement updateReplica().
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Sun, 1 Dec 2013 20:12:35 +0000 (21:12 +0100)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Sun, 23 Feb 2014 13:16:20 +0000 (14:16 +0100)
src/VfsNs.cpp

index 10e84bd..70dd977 100644 (file)
@@ -1366,7 +1366,29 @@ Replica VfsCatalog::getReplicaByRFN(const std::string& rfn) throw (DmException)
 
 void VfsCatalog::updateReplica(const Replica& replica) throw (DmException)
 {
-  // Nothing
+  std::map<ino_t,std::string>::const_iterator it;
+  std::string path;
+  ExtendedStat meta;
+  char buf[VFS_XATTR_LENGTH + 8 + 20 + 1];
+
+  if (vfsCheckPermissions("", S_IWRITE))
+    vfsThrow(EACCES, "not enough permissions for '%s'", clientName.c_str());
+
+  it = inodes.find(replica.fileid);
+  if (it == inodes.end())
+    vfsThrow(EINVAL, "fileid %lu not found in the catalog cache", replica.fileid);
+  path = it->second;
+
+  meta = this->vfsExtendedStat(path, true, true, true);
+  if (checkPermissions(this->secCtx_, meta.acl, meta.stat, S_IWRITE) != 0)
+    vfsThrow(EACCES, "not enough permissions for '%s' to add replica '%s'", clientName.c_str(), path.c_str());
+
+  snprintf(buf, sizeof buf, VFS_XATTR "replica." "%ld", replica.replicaid);
+  if (!meta.hasField(buf))
+    vfsThrow(DMLITE_NO_SUCH_REPLICA, "replica %lu of '%s' doesn't exist", replica.replicaid, path.c_str());
+
+  vfsSetXattr(path, getLocalPath(path), buf, replica.rfn, ATTR_REPLACE);
+  debug("updated '%s' to '%s'", replica.rfn.c_str(), path.c_str());
 }