auto statptr = getStat(fpath);
if (statptr == nullptr)
- ThrowExc(CSR_ERROR_FILE_DO_NOT_EXIST, "file not exist: " << fpath);
+ ThrowExc(CSR_ERROR_FILE_DO_NOT_EXIST, "file not exist or no permission: " << fpath);
else if (!S_ISREG(statptr->st_mode) && !S_ISDIR(statptr->st_mode))
ThrowExc(CSR_ERROR_FILE_SYSTEM, "file type is not reguler or dir: " << fpath);
{
auto statptr = getStat(dirpath);
if (statptr == nullptr)
- ThrowExc(CSR_ERROR_FILE_DO_NOT_EXIST, "directory not exist: " << dirpath);
+ ThrowExc(CSR_ERROR_FILE_DO_NOT_EXIST, "directory not exist or no permission: " << dirpath);
else if (!S_ISDIR(statptr->st_mode))
ThrowExc(CSR_ERROR_FILE_SYSTEM, "file type is not directory: " << dirpath);
else
#include <cstring>
#include <cerrno>
+#include <unistd.h>
#include "common/audit/logger.h"
std::unique_ptr<struct stat> statptr(new struct stat);
memset(statptr.get(), 0x00, sizeof(struct stat));
- if (stat(target.c_str(), statptr.get()) != 0) {
+ if (::stat(target.c_str(), statptr.get()) != 0) {
const int err = errno;
if (err == ENOENT)
WARN("target not exist: " << target);
else if (err == EACCES)
- WARN("no permission to read target: " << target);
+ WARN("no permission to read path: " << target);
else
ERROR("stat() failed on target: " << target << " errno: " << err);
return nullptr;
}
- return statptr;
+ // if no permission to read, return nullptr
+ if (::access(target.c_str(), R_OK) != 0)
+ return nullptr;
+ else
+ return statptr;
}
}