From 41b373af03f468ebeea269cc4797ef1602fe496f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= Date: Tue, 15 Oct 2013 10:16:57 +0200 Subject: [PATCH] Helper function for setting user extended attribute. --- src/VfsNs.cpp | 28 ++++++++++++++++++++++------ src/VfsNs.h | 1 + 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/VfsNs.cpp b/src/VfsNs.cpp index 9ffff6d..ab06268 100644 --- a/src/VfsNs.cpp +++ b/src/VfsNs.cpp @@ -552,14 +552,11 @@ void VfsCatalog::updateExtendedAttributes(const std::string& path, if (oldXattrs.hasField(key)) { oldvalue = Extensible::anyToString(oldXattrs[key]); - if (oldvalue != value) { - syslog(LOG_DEBUG, "%s: replacing '%s' from '%s' to '%s' on '%s'", __func__, key.c_str(), oldvalue.c_str(), value.c_str(), lpath.c_str()); - wrapCall(attr_set(lpath.c_str(), key.c_str(), value.c_str(), value.size(), ATTR_REPLACE), "could not replace extended attribute '%s' on '%s'", key.c_str(), path.c_str()); - } + if (oldvalue != value) + vfsSetXattr(path, lpath, key, value, ATTR_REPLACE); oldXattrs.erase(key); } else { - syslog(LOG_DEBUG, "%s: creating '%s' = '%s' on '%s'", __func__, key.c_str(), value.c_str(), lpath.c_str()); - wrapCall(attr_set(lpath.c_str(), key.c_str(), value.c_str(), value.size(), ATTR_CREATE), "could not create extended attribute '%s' on '%s'", key.c_str(), path.c_str()); + vfsSetXattr(path, lpath, key, value, ATTR_CREATE); } } for (it = oldXattrs.begin(); it != oldXattrs.end(); it++) { @@ -889,6 +886,25 @@ Extensible VfsCatalog::vfsGetXattrs(const std::string& path, const std::string& +void VfsCatalog::vfsSetXattr(const std::string& path, const std::string& lpath, const std::string key, const std::string value, int flags) { + switch (flags & (ATTR_REPLACE | ATTR_CREATE)) { + case ATTR_REPLACE: + syslog(LOG_DEBUG, "%s: replacing '%s' -> '%s' on '%s'", __func__, key.c_str(), value.c_str(), lpath.c_str()); + wrapCall(attr_set(lpath.c_str(), key.c_str(), value.c_str(), value.size(), flags), "could not replace extended attribute '%s' on '%s'", key.c_str(), path.c_str()); + break; + case ATTR_CREATE: + syslog(LOG_DEBUG, "%s: creating '%s' -> '%s' on '%s'", __func__, key.c_str(), value.c_str(), lpath.c_str()); + wrapCall(attr_set(lpath.c_str(), key.c_str(), value.c_str(), value.size(), flags), "could not create extended attribute '%s' on '%s'", key.c_str(), path.c_str()); + break; + default: + syslog(LOG_DEBUG, "%s: setting '%s' -> '%s' on '%s'", __func__, key.c_str(), value.c_str(), lpath.c_str()); + wrapCall(attr_set(lpath.c_str(), key.c_str(), value.c_str(), value.size(), flags), "could not set extended attribute '%s' on '%s'", key.c_str(), path.c_str()); + break; + } +} + + + regex_t *VfsCatalog::vfsCompileRegex(const char *name, const std::string value) throw (DmException) { regex_t regex; int ret; diff --git a/src/VfsNs.h b/src/VfsNs.h index 462bbc3..13d0c48 100644 --- a/src/VfsNs.h +++ b/src/VfsNs.h @@ -103,6 +103,7 @@ namespace dmlite { ExtendedStat vfsExtendedStat(const std::string& name, const std::string& path, bool follow) throw (DmException); PrivateDir* vfsOpenDir(const std::string& lpath, const std::string& path) throw (DmException); Extensible vfsGetXattrs(const std::string& path, const std::string& lpath, bool follow) throw (DmException); + void vfsSetXattr(const std::string& path, const std::string& lpath, const std::string key, const std::string value, int flags); regex_t *vfsCompileRegex(const char *name, const std::string value) throw (DmException); bool vfsEvalRegex(regex_t *allowRegex, regex_t *denyRegex, const char *subj); -- 1.8.2.3