refactor
This commit is contained in:
@ -140,32 +140,32 @@ auto base_provider::create_directory(const std::string &api_path,
|
|||||||
api_meta_map &meta) -> api_error {
|
api_meta_map &meta) -> api_error {
|
||||||
REPERTORY_USES_FUNCTION_NAME();
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
bool exists{};
|
|
||||||
auto res = is_directory(api_path, exists);
|
|
||||||
if (res != api_error::success) {
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
if (exists) {
|
|
||||||
utils::error::raise_api_path_error(function_name, api_path,
|
|
||||||
api_error::directory_exists,
|
|
||||||
"failed to create directory");
|
|
||||||
return api_error::directory_exists;
|
|
||||||
}
|
|
||||||
|
|
||||||
res = is_file(api_path, exists);
|
|
||||||
if (res != api_error::success) {
|
|
||||||
utils::error::raise_api_path_error(function_name, api_path, res,
|
|
||||||
"failed to create directory");
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
if (exists) {
|
|
||||||
utils::error::raise_api_path_error(function_name, api_path,
|
|
||||||
api_error::item_exists,
|
|
||||||
"failed to create directory");
|
|
||||||
return api_error::item_exists;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
bool exists{};
|
||||||
|
auto res = is_directory(api_path, exists);
|
||||||
|
if (res != api_error::success) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
if (exists) {
|
||||||
|
utils::error::raise_api_path_error(function_name, api_path,
|
||||||
|
api_error::directory_exists,
|
||||||
|
"failed to create directory");
|
||||||
|
return api_error::directory_exists;
|
||||||
|
}
|
||||||
|
|
||||||
|
res = is_file(api_path, exists);
|
||||||
|
if (res != api_error::success) {
|
||||||
|
utils::error::raise_api_path_error(function_name, api_path, res,
|
||||||
|
"failed to create directory");
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
if (exists) {
|
||||||
|
utils::error::raise_api_path_error(function_name, api_path,
|
||||||
|
api_error::item_exists,
|
||||||
|
"failed to create directory");
|
||||||
|
return api_error::item_exists;
|
||||||
|
}
|
||||||
|
|
||||||
res = create_directory_impl(api_path, meta);
|
res = create_directory_impl(api_path, meta);
|
||||||
if (res != api_error::success) {
|
if (res != api_error::success) {
|
||||||
utils::error::raise_api_path_error(function_name, api_path, res,
|
utils::error::raise_api_path_error(function_name, api_path, res,
|
||||||
@ -186,30 +186,30 @@ auto base_provider::create_file(const std::string &api_path, api_meta_map &meta)
|
|||||||
-> api_error {
|
-> api_error {
|
||||||
REPERTORY_USES_FUNCTION_NAME();
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
bool exists{};
|
|
||||||
auto res = is_directory(api_path, exists);
|
|
||||||
if (res != api_error::success && res != api_error::item_not_found) {
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
if (exists) {
|
|
||||||
utils::error::raise_api_path_error(function_name, api_path,
|
|
||||||
api_error::directory_exists,
|
|
||||||
"failed to create file");
|
|
||||||
return api_error::directory_exists;
|
|
||||||
}
|
|
||||||
|
|
||||||
res = is_file(api_path, exists);
|
|
||||||
if (res != api_error::success && res != api_error::item_not_found) {
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
if (exists) {
|
|
||||||
utils::error::raise_api_path_error(function_name, api_path,
|
|
||||||
api_error::item_exists,
|
|
||||||
"failed to create file");
|
|
||||||
return api_error::item_exists;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
bool exists{};
|
||||||
|
auto res = is_directory(api_path, exists);
|
||||||
|
if (res != api_error::success && res != api_error::item_not_found) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
if (exists) {
|
||||||
|
utils::error::raise_api_path_error(function_name, api_path,
|
||||||
|
api_error::directory_exists,
|
||||||
|
"failed to create file");
|
||||||
|
return api_error::directory_exists;
|
||||||
|
}
|
||||||
|
|
||||||
|
res = is_file(api_path, exists);
|
||||||
|
if (res != api_error::success && res != api_error::item_not_found) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
if (exists) {
|
||||||
|
utils::error::raise_api_path_error(function_name, api_path,
|
||||||
|
api_error::item_exists,
|
||||||
|
"failed to create file");
|
||||||
|
return api_error::item_exists;
|
||||||
|
}
|
||||||
|
|
||||||
res = create_file_extra(api_path, meta);
|
res = create_file_extra(api_path, meta);
|
||||||
if (res != api_error::success) {
|
if (res != api_error::success) {
|
||||||
utils::error::raise_api_path_error(function_name, api_path, res,
|
utils::error::raise_api_path_error(function_name, api_path, res,
|
||||||
@ -260,16 +260,16 @@ auto base_provider::get_directory_items(const std::string &api_path,
|
|||||||
-> api_error {
|
-> api_error {
|
||||||
REPERTORY_USES_FUNCTION_NAME();
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
bool exists{};
|
|
||||||
auto res = is_directory(api_path, exists);
|
|
||||||
if (res != api_error::success) {
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
if (not exists) {
|
|
||||||
return api_error::directory_not_found;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
bool exists{};
|
||||||
|
auto res = is_directory(api_path, exists);
|
||||||
|
if (res != api_error::success) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
if (not exists) {
|
||||||
|
return api_error::directory_not_found;
|
||||||
|
}
|
||||||
|
|
||||||
res = get_directory_items_impl(api_path, list);
|
res = get_directory_items_impl(api_path, list);
|
||||||
if (res != api_error::success) {
|
if (res != api_error::success) {
|
||||||
return res;
|
return res;
|
||||||
@ -783,16 +783,17 @@ auto base_provider::upload_file(const std::string &api_path,
|
|||||||
stop_type &stop_requested) -> api_error {
|
stop_type &stop_requested) -> api_error {
|
||||||
REPERTORY_USES_FUNCTION_NAME();
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
event_system::instance().raise<provider_upload_begin>(api_path, source_path);
|
|
||||||
|
|
||||||
const auto notify_end = [&api_path,
|
|
||||||
&source_path](api_error error) -> api_error {
|
|
||||||
event_system::instance().raise<provider_upload_end>(api_path, source_path,
|
|
||||||
error);
|
|
||||||
return error;
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
event_system::instance().raise<provider_upload_begin>(api_path,
|
||||||
|
source_path);
|
||||||
|
|
||||||
|
const auto notify_end = [&api_path,
|
||||||
|
&source_path](api_error error) -> api_error {
|
||||||
|
event_system::instance().raise<provider_upload_end>(api_path, source_path,
|
||||||
|
error);
|
||||||
|
return error;
|
||||||
|
};
|
||||||
|
|
||||||
return notify_end(upload_file_impl(api_path, source_path, stop_requested));
|
return notify_end(upload_file_impl(api_path, source_path, stop_requested));
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
utils::error::raise_error(function_name, e, "exception occurred");
|
utils::error::raise_error(function_name, e, "exception occurred");
|
||||||
|
Reference in New Issue
Block a user