Modify canRead and CanWrite functions of fsaccess class

Signed-off-by: Mayank Raghuwanshi <mayank.raghuwanshi@intel.com>
This commit is contained in:
Mayank Raghuwanshi
2021-10-04 16:39:24 +05:30
committed by Compute-Runtime-Automation
parent 12ab2961b1
commit 52e9dd26a6
4 changed files with 78 additions and 8 deletions

View File

@@ -168,23 +168,25 @@ ze_result_t FsAccess::write(const std::string file, const std::string val) {
}
ze_result_t FsAccess::canRead(const std::string file) {
if (access(file.c_str(), F_OK)) {
struct stat sb;
if (statSyscall(file.c_str(), &sb) != 0) {
return ZE_RESULT_ERROR_UNKNOWN;
}
if (access(file.c_str(), R_OK)) {
return ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS;
if (sb.st_mode & S_IRUSR) {
return ZE_RESULT_SUCCESS;
}
return ZE_RESULT_SUCCESS;
return ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS;
}
ze_result_t FsAccess::canWrite(const std::string file) {
if (access(file.c_str(), F_OK)) {
struct stat sb;
if (statSyscall(file.c_str(), &sb) != 0) {
return ZE_RESULT_ERROR_UNKNOWN;
}
if (access(file.c_str(), W_OK)) {
return ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS;
if (sb.st_mode & S_IWUSR) {
return ZE_RESULT_SUCCESS;
}
return ZE_RESULT_SUCCESS;
return ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS;
}
bool FsAccess::fileExists(const std::string file) {

View File

@@ -55,6 +55,7 @@ class FsAccess {
protected:
FsAccess();
decltype(&NEO::SysCalls::access) accessSyscall = NEO::SysCalls::access;
decltype(&stat) statSyscall = stat;
};
class ProcfsAccess : private FsAccess {