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());
}