Compare commits
5 Commits
67fe189765
...
b865c9300b
Author | SHA1 | Date | |
---|---|---|---|
b865c9300b | |||
8df55fcda5 | |||
7d9dc52ba7 | |||
dd75db3be3 | |||
ad820dcc27 |
@ -40,6 +40,7 @@
|
||||
#include "utils/file_utils.hpp"
|
||||
#include "utils/path.hpp"
|
||||
#include "utils/polling.hpp"
|
||||
#include <spdlog/fmt/bundled/base.h>
|
||||
|
||||
namespace repertory {
|
||||
encrypt_provider::encrypt_provider(app_config &config)
|
||||
@ -342,13 +343,23 @@ auto encrypt_provider::get_file_list(api_file_list &list,
|
||||
const auto &cfg{get_encrypt_config()};
|
||||
|
||||
try {
|
||||
for (const auto &dir_entry : utils::file::directory{cfg.path}.get_items()) {
|
||||
std::string api_path{};
|
||||
if (process_directory_entry(*dir_entry.get(), cfg, api_path)) {
|
||||
list.emplace_back(create_api_file(
|
||||
api_path, dir_entry->is_directory_item(), dir_entry->get_path()));
|
||||
using func = std::function<void(std::string path)>;
|
||||
const func process_directory = [&](std::string path) {
|
||||
for (const auto &dir_entry : utils::file::directory{path}.get_items()) {
|
||||
std::string api_path{};
|
||||
if (dir_entry->is_directory_item()) {
|
||||
process_directory_entry(*dir_entry.get(), cfg, api_path);
|
||||
process_directory(dir_entry->get_path());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (process_directory_entry(*dir_entry.get(), cfg, api_path)) {
|
||||
list.emplace_back(create_api_file(
|
||||
api_path, dir_entry->is_directory_item(), dir_entry->get_path()));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
process_directory(cfg.path);
|
||||
|
||||
return api_error::success;
|
||||
} catch (const std::exception &ex) {
|
||||
|
@ -19,8 +19,6 @@
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#if 0
|
||||
|
||||
#include "test_common.hpp"
|
||||
|
||||
#include "comm/curl/curl_comm.hpp"
|
||||
@ -37,6 +35,7 @@
|
||||
#include "utils/string.hpp"
|
||||
#include "utils/time.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
#include <spdlog/fmt/bundled/base.h>
|
||||
|
||||
namespace {
|
||||
#if defined(_WIN32)
|
||||
@ -99,8 +98,6 @@ const auto create_directory = [](repertory::i_provider &provider,
|
||||
repertory::utils::string::to_bool(meta2[repertory::META_PINNED]));
|
||||
EXPECT_EQ(std::uint64_t(0U),
|
||||
repertory::utils::string::to_uint64(meta2[repertory::META_SIZE]));
|
||||
EXPECT_STREQ((api_path + "_src").c_str(),
|
||||
meta2[repertory::META_SOURCE].c_str());
|
||||
EXPECT_EQ(getuid(), static_cast<uid_t>(repertory::utils::string::to_uint32(
|
||||
meta2[repertory::META_UID])));
|
||||
EXPECT_EQ(date + 4U, repertory::utils::string::to_uint64(
|
||||
@ -178,6 +175,9 @@ const auto decrypt_parts = [](const repertory::app_config &cfg,
|
||||
|
||||
namespace repertory {
|
||||
static void can_create_and_remove_directory(i_provider &provider) {
|
||||
fmt::println("testing|{}|{}",
|
||||
app_config::get_provider_name(provider.get_provider_type()),
|
||||
__FUNCTION__);
|
||||
if (provider.is_read_only()) {
|
||||
api_meta_map meta{};
|
||||
EXPECT_EQ(api_error::not_implemented,
|
||||
@ -196,6 +196,9 @@ static void can_create_and_remove_directory(i_provider &provider) {
|
||||
}
|
||||
|
||||
static void create_directory_fails_if_already_exists(i_provider &provider) {
|
||||
fmt::println("testing|{}|{}",
|
||||
app_config::get_provider_name(provider.get_provider_type()),
|
||||
__FUNCTION__);
|
||||
if (provider.is_read_only()) {
|
||||
return;
|
||||
}
|
||||
@ -210,6 +213,9 @@ static void create_directory_fails_if_already_exists(i_provider &provider) {
|
||||
|
||||
static void
|
||||
create_directory_fails_if_file_already_exists(i_provider &provider) {
|
||||
fmt::println("testing|{}|{}",
|
||||
app_config::get_provider_name(provider.get_provider_type()),
|
||||
__FUNCTION__);
|
||||
if (provider.is_read_only()) {
|
||||
return;
|
||||
}
|
||||
@ -223,6 +229,9 @@ create_directory_fails_if_file_already_exists(i_provider &provider) {
|
||||
}
|
||||
|
||||
static void create_directory_clone_source_meta(i_provider &provider) {
|
||||
fmt::println("testing|{}|{}",
|
||||
app_config::get_provider_name(provider.get_provider_type()),
|
||||
__FUNCTION__);
|
||||
if (provider.is_read_only()) {
|
||||
EXPECT_EQ(api_error::not_implemented,
|
||||
provider.create_directory_clone_source_meta("/moose", "/moose"));
|
||||
@ -257,6 +266,9 @@ static void create_directory_clone_source_meta(i_provider &provider) {
|
||||
|
||||
static void create_directory_clone_source_meta_fails_if_already_exists(
|
||||
i_provider &provider) {
|
||||
fmt::println("testing|{}|{}",
|
||||
app_config::get_provider_name(provider.get_provider_type()),
|
||||
__FUNCTION__);
|
||||
if (provider.is_read_only()) {
|
||||
return;
|
||||
}
|
||||
@ -272,6 +284,9 @@ static void create_directory_clone_source_meta_fails_if_already_exists(
|
||||
|
||||
static void create_directory_clone_source_meta_fails_if_directory_not_found(
|
||||
i_provider &provider) {
|
||||
fmt::println("testing|{}|{}",
|
||||
app_config::get_provider_name(provider.get_provider_type()),
|
||||
__FUNCTION__);
|
||||
if (provider.is_read_only()) {
|
||||
return;
|
||||
}
|
||||
@ -282,6 +297,9 @@ static void create_directory_clone_source_meta_fails_if_directory_not_found(
|
||||
|
||||
static void create_directory_clone_source_meta_fails_if_file_already_exists(
|
||||
i_provider &provider) {
|
||||
fmt::println("testing|{}|{}",
|
||||
app_config::get_provider_name(provider.get_provider_type()),
|
||||
__FUNCTION__);
|
||||
if (provider.is_read_only()) {
|
||||
return;
|
||||
}
|
||||
@ -297,6 +315,9 @@ static void create_directory_clone_source_meta_fails_if_file_already_exists(
|
||||
}
|
||||
|
||||
static void can_create_and_remove_file(i_provider &provider) {
|
||||
fmt::println("testing|{}|{}",
|
||||
app_config::get_provider_name(provider.get_provider_type()),
|
||||
__FUNCTION__);
|
||||
if (provider.is_read_only()) {
|
||||
api_meta_map meta{};
|
||||
EXPECT_EQ(api_error::not_implemented,
|
||||
@ -317,6 +338,9 @@ static void can_create_and_remove_file(i_provider &provider) {
|
||||
}
|
||||
|
||||
static void create_file_fails_if_already_exists(i_provider &provider) {
|
||||
fmt::println("testing|{}|{}",
|
||||
app_config::get_provider_name(provider.get_provider_type()),
|
||||
__FUNCTION__);
|
||||
if (provider.is_read_only()) {
|
||||
return;
|
||||
}
|
||||
@ -331,6 +355,9 @@ static void create_file_fails_if_already_exists(i_provider &provider) {
|
||||
|
||||
static void
|
||||
create_file_fails_if_directory_already_exists(i_provider &provider) {
|
||||
fmt::println("testing|{}|{}",
|
||||
app_config::get_provider_name(provider.get_provider_type()),
|
||||
__FUNCTION__);
|
||||
if (provider.is_read_only()) {
|
||||
return;
|
||||
}
|
||||
@ -345,9 +372,12 @@ create_file_fails_if_directory_already_exists(i_provider &provider) {
|
||||
|
||||
static void get_api_path_from_source(const app_config &cfg,
|
||||
i_provider &provider) {
|
||||
fmt::println("testing|{}|{}",
|
||||
app_config::get_provider_name(provider.get_provider_type()),
|
||||
__FUNCTION__);
|
||||
if (provider.get_provider_type() == provider_type::encrypt) {
|
||||
const auto source_path =
|
||||
utils::path::combine("./test_date/encrypt", {"test.txt"});
|
||||
auto source_path =
|
||||
utils::path::combine("./test_input/encrypt", {"test.txt"});
|
||||
|
||||
std::string api_path{};
|
||||
EXPECT_EQ(api_error::success,
|
||||
@ -376,6 +406,9 @@ static void get_api_path_from_source(const app_config &cfg,
|
||||
static void
|
||||
get_api_path_from_source_fails_if_file_not_found(const app_config &cfg,
|
||||
i_provider &provider) {
|
||||
fmt::println("testing|{}|{}",
|
||||
app_config::get_provider_name(provider.get_provider_type()),
|
||||
__FUNCTION__);
|
||||
std::string source_path{};
|
||||
if (provider.get_provider_type() == provider_type::encrypt) {
|
||||
source_path = utils::path::combine(cfg.get_encrypt_config().path,
|
||||
@ -391,13 +424,16 @@ get_api_path_from_source_fails_if_file_not_found(const app_config &cfg,
|
||||
EXPECT_TRUE(api_path.empty());
|
||||
}
|
||||
|
||||
static void get_directory_item_count(const app_config &cfg,
|
||||
static void get_directory_item_count(const app_config & /* cfg */,
|
||||
i_provider &provider) {
|
||||
fmt::println("testing|{}|{}",
|
||||
app_config::get_provider_name(provider.get_provider_type()),
|
||||
__FUNCTION__);
|
||||
if (provider.get_provider_type() == provider_type::encrypt) {
|
||||
EXPECT_EQ(std::size_t(2U), provider.get_directory_item_count("/"));
|
||||
EXPECT_EQ(std::size_t(0U), provider.get_directory_item_count("/not_found"));
|
||||
|
||||
const auto source_path =
|
||||
auto source_path =
|
||||
utils::path::combine(test::get_test_input_dir(), {"encrypt", "sub10"});
|
||||
|
||||
std::string api_path{};
|
||||
@ -408,6 +444,9 @@ static void get_directory_item_count(const app_config &cfg,
|
||||
}
|
||||
|
||||
static void get_directory_items(const app_config &cfg, i_provider &provider) {
|
||||
fmt::println("testing|{}|{}",
|
||||
app_config::get_provider_name(provider.get_provider_type()),
|
||||
__FUNCTION__);
|
||||
directory_item_list list{};
|
||||
EXPECT_EQ(api_error::success, provider.get_directory_items("/", list));
|
||||
check_forced_dirs(list);
|
||||
@ -443,7 +482,7 @@ static void get_directory_items(const app_config &cfg, i_provider &provider) {
|
||||
EXPECT_EQ(std::size_t(46U), file->size);
|
||||
#endif
|
||||
|
||||
const auto source_path =
|
||||
auto source_path =
|
||||
utils::path::combine(cfg.get_encrypt_config().path, {"sub10"});
|
||||
std::string api_path{};
|
||||
EXPECT_EQ(api_error::success,
|
||||
@ -477,6 +516,9 @@ static void get_directory_items(const app_config &cfg, i_provider &provider) {
|
||||
|
||||
static void
|
||||
get_directory_items_fails_if_directory_not_found(i_provider &provider) {
|
||||
fmt::println("testing|{}|{}",
|
||||
app_config::get_provider_name(provider.get_provider_type()),
|
||||
__FUNCTION__);
|
||||
directory_item_list list{};
|
||||
EXPECT_EQ(api_error::directory_not_found,
|
||||
provider.get_directory_items("/not_found", list));
|
||||
@ -485,8 +527,11 @@ get_directory_items_fails_if_directory_not_found(i_provider &provider) {
|
||||
|
||||
static void get_directory_items_fails_if_item_is_file(const app_config &cfg,
|
||||
i_provider &provider) {
|
||||
fmt::println("testing|{}|{}",
|
||||
app_config::get_provider_name(provider.get_provider_type()),
|
||||
__FUNCTION__);
|
||||
if (provider.get_provider_type() == provider_type::encrypt) {
|
||||
const auto source_path =
|
||||
auto source_path =
|
||||
utils::path::combine(cfg.get_encrypt_config().path, {"test.txt"});
|
||||
|
||||
std::string api_path{};
|
||||
@ -501,8 +546,11 @@ static void get_directory_items_fails_if_item_is_file(const app_config &cfg,
|
||||
}
|
||||
|
||||
static void get_file(const app_config &cfg, i_provider &provider) {
|
||||
fmt::println("testing|{}|{}",
|
||||
app_config::get_provider_name(provider.get_provider_type()),
|
||||
__FUNCTION__);
|
||||
if (provider.get_provider_type() == provider_type::encrypt) {
|
||||
const auto source_path =
|
||||
auto source_path =
|
||||
utils::path::combine(cfg.get_encrypt_config().path, {"test.txt"});
|
||||
|
||||
std::string api_path{};
|
||||
@ -526,14 +574,20 @@ static void get_file(const app_config &cfg, i_provider &provider) {
|
||||
}
|
||||
|
||||
static void get_file_fails_if_file_not_found(i_provider &provider) {
|
||||
fmt::println("testing|{}|{}",
|
||||
app_config::get_provider_name(provider.get_provider_type()),
|
||||
__FUNCTION__);
|
||||
api_file file{};
|
||||
EXPECT_EQ(api_error::item_not_found, provider.get_file("/not_found", file));
|
||||
}
|
||||
|
||||
static void get_file_fails_if_item_is_directory(const app_config &cfg,
|
||||
i_provider &provider) {
|
||||
fmt::println("testing|{}|{}",
|
||||
app_config::get_provider_name(provider.get_provider_type()),
|
||||
__FUNCTION__);
|
||||
if (provider.get_provider_type() == provider_type::encrypt) {
|
||||
const auto source_path =
|
||||
auto source_path =
|
||||
utils::path::combine(cfg.get_encrypt_config().path, {"sub10"});
|
||||
|
||||
std::string api_path{};
|
||||
@ -630,16 +684,15 @@ static void run_tests(const app_config &cfg, i_provider &provider) {
|
||||
}
|
||||
|
||||
TEST(providers_test, encrypt_provider) {
|
||||
const auto config_path =
|
||||
utils::path::combine(test::get_test_output_dir(), {"encrypt_provider"});
|
||||
|
||||
auto config_path = utils::path::combine(test::get_test_output_dir(),
|
||||
{"provider", "encrypt"});
|
||||
console_consumer consumer{};
|
||||
event_system::instance().start();
|
||||
|
||||
{
|
||||
app_config cfg(provider_type::encrypt, config_path);
|
||||
|
||||
const auto encrypt_path =
|
||||
auto encrypt_path =
|
||||
utils::path::combine(test::get_test_input_dir(), {"encrypt"});
|
||||
|
||||
EXPECT_STREQ(
|
||||
@ -674,8 +727,8 @@ TEST(providers_test, encrypt_provider) {
|
||||
}
|
||||
|
||||
TEST(providers_test, s3_provider) {
|
||||
const auto config_path =
|
||||
utils::path::combine(test::get_test_output_dir(), {"s3_provider"});
|
||||
auto config_path =
|
||||
utils::path::combine(test::get_test_output_dir(), {"provider", "s3"});
|
||||
|
||||
console_consumer consumer{};
|
||||
event_system::instance().start();
|
||||
@ -685,7 +738,7 @@ TEST(providers_test, s3_provider) {
|
||||
{
|
||||
app_config src_cfg(
|
||||
provider_type::s3,
|
||||
utils::path::combine(test::get_test_config_dir(), {"storj"}));
|
||||
utils::path::combine(test::get_test_config_dir(), {"s3"}));
|
||||
cfg.set_s3_config(src_cfg.get_s3_config());
|
||||
}
|
||||
|
||||
@ -714,8 +767,8 @@ TEST(providers_test, s3_provider) {
|
||||
}
|
||||
|
||||
TEST(providers_test, sia_provider) {
|
||||
const auto config_path =
|
||||
utils::path::combine(test::get_test_output_dir(), {"sia_provider"});
|
||||
auto config_path =
|
||||
utils::path::combine(test::get_test_output_dir(), {"sia", "provider"});
|
||||
|
||||
console_consumer consumer{};
|
||||
event_system::instance().start();
|
||||
@ -753,5 +806,3 @@ TEST(providers_test, sia_provider) {
|
||||
event_system::instance().stop();
|
||||
}
|
||||
} // namespace repertory
|
||||
|
||||
#endif // 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user