From 6d4016cc9d7be0bd3c8110382076cae35d9be161 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Mon, 10 Feb 2014 13:52:11 +0000 Subject: Add a ClearDirectoryCache method to BackupStoreContext. It's used in several places, and about to be one more. --- lib/backupstore/BackupStoreContext.cpp | 16 +++++++++------- lib/backupstore/BackupStoreContext.h | 1 + 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'lib/backupstore') diff --git a/lib/backupstore/BackupStoreContext.cpp b/lib/backupstore/BackupStoreContext.cpp index db0b11c8..7548cba6 100644 --- a/lib/backupstore/BackupStoreContext.cpp +++ b/lib/backupstore/BackupStoreContext.cpp @@ -78,15 +78,21 @@ BackupStoreContext::BackupStoreContext(int32_t ClientID, // // -------------------------------------------------------------------------- BackupStoreContext::~BackupStoreContext() +{ + ClearDirectoryCache(); +} + +void BackupStoreContext::ClearDirectoryCache() { // Delete the objects in the cache - for(std::map::iterator i(mDirectoryCache.begin()); i != mDirectoryCache.end(); ++i) + for(std::map::iterator i(mDirectoryCache.begin()); + i != mDirectoryCache.end(); ++i) { delete (i->second); } + mDirectoryCache.clear(); } - // -------------------------------------------------------------------------- // // Function @@ -321,11 +327,7 @@ BackupStoreDirectory &BackupStoreContext::GetDirectoryInternal(int64_t ObjectID) if(mDirectoryCache.size() > MAX_CACHE_SIZE) { // Very simple. Just delete everything! - for(std::map::iterator i(mDirectoryCache.begin()); i != mDirectoryCache.end(); ++i) - { - delete (i->second); - } - mDirectoryCache.clear(); + ClearDirectoryCache(); } // Get a RaidFileRead to read it diff --git a/lib/backupstore/BackupStoreContext.h b/lib/backupstore/BackupStoreContext.h index 9440950c..03f642ef 100644 --- a/lib/backupstore/BackupStoreContext.h +++ b/lib/backupstore/BackupStoreContext.h @@ -168,6 +168,7 @@ private: void SaveDirectory(BackupStoreDirectory &rDir, int64_t ObjectID); void RemoveDirectoryFromCache(int64_t ObjectID); void DeleteDirectoryRecurse(int64_t ObjectID, int64_t &rBlocksDeletedOut, bool Undelete); + void ClearDirectoryCache(); int64_t AllocateObjectID(); std::string mConnectionDetails; -- cgit v1.2.3