From c5a94cfc0c50c2f9119244f10b7f80341a3f9631 Mon Sep 17 00:00:00 2001 From: Takeshi Nakatani Date: Sat, 6 Feb 2016 13:38:48 +0000 Subject: [PATCH] Check cache dirctory path and attributes - #347 --- src/fdcache.cpp | 10 ++++++++++ src/s3fs.cpp | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/fdcache.cpp b/src/fdcache.cpp index 3a95b51..158ae3c 100644 --- a/src/fdcache.cpp +++ b/src/fdcache.cpp @@ -1584,6 +1584,16 @@ bool FdManager::SetCacheDir(const char* dir) if(!dir || '\0' == dir[0]){ cache_dir = ""; }else{ + // check the directory + struct stat st; + if(0 != stat(dir, &st)){ + S3FS_PRN_ERR("could not access to cache directory(%s) by errno(%d).", cache_dir.c_str(), errno); + return false; + } + if(!S_ISDIR(st.st_mode)){ + S3FS_PRN_ERR("the cache directory(%s) is not directory.", cache_dir.c_str()); + return false; + } cache_dir = dir; } return true; diff --git a/src/s3fs.cpp b/src/s3fs.cpp index 2b1a88c..b894d88 100644 --- a/src/s3fs.cpp +++ b/src/s3fs.cpp @@ -4253,7 +4253,10 @@ static int my_fuse_opt_proc(void* data, const char* arg, int key, struct fuse_ar return 0; } if(0 == STR2NCMP(arg, "use_cache=")){ - FdManager::SetCacheDir(strchr(arg, '=') + sizeof(char)); + if(!FdManager::SetCacheDir(strchr(arg, '=') + sizeof(char))){ + S3FS_PRN_EXIT("cache directory(%s) is specified, but it does not exist or is not directory.", strchr(arg, '=') + sizeof(char)); + return -1; + } return 0; } if(0 == strcmp(arg, "del_cache")){