From: František Dvořák Date: Thu, 17 Oct 2013 15:38:05 +0000 (+0200) Subject: Reshuffle extendedStat(). X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=5b1b957c70e98ecf094d7a582e068d3e181f8325;p=dmlite-plugins-vfs-old.git Reshuffle extendedStat(). --- diff --git a/src/VfsNs.cpp b/src/VfsNs.cpp index 64db5f7..b78650e 100644 --- a/src/VfsNs.cpp +++ b/src/VfsNs.cpp @@ -129,55 +129,77 @@ std::string VfsCatalog::getWorkingDir(void) throw (DmException) +/// +/// Do simple stat()/lstat() without setting st_nlink and checking permissions. +/// Optionally retrieves also the information related to permissions in +/// optimized way (using only attributes related to permissions). +/// +/// @param name file name +/// @param path local disk namespace path +/// @param follow follow symlinks (to use stat() or lstat()) // -// helper function -// (stat() only, without setting st_nlink, checking permissions, or xattr) -// -ExtendedStat VfsCatalog::vfsExtendedStat(const std::string& name, const std::string& path, bool follow) throw (DmException) { +ExtendedStat VfsCatalog::vfsSimpleStat(const std::string& name, const std::string& path, const std::string& lpath, bool follow) throw (DmException) { ExtendedStat xStat; struct stat fstat; if (follow) - wrapCall(stat(path.c_str(), &fstat), "could not stat '%s'", path.c_str()); + wrapCall(stat(lpath.c_str(), &fstat), "could not stat '%s'", path.c_str()); else - wrapCall(lstat(path.c_str(), &fstat), "could not lstat '%s'", path.c_str()); + wrapCall(lstat(lpath.c_str(), &fstat), "could not lstat '%s'", path.c_str()); - xStat.acl = Acl(); xStat.name = name; xStat.stat = fstat; xStat.parent = 0; xStat.status = ExtendedStat::kOnline; + xStat.acl = Acl(); return xStat; } -ExtendedStat VfsCatalog::extendedStat(const std::string& path, bool follow) throw (DmException) -{ +/// +/// Perform simple stat (using vfsSimpleStat()) with all permissions checks. +/// Optionally retrieves also the information related to permissions in +/// optimized way (using only attributes related to permissions). +/// +/// @param path public namespace path +/// @param follow follow symlinks +/// +ExtendedStat VfsCatalog::vfsExtendedStat(const std::string& path, bool follow) throw (DmException) { ExtendedStat meta; - Extensible xattrs; - std::string dir, c; std::vector components; + std::string dir; // check permissions from the top if (path[0] == '/') dir = path; else dir = this->getWorkingDir() + "/" + path; components = Url::splitPath(dir); - dir = this->prefix_; + dir = ""; for (unsigned int i = 0; i < components.size() - 1; i++) { // the first component always '/', let's use it as separator if (i < 2) dir += components[i]; else dir = dir + "/" + components[i]; - meta = vfsExtendedStat(components[i], dir, true); + meta = vfsSimpleStat(components[i], dir, getLocalPath(dir), true); if (checkPermissions(this->secCtx_, meta.acl, meta.stat, S_IEXEC) != 0) vfsThrow(EACCES, "not enough permissions for '%s' to list '%s'", clientName.c_str(), meta.name.c_str()); } - meta = vfsExtendedStat(components.back(), getLocalPath(path), follow); + return vfsSimpleStat(components.back(), path, getLocalPath(path), follow); +} + + + +ExtendedStat VfsCatalog::extendedStat(const std::string& path, bool follow) throw (DmException) +{ + ExtendedStat meta; + Extensible xattrs; + + meta = vfsExtendedStat(path, follow); + // not require working xattrs try { xattrs = vfsGetXattrs(path, getLocalPath(path), follow); diff --git a/src/VfsNs.h b/src/VfsNs.h index 626103e..c0f4a9a 100644 --- a/src/VfsNs.h +++ b/src/VfsNs.h @@ -100,7 +100,8 @@ namespace dmlite { /// Get path on the local disk according to "public" path. /// Relative paths are unchanged. const std::string getLocalPath(const std::string &path); - ExtendedStat vfsExtendedStat(const std::string& name, const std::string& path, bool follow) throw (DmException); + ExtendedStat vfsSimpleStat(const std::string& name, const std::string& path, const std::string& lpath, bool follow) throw (DmException); + ExtendedStat vfsExtendedStat(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);