From 150b83f61ef82d2de8fddd53a82ecaffaae4a166 Mon Sep 17 00:00:00 2001 From: Takeshi Nakatani Date: Sat, 6 Feb 2016 18:59:13 +0000 Subject: [PATCH] Remove stat file cache dir if specified del_cache - #337 --- src/fdcache.cpp | 17 +++++++++++++++++ src/fdcache.h | 1 + src/s3fs.cpp | 14 ++++++++------ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/fdcache.cpp b/src/fdcache.cpp index 158ae3c..a72f845 100644 --- a/src/fdcache.cpp +++ b/src/fdcache.cpp @@ -124,6 +124,23 @@ bool CacheFileStat::DeleteCacheFileStat(const char* path) return true; } +// [NOTE] +// If remove stat file directory, it should do before removing +// file cache directory. +// +bool CacheFileStat::DeleteCacheFileStatDirectory(void) +{ + string top_path = FdManager::GetCacheDir(); + + if(top_path.empty() || bucket.empty()){ + return true; + } + top_path += "/."; + top_path += bucket; + top_path += ".stat"; + return delete_files_in_dir(top_path.c_str(), true); +} + //------------------------------------------------ // CacheFileStat methods //------------------------------------------------ diff --git a/src/fdcache.h b/src/fdcache.h index f1bb64c..423c5b5 100644 --- a/src/fdcache.h +++ b/src/fdcache.h @@ -38,6 +38,7 @@ class CacheFileStat public: static bool DeleteCacheFileStat(const char* path); static bool CheckCacheFileStatTopDir(void); + static bool DeleteCacheFileStatDirectory(void); explicit CacheFileStat(const char* tpath = NULL); ~CacheFileStat(); diff --git a/src/s3fs.cpp b/src/s3fs.cpp index b894d88..8b3e2fc 100644 --- a/src/s3fs.cpp +++ b/src/s3fs.cpp @@ -3315,6 +3315,11 @@ static void* s3fs_init(struct fuse_conn_info* conn) { S3FS_PRN_CRIT("init v%s(commit:%s) with %s", VERSION, COMMIT_HASH_VAL, s3fs_crypt_lib_name()); + // cache(remove cache dirs at first) + if(is_remove_cache && (!CacheFileStat::DeleteCacheFileStatDirectory() || !FdManager::DeleteCacheDirectory())){ + S3FS_PRN_DBG("Could not inilialize cache directory."); + } + // ssl init if(!s3fs_init_global_ssl()){ S3FS_PRN_CRIT("could not initialize for ssl libraries."); @@ -3350,10 +3355,7 @@ static void* s3fs_init(struct fuse_conn_info* conn) conn->want |= FUSE_CAP_ATOMIC_O_TRUNC; } #endif - // cache - if(is_remove_cache && !FdManager::DeleteCacheDirectory()){ - S3FS_PRN_DBG("Could not inilialize cache directory."); - } + return NULL; } @@ -3365,8 +3367,8 @@ static void s3fs_destroy(void*) if(!S3fsCurl::DestroyS3fsCurl()){ S3FS_PRN_WARN("Could not release curl library."); } - // cache - if(is_remove_cache && !FdManager::DeleteCacheDirectory()){ + // cache(remove at last) + if(is_remove_cache && (!CacheFileStat::DeleteCacheFileStatDirectory() || !FdManager::DeleteCacheDirectory())){ S3FS_PRN_WARN("Could not remove cache directory."); } // ssl