extract common behavior
This commit is contained in:
@@ -114,6 +114,106 @@ auto base_provider::create_directory_clone_source_meta(
|
||||
return create_directory(api_path, meta);
|
||||
}
|
||||
|
||||
auto base_provider::create_directory(const std::string &api_path,
|
||||
api_meta_map &meta) -> api_error {
|
||||
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__, 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__, api_path, res,
|
||||
"failed to create directory");
|
||||
return res;
|
||||
}
|
||||
if (exists) {
|
||||
utils::error::raise_api_path_error(__FUNCTION__, api_path,
|
||||
api_error::item_exists,
|
||||
"failed to create directory");
|
||||
return api_error::item_exists;
|
||||
}
|
||||
|
||||
try {
|
||||
res = create_directory_impl(api_path, meta);
|
||||
if (res != api_error::success) {
|
||||
utils::error::raise_api_path_error(__FUNCTION__, api_path, res,
|
||||
"failed to create directory");
|
||||
return res;
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
utils::error::raise_api_path_error(__FUNCTION__, api_path, e,
|
||||
"failed to create directory");
|
||||
return api_error::error;
|
||||
}
|
||||
|
||||
meta[META_DIRECTORY] = utils::string::from_bool(true);
|
||||
return set_item_meta(api_path, meta);
|
||||
}
|
||||
|
||||
auto base_provider::create_file(const std::string &api_path, api_meta_map &meta)
|
||||
-> api_error {
|
||||
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__, 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__, api_path,
|
||||
api_error::item_exists,
|
||||
"failed to create file");
|
||||
return api_error::item_exists;
|
||||
}
|
||||
|
||||
try {
|
||||
res = create_file_extra(api_path, meta);
|
||||
if (res != api_error::success) {
|
||||
utils::error::raise_api_path_error(__FUNCTION__, api_path, res,
|
||||
"failed to create file");
|
||||
return res;
|
||||
}
|
||||
|
||||
meta[META_DIRECTORY] = utils::string::from_bool(false);
|
||||
res = set_item_meta(api_path, meta);
|
||||
if (res != api_error::success) {
|
||||
utils::error::raise_api_path_error(__FUNCTION__, api_path, res,
|
||||
"failed to create file");
|
||||
return res;
|
||||
}
|
||||
|
||||
stop_type stop_requested{false};
|
||||
res = upload_file(api_path, meta[META_SOURCE], stop_requested);
|
||||
if (res != api_error::success) {
|
||||
get_db()->Delete(rocksdb::WriteOptions(), api_path);
|
||||
}
|
||||
|
||||
return res;
|
||||
} catch (const std::exception &e) {
|
||||
utils::error::raise_api_path_error(__FUNCTION__, api_path, e,
|
||||
"failed to create file");
|
||||
}
|
||||
|
||||
return api_error::error;
|
||||
}
|
||||
|
||||
auto base_provider::get_api_path_from_source(const std::string &source_path,
|
||||
std::string &api_path) const
|
||||
-> api_error {
|
||||
|
Reference in New Issue
Block a user