]> pilppa.org Git - libplp.git/blobdiff - src/FileUtil.cc
Data read optimizations
[libplp.git] / src / FileUtil.cc
index 1a45e8942b657b4241ad1ba01597b5fcb52fb097..8b905e6729d4958dad96ff74303a83991133f3eb 100644 (file)
@@ -122,7 +122,8 @@ bool FileUtil::mkdirs(const char *path) {
        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;
 
@@ -141,6 +142,43 @@ bool FileUtil::file_exist(const char *file_name_with_path, bool writable) {
        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;