X-Git-Url: http://pilppa.org/gitweb/?p=libplp.git;a=blobdiff_plain;f=src%2FFileUtil.cc;h=8b905e6729d4958dad96ff74303a83991133f3eb;hp=1a45e8942b657b4241ad1ba01597b5fcb52fb097;hb=fb1be129d4304d68e42f3e30710968a0899e5482;hpb=88183ebdd35a2bd340d949382f593466dfc887de diff --git a/src/FileUtil.cc b/src/FileUtil.cc index 1a45e89..8b905e6 100644 --- a/src/FileUtil.cc +++ b/src/FileUtil.cc @@ -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;