From: František Dvořák Date: Thu, 17 Oct 2013 17:48:00 +0000 (+0200) Subject: Helper function for setting user extended attribute. X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=3b49ae5a0e4156d218557f14ac90806a10ac78cf;p=dmlite-plugins-vfs.git Helper function for setting user extended attribute. --- 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);