error handling
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good

This commit is contained in:
2024-08-30 11:37:37 -05:00
parent 303420406b
commit dffd718b5b
2 changed files with 90 additions and 54 deletions

View File

@ -83,7 +83,11 @@ auto encrypt_provider::create_api_file(
file.api_parent = utils::path::get_parent_api_path(api_path);
file.changed_date = times->get(utils::file::time_type::modified);
file.creation_date = times->get(utils::file::time_type::created);
file.file_size = directory ? 0U : utils::encryption::encrypting_reader::calculate_encrypted_size( source_path);
file.file_size =
directory
? 0U
: utils::encryption::encrypting_reader::calculate_encrypted_size(
source_path);
file.modified_date = times->get(utils::file::time_type::written);
file.source_path = source_path;
@ -369,6 +373,11 @@ auto encrypt_provider::get_directory_items(
auto encrypt_provider::get_file(const std::string &api_path,
api_file &file) const -> api_error {
static constexpr const std::string_view function_name{
static_cast<const char *>(__FUNCTION__),
};
try {
bool exists{};
auto res = is_directory(api_path, exists);
if (res != api_error::success) {
@ -389,8 +398,15 @@ auto encrypt_provider::get_file(const std::string &api_path,
}
file = create_api_file(
api_path, false, row->get_column("source_path").get_value<std::string>());
api_path, false,
row->get_column("source_path").get_value<std::string>());
return api_error::success;
} catch (const std::exception &ex) {
utils::error::raise_error(function_name, ex, api_path,
"failed to get file");
}
return api_error::error;
}
auto encrypt_provider::get_file_list(api_file_list &list) const -> api_error {
@ -530,6 +546,11 @@ auto encrypt_provider::get_filesystem_item_from_source_path(
auto encrypt_provider::get_filesystem_item_and_file(
const std::string &api_path, api_file &file,
filesystem_item &fsi) const -> api_error {
static constexpr const std::string_view function_name{
static_cast<const char *>(__FUNCTION__),
};
try {
bool exists{};
auto res = is_directory(api_path, exists);
if (res != api_error::success) {
@ -546,6 +567,12 @@ auto encrypt_provider::get_filesystem_item_and_file(
file = create_api_file(api_path, false, fsi.source_path);
return api_error::success;
} catch (const std::exception &ex) {
utils::error::raise_error(function_name, ex, api_path,
"failed to get filesystem_item and file");
}
return api_error::error;
}
auto encrypt_provider::get_pinned_files() const -> std::vector<std::string> {
@ -558,6 +585,7 @@ auto encrypt_provider::get_item_meta(const std::string &api_path,
static_cast<const char *>(__FUNCTION__),
};
try {
auto result = db::db_select{*db_, source_table}
.column("source_path")
.where("api_path")
@ -579,6 +607,12 @@ auto encrypt_provider::get_item_meta(const std::string &api_path,
auto file = create_api_file(api_path, exists, source_path);
create_item_meta(meta, exists, file);
return api_error::success;
} catch (const std::exception &ex) {
utils::error::raise_error(function_name, ex, api_path,
"failed to get item meta");
}
return api_error::error;
}
auto encrypt_provider::get_item_meta(const std::string &api_path,

View File

@ -89,6 +89,8 @@ auto get_times(std::string_view path) -> std::optional<file_times> {
ret.written = static_cast<std::uint64_t>(
st.st_mtim.tv_nsec + st.st_mtim.tv_sec * utils::time::NANOS_PER_SECOND);
#endif // defined(_WIN32)
return ret;
} catch (const std::exception &e) {
utils::error::handle_exception(function_name, e);
} catch (...) {