refactor
This commit is contained in:
parent
94675a3011
commit
f44972b8b3
@ -66,7 +66,7 @@ private:
|
|||||||
const api_file &file);
|
const api_file &file);
|
||||||
|
|
||||||
auto do_directory_operation(
|
auto do_directory_operation(
|
||||||
const std::string &api_path,
|
const std::string &api_path, bool directory,
|
||||||
std::function<api_error(const encrypt_config &cfg,
|
std::function<api_error(const encrypt_config &cfg,
|
||||||
const std::string &source_path)>
|
const std::string &source_path)>
|
||||||
callback) const -> api_error;
|
callback) const -> api_error;
|
||||||
|
@ -170,23 +170,14 @@ auto encrypt_provider::create_directory(const std::string &api_path,
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto encrypt_provider::do_directory_operation(
|
auto encrypt_provider::do_directory_operation(
|
||||||
const std::string &api_path,
|
const std::string &api_path, bool directory,
|
||||||
std::function<api_error(const encrypt_config &cfg,
|
std::function<api_error(const encrypt_config &cfg,
|
||||||
const std::string &source_path)>
|
const std::string &source_path)>
|
||||||
callback) const -> api_error {
|
callback) const -> api_error {
|
||||||
bool exists{};
|
|
||||||
auto res = is_file(api_path, exists);
|
|
||||||
if (res != api_error::success) {
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
if (exists) {
|
|
||||||
return api_error::item_exists;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto cfg = config_.get_encrypt_config();
|
auto cfg = config_.get_encrypt_config();
|
||||||
std::string source_path{api_path};
|
std::string source_path{api_path};
|
||||||
if (api_path != "/") {
|
if (api_path != "/") {
|
||||||
res =
|
auto res =
|
||||||
utils::encryption::decrypt_file_path(cfg.encryption_token, source_path);
|
utils::encryption::decrypt_file_path(cfg.encryption_token, source_path);
|
||||||
if (res != api_error::success) {
|
if (res != api_error::success) {
|
||||||
return res;
|
return res;
|
||||||
@ -201,7 +192,20 @@ auto encrypt_provider::do_directory_operation(
|
|||||||
return api_error::directory_not_found;
|
return api_error::directory_not_found;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (not utils::file::is_directory(source_path)) {
|
auto exists = utils::file::is_file(source_path);
|
||||||
|
if (exists && directory) {
|
||||||
|
return api_error::item_exists;
|
||||||
|
}
|
||||||
|
if (not exists && not directory) {
|
||||||
|
return api_error::item_not_found;
|
||||||
|
}
|
||||||
|
|
||||||
|
exists = utils::file::is_directory(source_path);
|
||||||
|
if (exists && not directory) {
|
||||||
|
return api_error::item_exists;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (not exists && directory) {
|
||||||
return api_error::directory_not_found;
|
return api_error::directory_not_found;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,7 +257,7 @@ auto encrypt_provider::get_directory_item_count(
|
|||||||
|
|
||||||
std::uint64_t count{};
|
std::uint64_t count{};
|
||||||
auto res = do_directory_operation(
|
auto res = do_directory_operation(
|
||||||
api_path,
|
api_path, true,
|
||||||
[&api_path, &count](const encrypt_config & /* cfg */,
|
[&api_path, &count](const encrypt_config & /* cfg */,
|
||||||
const std::string &source_path) -> api_error {
|
const std::string &source_path) -> api_error {
|
||||||
try {
|
try {
|
||||||
@ -282,7 +286,7 @@ auto encrypt_provider::get_directory_items(const std::string &api_path,
|
|||||||
static const auto *function_name = __FUNCTION__;
|
static const auto *function_name = __FUNCTION__;
|
||||||
|
|
||||||
return do_directory_operation(
|
return do_directory_operation(
|
||||||
api_path,
|
api_path, true,
|
||||||
[this, &list](const encrypt_config &cfg,
|
[this, &list](const encrypt_config &cfg,
|
||||||
const std::string &source_path) -> api_error {
|
const std::string &source_path) -> api_error {
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user