#include <string.h>
#include <sys/stat.h>
#include <stdbool.h>
+#include <unistd.h>
#include "log.h"
#include "FileUtil.hh"
return ret_val;
}
-bool FileUtil::file_exist(const char *file_name_with_path, bool writable) {
+bool FileUtil::file_exist(const char *file_name_with_path,
+ bool writable) {
bool ret_val;
int acl_mode;
return ret_val;
}
+bool FileUtil::dir_exist(const char *dir_name_with_path,
+ bool writable) {
+ bool ret_val;
+ struct stat st;
+ bool is_dir;
+
+ ret_val = false;
+ if (stat(dir_name_with_path, &st) == 0) {
+ is_dir = S_ISDIR(st.st_mode);
+ if (is_dir == true) {
+ if (writable == false) {
+ // check only the read permission
+ ret_val = ((st.st_mode) & S_IRUSR);
+
+ }
+ else {
+ // check also the write permission
+ ret_val = ((st.st_mode) & S_IWUSR);
+ }
+/*
+ int acl_mode;
+ if (writable == true) {
+ acl_mode = W_OK;
+ }
+ else {
+ acl_mode = R_OK;
+ }
+ if (dir_name_with_path != NULL) {
+ if (access(dir_name_with_path, acl_mode) == 0) {
+ }
+ }
+*/
+ }
+ }
+ return ret_val;
+}
+
bool FileUtil::mkfile(const char *file_name_with_path, bool writable) {
bool ret_val;
string path_name;