diff --git a/repertory/librepertory/src/file_manager/cache_size_mgr.cpp b/repertory/librepertory/src/file_manager/cache_size_mgr.cpp index 65f348b5..969781c2 100644 --- a/repertory/librepertory/src/file_manager/cache_size_mgr.cpp +++ b/repertory/librepertory/src/file_manager/cache_size_mgr.cpp @@ -38,6 +38,10 @@ E_SIMPLE2(max_cache_size_reached, warn, true, cache_size_mgr cache_size_mgr::instance_{}; auto cache_size_mgr::expand(std::uint64_t size) -> api_error { + if (size == 0U) { + return api_error::success; + } + unique_mutex_lock lock(mtx_); if (cfg_ == nullptr) { return api_error::error; @@ -81,6 +85,10 @@ void cache_size_mgr::initialize(app_config *cfg) { } auto cache_size_mgr::shrink(std::uint64_t size) -> api_error { + if (size == 0U) { + return api_error::success; + } + mutex_lock lock(mtx_); if (cache_size_ >= size) { cache_size_ -= size; diff --git a/repertory/librepertory/src/file_manager/open_file.cpp b/repertory/librepertory/src/file_manager/open_file.cpp index 0e804334..ccd7a090 100644 --- a/repertory/librepertory/src/file_manager/open_file.cpp +++ b/repertory/librepertory/src/file_manager/open_file.cpp @@ -492,7 +492,7 @@ auto open_file::close() -> bool { } if (err != api_error::success || read_state_.all()) { - mgr_.remove_resume(get_api_path(), get_source_path()); + mgr_.remove_resume(fsi_.api_path, get_source_path()); } if (err == api_error::success) { @@ -500,14 +500,17 @@ auto open_file::close() -> bool { } auto file = utils::file::file{fsi_.source_path}; + auto file_size = file.size().value_or(0U); 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"); + auto res = cache_size_mgr::instance().shrink(file_size); + if (res != api_error::success) { + utils::error::raise_api_path_error(function_name, fsi_.api_path, + fsi_.source_path, res, + "failed to shrink cache"); + } } else { utils::error::raise_api_path_error( - function_name, get_api_path(), fsi_.source_path, + function_name, fsi_.api_path, fsi_.source_path, utils::get_last_error_code(), "failed to delete source file"); } @@ -517,7 +520,7 @@ auto open_file::close() -> bool { auto res = provider_.set_item_meta(fsi_.api_path, META_SOURCE, fsi_.source_path); if (res != api_error::success) { - utils::error::raise_api_path_error(function_name, get_api_path(), + utils::error::raise_api_path_error(function_name, fsi_.api_path, fsi_.source_path, res, "failed to set new source path"); }