diff --git a/repertory/librepertory/src/file_manager/cache_size_mgr.cpp b/repertory/librepertory/src/file_manager/cache_size_mgr.cpp index 138e1647..65f348b5 100644 --- a/repertory/librepertory/src/file_manager/cache_size_mgr.cpp +++ b/repertory/librepertory/src/file_manager/cache_size_mgr.cpp @@ -82,7 +82,7 @@ void cache_size_mgr::initialize(app_config *cfg) { auto cache_size_mgr::shrink(std::uint64_t size) -> api_error { mutex_lock lock(mtx_); - if (size >= cache_size_) { + if (cache_size_ >= size) { cache_size_ -= size; } else { cache_size_ = 0U; diff --git a/repertory/librepertory/src/file_manager/open_file.cpp b/repertory/librepertory/src/file_manager/open_file.cpp index b39ee174..0e804334 100644 --- a/repertory/librepertory/src/file_manager/open_file.cpp +++ b/repertory/librepertory/src/file_manager/open_file.cpp @@ -499,7 +499,13 @@ auto open_file::close() -> bool { return true; } - if (not utils::file::file(fsi_.source_path).remove()) { + auto file = utils::file::file{fsi_.source_path}; + if (file.remove()) { + err = cache_size_mgr::instance().shrink(file.size().value_or(0U)); + if (err != api_error::success) { + utils::error::raise_api_path_error(function_name, api_path, err, + } "failed to shrink cache"); + } else { utils::error::raise_api_path_error( function_name, get_api_path(), fsi_.source_path, utils::get_last_error_code(), "failed to delete source file");