Catalog access() implementation.
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Wed, 9 Oct 2013 12:05:57 +0000 (14:05 +0200)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Wed, 9 Oct 2013 12:05:57 +0000 (14:05 +0200)
src/VfsNs.cpp
src/VfsNs.h

index c1f09c3..8ac10c5 100644 (file)
@@ -90,6 +90,32 @@ ExtendedStat VfsCatalog::extendedStat(const std::string& path, bool follow) thro
 
 
 
+bool VfsCatalog::access(const std::string& path, int mode) throw (DmException)
+{
+  struct stat  fstat;
+
+  if (stat(path.c_str(), &fstat) == -1) {
+    if (errno == ENOENT) {
+      // throw exeption up only if there was not requested test for existence (F_OK)
+      if (mode & F_OK) return false;
+      else vfsThrowErrno("stat() failed on '" + path + "' (stat)");
+    } else
+      vfsThrowErrno("stat() failed on '" + path + "' (stat)");
+  }
+
+  if (::access(path.c_str(), mode) == -1) {
+    if (errno == ENOENT) {
+      // stat() performed OK, but access() failed with ENOENT
+      vfsThrowErrno("access() failed with ENOENT on '" + path + "' (dangling symlink?)");
+    } else
+      return false;
+  }
+
+  return true;
+}
+
+
+
 void VfsCatalog::addReplica(const Replica& replica) throw (DmException)
 {
   throw DmException(EACCES, "Write mode not supported");
index e506f9f..9bc4f87 100644 (file)
@@ -40,6 +40,7 @@ namespace dmlite {
     std::string getWorkingDir (void)               throw (DmException);
 
     ExtendedStat extendedStat(const std::string&, bool) throw (DmException);
+    bool access(const std::string& path, int mode) throw (DmException);
 
     SymLink readLink(ino_t) throw (DmException);