From 700e288718162bcb4da9bfcaee8fc1710d445bdc Mon Sep 17 00:00:00 2001 From: Takeshi Nakatani Date: Sun, 12 Jul 2020 07:49:51 +0000 Subject: [PATCH] Put similar processing together into method GetCacheFileStatTopDir --- src/fdcache.cpp | 43 ++++++++++++++++++++++++++----------------- src/fdcache.h | 1 + 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/fdcache.cpp b/src/fdcache.cpp index 561f56f..81bfff8 100644 --- a/src/fdcache.cpp +++ b/src/fdcache.cpp @@ -65,13 +65,28 @@ static const int MAX_MULTIPART_CNT = 10 * 1000; // S3 multipart max count //------------------------------------------------ // CacheFileStat class methods //------------------------------------------------ +string CacheFileStat::GetCacheFileStatTopDir() +{ + string top_path(""); + if(!FdManager::IsCacheDir() || bucket.empty()){ + return top_path; + } + + // stat top dir( "//..stat" ) + top_path += FdManager::GetCacheDir(); + top_path += "/."; + top_path += bucket; + top_path += ".stat"; + return top_path; +} + bool CacheFileStat::MakeCacheFileStatPath(const char* path, string& sfile_path, bool is_create_dir) { - // make stat dir top path( "//..stat" ) - string top_path = FdManager::GetCacheDir(); - top_path += "/."; - top_path += bucket; - top_path += ".stat"; + string top_path = CacheFileStat::GetCacheFileStatTopDir(); + if(top_path.empty()){ + S3FS_PRN_ERR("The path to cache top dir is empty."); + return false; + } if(is_create_dir){ int result; @@ -90,14 +105,11 @@ bool CacheFileStat::MakeCacheFileStatPath(const char* path, string& sfile_path, bool CacheFileStat::CheckCacheFileStatTopDir() { - if(!FdManager::IsCacheDir()){ + string top_path = CacheFileStat::GetCacheFileStatTopDir(); + if(top_path.empty()){ + S3FS_PRN_INFO("The path to cache top dir is empty, thus not need to check permission."); return true; } - // make stat dir top path( "//..stat" ) - string top_path = FdManager::GetCacheDir(); - top_path += "/."; - top_path += bucket; - top_path += ".stat"; return check_exist_dir_permission(top_path.c_str()); } @@ -130,14 +142,11 @@ bool CacheFileStat::DeleteCacheFileStat(const char* path) // bool CacheFileStat::DeleteCacheFileStatDirectory() { - string top_path = FdManager::GetCacheDir(); - - if(top_path.empty() || bucket.empty()){ + string top_path = CacheFileStat::GetCacheFileStatTopDir(); + if(top_path.empty()){ + S3FS_PRN_INFO("The path to cache top dir is empty, thus not need to remove it."); return true; } - top_path += "/."; - top_path += bucket; - top_path += ".stat"; return delete_files_in_dir(top_path.c_str(), true); } diff --git a/src/fdcache.h b/src/fdcache.h index 6ef6687..d48916d 100644 --- a/src/fdcache.h +++ b/src/fdcache.h @@ -35,6 +35,7 @@ class CacheFileStat static bool MakeCacheFileStatPath(const char* path, std::string& sfile_path, bool is_create_dir = true); public: + static std::string GetCacheFileStatTopDir(void); static bool DeleteCacheFileStat(const char* path); static bool CheckCacheFileStatTopDir(void); static bool DeleteCacheFileStatDirectory(void);