From 072e32f6d9437702fd406b9dcbbfd0f17c908768 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= Date: Sun, 1 Dec 2013 21:12:35 +0100 Subject: [PATCH] Implement updateReplica(). --- src/VfsNs.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/VfsNs.cpp b/src/VfsNs.cpp index 10e84bd..70dd977 100644 --- a/src/VfsNs.cpp +++ b/src/VfsNs.cpp @@ -1366,7 +1366,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()); } -- 1.8.2.3