From: František Dvořák Date: Sun, 1 Dec 2013 16:26:29 +0000 (+0100) Subject: Implement updateReplica(). X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=3a5acef36b70d53b3f71cda53921aaf808e6cded;p=dmlite-plugins-vfs-old.git Implement updateReplica(). --- diff --git a/src/VfsNs.cpp b/src/VfsNs.cpp index 15145db..2d6e22b 100644 --- a/src/VfsNs.cpp +++ b/src/VfsNs.cpp @@ -1361,7 +1361,29 @@ Replica VfsCatalog::getReplicaByRFN(const std::string& rfn) throw (DmException) void VfsCatalog::updateReplica(const Replica& replica) throw (DmException) { - // Nothing + std::map::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()); }