diff --git a/include/providers/encrypt/encrypt_provider.hpp b/include/providers/encrypt/encrypt_provider.hpp index 57bd8d5d..519a192f 100644 --- a/include/providers/encrypt/encrypt_provider.hpp +++ b/include/providers/encrypt/encrypt_provider.hpp @@ -66,7 +66,7 @@ private: const api_file &file); auto do_directory_operation( - const std::string &api_path, + const std::string &api_path, bool directory, std::function callback) const -> api_error; diff --git a/src/providers/encrypt/encrypt_provider.cpp b/src/providers/encrypt/encrypt_provider.cpp index b60fcdca..22d2d7eb 100644 --- a/src/providers/encrypt/encrypt_provider.cpp +++ b/src/providers/encrypt/encrypt_provider.cpp @@ -170,23 +170,14 @@ auto encrypt_provider::create_directory(const std::string &api_path, } auto encrypt_provider::do_directory_operation( - const std::string &api_path, + const std::string &api_path, bool directory, std::function 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(); std::string source_path{api_path}; if (api_path != "/") { - res = + auto res = utils::encryption::decrypt_file_path(cfg.encryption_token, source_path); if (res != api_error::success) { return res; @@ -201,7 +192,20 @@ auto encrypt_provider::do_directory_operation( 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; } @@ -253,7 +257,7 @@ auto encrypt_provider::get_directory_item_count( std::uint64_t count{}; auto res = do_directory_operation( - api_path, + api_path, true, [&api_path, &count](const encrypt_config & /* cfg */, const std::string &source_path) -> api_error { try { @@ -282,7 +286,7 @@ auto encrypt_provider::get_directory_items(const std::string &api_path, static const auto *function_name = __FUNCTION__; return do_directory_operation( - api_path, + api_path, true, [this, &list](const encrypt_config &cfg, const std::string &source_path) -> api_error { try {