From 868e8ae12405ffea23161fece7b22fed5b50afde Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Wed, 25 Sep 2024 07:18:48 -0500 Subject: [PATCH] refactor --- .../src/file_manager/file_manager.cpp | 72 ++++++++++--------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/repertory/librepertory/src/file_manager/file_manager.cpp b/repertory/librepertory/src/file_manager/file_manager.cpp index 4757ad31..3adbee12 100644 --- a/repertory/librepertory/src/file_manager/file_manager.cpp +++ b/repertory/librepertory/src/file_manager/file_manager.cpp @@ -866,44 +866,48 @@ void file_manager::start() { filesystem_item fsi{}; auto res = provider_.get_filesystem_item(api_path, false, fsi); - if (res == api_error::success) { - if (source_path == fsi.source_path) { - auto opt_size = utils::file::file{fsi.source_path}.size(); - if (opt_size.has_value()) { - auto file_size{opt_size.value()}; - if (file_size == fsi.size) { - auto closeable_file = std::make_shared( - chunk_size, - config_.get_enable_chunk_download_timeout() - ? config_.get_chunk_downloader_timeout_secs() - : 0U, - fsi, provider_, read_state, *this); - open_file_lookup_[api_path] = closeable_file; - event_system::instance().raise( - fsi.api_path, fsi.source_path); - } else { - event_system::instance().raise( - fsi.api_path, fsi.source_path, - "file size mismatch|expected|" + std::to_string(fsi.size) + - "|actual|" + std::to_string(file_size)); - } - } else { - event_system::instance().raise( - fsi.api_path, fsi.source_path, - "failed to get file size: " + - std::to_string(utils::get_last_error_code())); - } - } else { - event_system::instance().raise( - fsi.api_path, fsi.source_path, - "source path mismatch|expected|" + source_path + "|actual|" + - fsi.source_path); - } - } else { + if (res != api_error::success) { event_system::instance().raise( api_path, source_path, "failed to get filesystem item|" + api_error_to_string(res)); + continue; } + + if (source_path != fsi.source_path) { + event_system::instance().raise( + fsi.api_path, fsi.source_path, + "source path mismatch|expected|" + source_path + "|actual|" + + fsi.source_path); + continue; + } + + auto opt_size = utils::file::file{fsi.source_path}.size(); + if (not opt_size.has_value()) { + event_system::instance().raise( + fsi.api_path, fsi.source_path, + "failed to get file size: " + + std::to_string(utils::get_last_error_code())); + continue; + } + + auto file_size{opt_size.value()}; + if (file_size != fsi.size) { + event_system::instance().raise( + fsi.api_path, fsi.source_path, + "file size mismatch|expected|" + std::to_string(fsi.size) + + "|actual|" + std::to_string(file_size)); + continue; + } + + auto closeable_file = std::make_shared( + chunk_size, + config_.get_enable_chunk_download_timeout() + ? config_.get_chunk_downloader_timeout_secs() + : 0U, + fsi, provider_, read_state, *this); + open_file_lookup_[api_path] = closeable_file; + event_system::instance().raise(fsi.api_path, + fsi.source_path); } catch (const std::exception &ex) { utils::error::raise_error(function_name, ex, "query error"); }