+///
+/// 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<std::string> 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);
/// 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);