refactor
This commit is contained in:
parent
51358c7110
commit
868e8ae124
@ -866,12 +866,39 @@ void file_manager::start() {
|
|||||||
|
|
||||||
filesystem_item fsi{};
|
filesystem_item fsi{};
|
||||||
auto res = provider_.get_filesystem_item(api_path, false, fsi);
|
auto res = provider_.get_filesystem_item(api_path, false, fsi);
|
||||||
if (res == api_error::success) {
|
if (res != api_error::success) {
|
||||||
if (source_path == fsi.source_path) {
|
event_system::instance().raise<download_restore_failed>(
|
||||||
|
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<download_restore_failed>(
|
||||||
|
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();
|
auto opt_size = utils::file::file{fsi.source_path}.size();
|
||||||
if (opt_size.has_value()) {
|
if (not opt_size.has_value()) {
|
||||||
|
event_system::instance().raise<download_restore_failed>(
|
||||||
|
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()};
|
auto file_size{opt_size.value()};
|
||||||
if (file_size == fsi.size) {
|
if (file_size != fsi.size) {
|
||||||
|
event_system::instance().raise<download_restore_failed>(
|
||||||
|
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<open_file>(
|
auto closeable_file = std::make_shared<open_file>(
|
||||||
chunk_size,
|
chunk_size,
|
||||||
config_.get_enable_chunk_download_timeout()
|
config_.get_enable_chunk_download_timeout()
|
||||||
@ -879,31 +906,8 @@ void file_manager::start() {
|
|||||||
: 0U,
|
: 0U,
|
||||||
fsi, provider_, read_state, *this);
|
fsi, provider_, read_state, *this);
|
||||||
open_file_lookup_[api_path] = closeable_file;
|
open_file_lookup_[api_path] = closeable_file;
|
||||||
event_system::instance().raise<download_restored>(
|
event_system::instance().raise<download_restored>(fsi.api_path,
|
||||||
fsi.api_path, fsi.source_path);
|
|
||||||
} else {
|
|
||||||
event_system::instance().raise<download_restore_failed>(
|
|
||||||
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<download_restore_failed>(
|
|
||||||
fsi.api_path, fsi.source_path,
|
|
||||||
"failed to get file size: " +
|
|
||||||
std::to_string(utils::get_last_error_code()));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
event_system::instance().raise<download_restore_failed>(
|
|
||||||
fsi.api_path, fsi.source_path,
|
|
||||||
"source path mismatch|expected|" + source_path + "|actual|" +
|
|
||||||
fsi.source_path);
|
fsi.source_path);
|
||||||
}
|
|
||||||
} else {
|
|
||||||
event_system::instance().raise<download_restore_failed>(
|
|
||||||
api_path, source_path,
|
|
||||||
"failed to get filesystem item|" + api_error_to_string(res));
|
|
||||||
}
|
|
||||||
} catch (const std::exception &ex) {
|
} catch (const std::exception &ex) {
|
||||||
utils::error::raise_error(function_name, ex, "query error");
|
utils::error::raise_error(function_name, ex, "query error");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user