From 51f3202f7450a22464fe7c672d0dcc8d352aaaf9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= Date: Wed, 9 Oct 2013 14:05:57 +0200 Subject: [PATCH] Catalog access() implementation. --- src/VfsNs.cpp | 26 ++++++++++++++++++++++++++ src/VfsNs.h | 1 + 2 files changed, 27 insertions(+) diff --git a/src/VfsNs.cpp b/src/VfsNs.cpp index c1f09c3..8ac10c5 100644 --- a/src/VfsNs.cpp +++ b/src/VfsNs.cpp @@ -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"); diff --git a/src/VfsNs.h b/src/VfsNs.h index e506f9f..9bc4f87 100644 --- a/src/VfsNs.h +++ b/src/VfsNs.h @@ -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); -- 1.8.2.3