v2.0.3-rc (#32)
Some checks reported errors
BlockStorage/repertory/pipeline/head Something is wrong with the build of this commit
Some checks reported errors
BlockStorage/repertory/pipeline/head Something is wrong with the build of this commit
# Changelog ## v2.0.3-rc ### Issues * \#28 \[bug\] Address slow directory responses in S3 mounts for deeply nested directories * \#29 \[bug\] S3 error responses are not being logged * \#30 \[bug\] Sia provider error responses are not logged * \#31 \[bug\] S3 provider should limit max key size to 1024 ### Changes from v2.0.2-rc * Always use direct for read-only providers * Fixed externally removed files not being processed during cleanup * Fixed http headers not being added for requests * Fixed incorrect `stat` values for remote mounts * Fixed invalid directory nullptr error on remote mounts * Fixed memory leak in event system * Refactored application shutdown * Refactored event system * Updated build system to Alpine 3.21.0 * Updated build system to MinGW-w64 12.0.0 * Updated copyright to 2018-2025 Reviewed-on: #32
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -42,6 +42,7 @@ protected:
|
||||
static std::uint64_t idx{};
|
||||
|
||||
event_system::instance().start();
|
||||
|
||||
auto cfg_directory = utils::path::combine(test::get_test_output_dir(),
|
||||
{
|
||||
"file_db_test",
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -42,6 +42,7 @@ protected:
|
||||
static std::uint64_t idx{};
|
||||
|
||||
event_system::instance().start();
|
||||
|
||||
auto cfg_directory = utils::path::combine(test::get_test_output_dir(),
|
||||
{
|
||||
"file_mgr_db_test",
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -45,7 +45,8 @@
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
std::atomic<std::size_t> idx{0U};
|
||||
std::atomic<std::size_t> provider_idx{0U};
|
||||
|
||||
constexpr const auto SLEEP_SECONDS{1.5s};
|
||||
} // namespace
|
||||
|
||||
@@ -126,6 +127,7 @@ protected:
|
||||
});
|
||||
}
|
||||
|
||||
config->set_database_type(database_type::sqlite);
|
||||
meta = create_meta_db(*config);
|
||||
execute_mount(drive_args, mount_location);
|
||||
};
|
||||
@@ -171,6 +173,7 @@ protected:
|
||||
});
|
||||
}
|
||||
|
||||
config->set_database_type(database_type::sqlite);
|
||||
meta = create_meta_db(*config);
|
||||
execute_mount(drive_args, mount_location);
|
||||
};
|
||||
@@ -197,6 +200,7 @@ protected:
|
||||
std::make_unique<app_config>(provider_type::remote, cfg_directory);
|
||||
config2->set_enable_drive_events(true);
|
||||
config2->set_event_level(event_level::trace);
|
||||
config2->set_database_type(database_type::sqlite);
|
||||
|
||||
drive_args2 = std::vector<std::string>({
|
||||
"-dd",
|
||||
@@ -259,14 +263,14 @@ protected:
|
||||
|
||||
public:
|
||||
static auto create_file_path(std::string &file_name) {
|
||||
file_name += std::to_string(++idx);
|
||||
file_name += std::to_string(++provider_idx);
|
||||
auto file_path = utils::path::combine(mount_location, {file_name});
|
||||
return file_path;
|
||||
}
|
||||
|
||||
static auto create_file_and_test(std::string &file_name, mode_t perms)
|
||||
-> std::string {
|
||||
file_name += std::to_string(++idx);
|
||||
static auto create_file_and_test(std::string &file_name,
|
||||
mode_t perms) -> std::string {
|
||||
file_name += std::to_string(++provider_idx);
|
||||
auto file_path = utils::path::combine(mount_location, {file_name});
|
||||
|
||||
auto handle = open(file_path.c_str(), O_CREAT | O_EXCL | O_RDWR, perms);
|
||||
@@ -283,7 +287,7 @@ public:
|
||||
EXPECT_TRUE(utils::file::file(file_path).exists());
|
||||
EXPECT_FALSE(utils::file::directory(file_path).exists());
|
||||
|
||||
struct stat64 unix_st{};
|
||||
struct stat64 unix_st {};
|
||||
EXPECT_EQ(0, stat64(file_path.c_str(), &unix_st));
|
||||
EXPECT_EQ(getgid(), unix_st.st_gid);
|
||||
EXPECT_EQ(getuid(), unix_st.st_uid);
|
||||
@@ -295,9 +299,9 @@ public:
|
||||
return create_file_and_test(file_name, ACCESSPERMS);
|
||||
}
|
||||
|
||||
static auto create_directory_and_test(std::string &dir_name, mode_t perms)
|
||||
-> std::string {
|
||||
dir_name += std::to_string(++idx);
|
||||
static auto create_directory_and_test(std::string &dir_name,
|
||||
mode_t perms) -> std::string {
|
||||
dir_name += std::to_string(++provider_idx);
|
||||
|
||||
auto dir_path = utils::path::combine(mount_location, {dir_name});
|
||||
mkdir(dir_path.c_str(), perms);
|
||||
@@ -305,7 +309,7 @@ public:
|
||||
EXPECT_TRUE(utils::file::directory(dir_path).exists());
|
||||
EXPECT_FALSE(utils::file::file(dir_path).exists());
|
||||
|
||||
struct stat64 unix_st{};
|
||||
struct stat64 unix_st {};
|
||||
EXPECT_EQ(0, stat64(dir_path.c_str(), &unix_st));
|
||||
EXPECT_EQ(getgid(), unix_st.st_gid);
|
||||
EXPECT_EQ(getuid(), unix_st.st_uid);
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -42,6 +42,7 @@ protected:
|
||||
static std::uint64_t idx{};
|
||||
|
||||
event_system::instance().start();
|
||||
|
||||
auto cfg_directory = utils::path::combine(test::get_test_output_dir(),
|
||||
{
|
||||
"meta_db_test",
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -42,9 +42,8 @@ private:
|
||||
std::string mount_location_;
|
||||
|
||||
public:
|
||||
[[nodiscard]] auto
|
||||
get_directory_item_count(const std::string & /*api_path*/) const
|
||||
-> std::uint64_t override {
|
||||
[[nodiscard]] auto get_directory_item_count(
|
||||
const std::string & /*api_path*/) const -> std::uint64_t override {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -85,10 +84,10 @@ public:
|
||||
return api_error::error;
|
||||
}
|
||||
|
||||
auto get_security_by_name(PWSTR /*file_name*/, PUINT32 attributes,
|
||||
PSECURITY_DESCRIPTOR descriptor,
|
||||
std::uint64_t *descriptor_size)
|
||||
-> NTSTATUS override {
|
||||
auto
|
||||
get_security_by_name(PWSTR /*file_name*/, PUINT32 attributes,
|
||||
PSECURITY_DESCRIPTOR descriptor,
|
||||
std::uint64_t *descriptor_size) -> NTSTATUS override {
|
||||
auto ret = STATUS_SUCCESS;
|
||||
|
||||
if (attributes != nullptr) {
|
||||
@@ -135,9 +134,9 @@ public:
|
||||
volume_label = "TestVolumeLabel";
|
||||
}
|
||||
|
||||
auto populate_file_info(const std::string &api_path,
|
||||
remote::file_info &file_info) const
|
||||
-> api_error override {
|
||||
auto
|
||||
populate_file_info(const std::string &api_path,
|
||||
remote::file_info &file_info) const -> api_error override {
|
||||
auto file_path = utils::path::combine(mount_location_, {api_path});
|
||||
auto directory = utils::file::directory(file_path).exists();
|
||||
auto attributes =
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -28,6 +28,6 @@ REPERTORY_IGNORE_WARNINGS_DISABLE()
|
||||
|
||||
#include "events/consumers/console_consumer.hpp"
|
||||
#include "events/event_system.hpp"
|
||||
#include "events/events.hpp"
|
||||
#include "events/i_event.hpp"
|
||||
|
||||
#endif // REPERTORY_TEST_INCLUDE_TEST_COMMON_HPP_
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -32,8 +32,9 @@ class event_capture final {
|
||||
E_CONSUMER();
|
||||
|
||||
public:
|
||||
explicit event_capture(std::vector<std::string> event_names,
|
||||
std::vector<std::string> non_fired_event_names = {})
|
||||
explicit event_capture(
|
||||
std::vector<std::string_view> event_names,
|
||||
std::vector<std::string_view> non_fired_event_names = {})
|
||||
: event_names_(std::move(event_names)),
|
||||
non_fired_event_names_(std::move(non_fired_event_names)) {
|
||||
E_SUBSCRIBE_ALL(process_event);
|
||||
@@ -51,56 +52,55 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<std::string> event_names_;
|
||||
std::vector<std::string> fired_event_names_;
|
||||
std::vector<std::string> non_fired_event_names_;
|
||||
std::vector<std::string_view> event_names_;
|
||||
std::vector<std::string_view> fired_event_names_;
|
||||
std::vector<std::string_view> non_fired_event_names_;
|
||||
std::mutex mutex_;
|
||||
std::condition_variable notify_;
|
||||
|
||||
public:
|
||||
void process_event(const event &event) {
|
||||
unique_mutex_lock l(mutex_);
|
||||
void process_event(const i_event &event) {
|
||||
unique_mutex_lock lock(mutex_);
|
||||
utils::collection::remove_element(event_names_, event.get_name());
|
||||
fired_event_names_.emplace_back(event.get_name());
|
||||
notify_.notify_all();
|
||||
l.unlock();
|
||||
lock.unlock();
|
||||
|
||||
for (size_t i = 0; i < non_fired_event_names_.size(); i++) {
|
||||
const auto it = std::find(non_fired_event_names_.begin(),
|
||||
non_fired_event_names_.end(), event.get_name());
|
||||
EXPECT_EQ(non_fired_event_names_.end(), it);
|
||||
if (it != non_fired_event_names_.end()) {
|
||||
std::cerr << '\t' << *it << std::endl;
|
||||
const auto iter =
|
||||
std::ranges::find(non_fired_event_names_, event.get_name());
|
||||
EXPECT_EQ(non_fired_event_names_.end(), iter);
|
||||
if (iter != non_fired_event_names_.end()) {
|
||||
std::cerr << '\t' << *iter << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wait_for_empty() {
|
||||
const auto start_time = std::chrono::system_clock::now();
|
||||
unique_mutex_lock l(mutex_);
|
||||
unique_mutex_lock lock(mutex_);
|
||||
while (not event_names_.empty() &&
|
||||
(std::chrono::duration_cast<std::chrono::seconds>(
|
||||
std::chrono::system_clock::now() - start_time)
|
||||
.count() < 10)) {
|
||||
notify_.wait_for(l, 1s);
|
||||
notify_.wait_for(lock, 1s);
|
||||
}
|
||||
l.unlock();
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
[[nodiscard]] auto wait_for_event(const std::string &event_name) -> bool {
|
||||
auto missing = true;
|
||||
const auto start_time = std::chrono::system_clock::now();
|
||||
|
||||
unique_mutex_lock l(mutex_);
|
||||
unique_mutex_lock lock(mutex_);
|
||||
while ((std::chrono::duration_cast<std::chrono::seconds>(
|
||||
std::chrono::system_clock::now() - start_time)
|
||||
.count() < 10) &&
|
||||
(missing =
|
||||
(std::find(fired_event_names_.begin(), fired_event_names_.end(),
|
||||
event_name) == fired_event_names_.end()))) {
|
||||
notify_.wait_for(l, 1s);
|
||||
(missing = (std::ranges::find(fired_event_names_, event_name) ==
|
||||
fired_event_names_.end()))) {
|
||||
notify_.wait_for(lock, 1s);
|
||||
}
|
||||
l.unlock();
|
||||
lock.unlock();
|
||||
return not missing;
|
||||
}
|
||||
};
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -54,7 +54,9 @@ public:
|
||||
event_system::instance().start();
|
||||
}
|
||||
|
||||
void TearDown() override { event_system::instance().stop(); }
|
||||
void TearDown() override {
|
||||
event_system::instance().stop();
|
||||
}
|
||||
};
|
||||
|
||||
std::atomic<std::uint64_t> config_test::idx{0U};
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -35,9 +35,13 @@ public:
|
||||
mock_provider provider;
|
||||
|
||||
protected:
|
||||
void SetUp() override { event_system::instance().start(); }
|
||||
void SetUp() override {
|
||||
event_system::instance().start();
|
||||
}
|
||||
|
||||
void TearDown() override { event_system::instance().stop(); }
|
||||
void TearDown() override {
|
||||
event_system::instance().stop();
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(direct_open_file_test, read_full_file) {
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -22,6 +22,10 @@
|
||||
|
||||
#include "fixtures/file_db_fixture.hpp"
|
||||
|
||||
namespace {
|
||||
const auto get_stop_requested = []() -> bool { return false; };
|
||||
} // namespace
|
||||
|
||||
namespace repertory {
|
||||
TYPED_TEST_CASE(file_db_test, file_db_types);
|
||||
|
||||
@@ -30,12 +34,15 @@ TYPED_TEST(file_db_test, can_add_and_remove_directory) {
|
||||
|
||||
EXPECT_EQ(api_error::success, this->file_db->add_directory("/", "c:\\test"));
|
||||
|
||||
auto list = this->file_db->get_item_list();
|
||||
auto list = this->file_db->get_item_list(get_stop_requested);
|
||||
EXPECT_EQ(1U, list.size());
|
||||
EXPECT_STREQ("/", list.at(0U).api_path.c_str());
|
||||
EXPECT_TRUE(list.at(0U).directory);
|
||||
EXPECT_STREQ("c:\\test", list.at(0U).source_path.c_str());
|
||||
|
||||
EXPECT_EQ(api_error::success, this->file_db->remove_item("/"));
|
||||
|
||||
list = this->file_db->get_item_list();
|
||||
list = this->file_db->get_item_list(get_stop_requested);
|
||||
EXPECT_EQ(0U, list.size());
|
||||
}
|
||||
|
||||
@@ -49,12 +56,15 @@ TYPED_TEST(file_db_test, can_add_and_remove_file) {
|
||||
"c:\\test\\file.txt",
|
||||
}));
|
||||
|
||||
auto list = this->file_db->get_item_list();
|
||||
auto list = this->file_db->get_item_list(get_stop_requested);
|
||||
EXPECT_EQ(1U, list.size());
|
||||
EXPECT_STREQ("/file", list.at(0U).api_path.c_str());
|
||||
EXPECT_FALSE(list.at(0U).directory);
|
||||
EXPECT_STREQ("c:\\test\\file.txt", list.at(0U).source_path.c_str());
|
||||
|
||||
EXPECT_EQ(api_error::success, this->file_db->remove_item("/file"));
|
||||
|
||||
list = this->file_db->get_item_list();
|
||||
list = this->file_db->get_item_list(get_stop_requested);
|
||||
EXPECT_EQ(0U, list.size());
|
||||
}
|
||||
|
||||
@@ -329,4 +339,30 @@ TYPED_TEST(file_db_test, item_not_found_is_returned_for_non_existing_api_path) {
|
||||
this->file_db->get_source_path("/file", source_path));
|
||||
EXPECT_TRUE(source_path.empty());
|
||||
}
|
||||
|
||||
TYPED_TEST(file_db_test, can_enumerate_item_list) {
|
||||
this->file_db->clear();
|
||||
|
||||
EXPECT_EQ(api_error::success,
|
||||
this->file_db->add_directory("/", std::filesystem::current_path().string()));
|
||||
EXPECT_EQ(api_error::success, this->file_db->add_or_update_file({
|
||||
"/file",
|
||||
0U,
|
||||
{},
|
||||
"c:\\test\\file.txt",
|
||||
}));
|
||||
|
||||
auto call_count{0U};
|
||||
const auto get_stop_requested = []() -> bool { return false; };
|
||||
|
||||
this->file_db->enumerate_item_list(
|
||||
[&call_count](auto &&list) {
|
||||
EXPECT_EQ(std::size_t(2U), list.size());
|
||||
++call_count;
|
||||
},
|
||||
get_stop_requested);
|
||||
|
||||
EXPECT_EQ(std::size_t(1U), call_count);
|
||||
}
|
||||
|
||||
} // namespace repertory
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.evt.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.evt.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -22,8 +22,21 @@
|
||||
#include "test_common.hpp"
|
||||
|
||||
#include "app_config.hpp"
|
||||
#include "events/types/download_restored.hpp"
|
||||
#include "events/types/download_resume_added.hpp"
|
||||
#include "events/types/download_resume_removed.hpp"
|
||||
#include "events/types/file_upload_completed.hpp"
|
||||
#include "events/types/file_upload_queued.hpp"
|
||||
#include "events/types/filesystem_item_closed.hpp"
|
||||
#include "events/types/filesystem_item_handle_closed.hpp"
|
||||
#include "events/types/filesystem_item_handle_opened.hpp"
|
||||
#include "events/types/filesystem_item_opened.hpp"
|
||||
#include "events/types/item_timeout.hpp"
|
||||
#include "events/types/service_start_begin.hpp"
|
||||
#include "events/types/service_start_end.hpp"
|
||||
#include "events/types/service_stop_begin.hpp"
|
||||
#include "events/types/service_stop_end.hpp"
|
||||
#include "file_manager/cache_size_mgr.hpp"
|
||||
#include "file_manager/events.hpp"
|
||||
#include "file_manager/file_manager.hpp"
|
||||
#include "file_manager/i_open_file.hpp"
|
||||
#include "mocks/mock_open_file.hpp"
|
||||
@@ -80,23 +93,28 @@ std::atomic<std::size_t> file_manager_test::inst{0U};
|
||||
TEST_F(file_manager_test, can_start_and_stop) {
|
||||
EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false));
|
||||
|
||||
event_consumer consumer("service_started", [](const event &evt) {
|
||||
const auto &evt2 = dynamic_cast<const service_started &>(evt);
|
||||
EXPECT_STREQ("file_manager", evt2.get_service().get<std::string>().c_str());
|
||||
event_consumer consumer(service_start_begin::name, [](const i_event &evt) {
|
||||
const auto &evt2 = dynamic_cast<const service_start_begin &>(evt);
|
||||
EXPECT_STREQ("file_manager", evt2.service_name.c_str());
|
||||
});
|
||||
event_consumer consumer2("service_shutdown_begin", [](const event &evt) {
|
||||
const auto &evt2 = dynamic_cast<const service_shutdown_begin &>(evt);
|
||||
EXPECT_STREQ("file_manager", evt2.get_service().get<std::string>().c_str());
|
||||
event_consumer consumer2(service_start_end::name, [](const i_event &evt) {
|
||||
const auto &evt2 = dynamic_cast<const service_start_end &>(evt);
|
||||
EXPECT_STREQ("file_manager", evt2.service_name.c_str());
|
||||
});
|
||||
event_consumer consumer3("service_shutdown_end", [](const event &evt) {
|
||||
const auto &evt2 = dynamic_cast<const service_shutdown_end &>(evt);
|
||||
EXPECT_STREQ("file_manager", evt2.get_service().get<std::string>().c_str());
|
||||
event_consumer consumer3(service_stop_begin::name, [](const i_event &evt) {
|
||||
const auto &evt2 = dynamic_cast<const service_stop_begin &>(evt);
|
||||
EXPECT_STREQ("file_manager", evt2.service_name.c_str());
|
||||
});
|
||||
event_consumer consumer4(service_stop_end::name, [](const i_event &evt) {
|
||||
const auto &evt2 = dynamic_cast<const service_stop_end &>(evt);
|
||||
EXPECT_STREQ("file_manager", evt2.service_name.c_str());
|
||||
});
|
||||
|
||||
event_capture capture({
|
||||
"service_started",
|
||||
"service_shutdown_begin",
|
||||
"service_shutdown_end",
|
||||
service_start_begin::name,
|
||||
service_start_end::name,
|
||||
service_stop_begin::name,
|
||||
service_stop_end::name,
|
||||
});
|
||||
|
||||
file_manager mgr(*cfg, mp);
|
||||
@@ -117,11 +135,11 @@ TEST_F(file_manager_test, can_create_and_close_file) {
|
||||
mgr.start();
|
||||
|
||||
event_capture capture({
|
||||
"item_timeout",
|
||||
"filesystem_item_opened",
|
||||
"filesystem_item_handle_opened",
|
||||
"filesystem_item_handle_closed",
|
||||
"filesystem_item_closed",
|
||||
item_timeout::name,
|
||||
filesystem_item_opened::name,
|
||||
filesystem_item_handle_opened::name,
|
||||
filesystem_item_handle_closed::name,
|
||||
filesystem_item_closed::name,
|
||||
});
|
||||
|
||||
auto source_path = utils::path::combine(cfg->get_cache_directory(),
|
||||
@@ -151,25 +169,23 @@ TEST_F(file_manager_test, can_create_and_close_file) {
|
||||
return api_error::success;
|
||||
});
|
||||
|
||||
event_consumer consumer("filesystem_item_opened", [&](const event &evt) {
|
||||
const auto &evt2 = dynamic_cast<const filesystem_item_opened &>(evt);
|
||||
EXPECT_STREQ("/test_create.txt",
|
||||
evt2.get_api_path().get<std::string>().c_str());
|
||||
EXPECT_STREQ(source_path.c_str(),
|
||||
evt2.get_source().get<std::string>().c_str());
|
||||
EXPECT_STREQ("0", evt2.get_directory().get<std::string>().c_str());
|
||||
});
|
||||
event_consumer consumer(
|
||||
filesystem_item_opened::name, [&](const i_event &evt) {
|
||||
const auto &evt2 = dynamic_cast<const filesystem_item_opened &>(evt);
|
||||
EXPECT_STREQ("/test_create.txt", evt2.api_path.c_str());
|
||||
EXPECT_STREQ(source_path.c_str(), evt2.source_path.c_str());
|
||||
EXPECT_FALSE(evt2.directory);
|
||||
});
|
||||
|
||||
event_consumer ec2("filesystem_item_handle_opened", [&](const event &evt) {
|
||||
const auto &evt2 =
|
||||
dynamic_cast<const filesystem_item_handle_opened &>(evt);
|
||||
EXPECT_STREQ("/test_create.txt",
|
||||
evt2.get_api_path().get<std::string>().c_str());
|
||||
EXPECT_STREQ(source_path.c_str(),
|
||||
evt2.get_source().get<std::string>().c_str());
|
||||
EXPECT_STREQ("0", evt2.get_directory().get<std::string>().c_str());
|
||||
EXPECT_STREQ("1", evt2.get_handle().get<std::string>().c_str());
|
||||
});
|
||||
event_consumer ec2(
|
||||
filesystem_item_handle_opened::name, [&](const i_event &evt) {
|
||||
const auto &evt2 =
|
||||
dynamic_cast<const filesystem_item_handle_opened &>(evt);
|
||||
EXPECT_STREQ("/test_create.txt", evt2.api_path.c_str());
|
||||
EXPECT_STREQ(source_path.c_str(), evt2.source_path.c_str());
|
||||
EXPECT_FALSE(evt2.directory);
|
||||
EXPECT_EQ(std::uint64_t(1U), evt2.handle);
|
||||
});
|
||||
|
||||
#if defined(_WIN32)
|
||||
EXPECT_EQ(api_error::success,
|
||||
@@ -183,24 +199,22 @@ TEST_F(file_manager_test, can_create_and_close_file) {
|
||||
EXPECT_EQ(std::uint64_t(1U), handle);
|
||||
}
|
||||
|
||||
event_consumer ec3("filesystem_item_closed", [&](const event &evt) {
|
||||
event_consumer ec3(filesystem_item_closed::name, [&](const i_event &evt) {
|
||||
const auto &evt2 = dynamic_cast<const filesystem_item_closed &>(evt);
|
||||
EXPECT_STREQ("/test_create.txt",
|
||||
evt2.get_api_path().get<std::string>().c_str());
|
||||
EXPECT_STREQ(source_path.c_str(),
|
||||
evt2.get_source().get<std::string>().c_str());
|
||||
EXPECT_STREQ("0", evt2.get_directory().get<std::string>().c_str());
|
||||
EXPECT_STREQ("/test_create.txt", evt2.api_path.c_str());
|
||||
EXPECT_STREQ(source_path.c_str(), evt2.source_path.c_str());
|
||||
EXPECT_FALSE(evt2.directory);
|
||||
});
|
||||
|
||||
event_consumer ec4("filesystem_item_handle_closed", [&](const event &evt) {
|
||||
const auto &evt2 = dynamic_cast<const filesystem_item_handle_closed &>(evt);
|
||||
EXPECT_STREQ("/test_create.txt",
|
||||
evt2.get_api_path().get<std::string>().c_str());
|
||||
EXPECT_STREQ(source_path.c_str(),
|
||||
evt2.get_source().get<std::string>().c_str());
|
||||
EXPECT_STREQ("0", evt2.get_directory().get<std::string>().c_str());
|
||||
EXPECT_STREQ("1", evt2.get_handle().get<std::string>().c_str());
|
||||
});
|
||||
event_consumer ec4(
|
||||
filesystem_item_handle_closed::name, [&](const i_event &evt) {
|
||||
const auto &evt2 =
|
||||
dynamic_cast<const filesystem_item_handle_closed &>(evt);
|
||||
EXPECT_STREQ("/test_create.txt", evt2.api_path.c_str());
|
||||
EXPECT_STREQ(source_path.c_str(), evt2.source_path.c_str());
|
||||
EXPECT_FALSE(evt2.directory);
|
||||
EXPECT_EQ(std::uint64_t(1U), evt2.handle);
|
||||
});
|
||||
|
||||
mgr.close(handle);
|
||||
|
||||
@@ -226,11 +240,11 @@ TEST_F(file_manager_test, can_open_and_close_file) {
|
||||
mgr.start();
|
||||
|
||||
event_capture capture({
|
||||
"item_timeout",
|
||||
"filesystem_item_opened",
|
||||
"filesystem_item_handle_opened",
|
||||
"filesystem_item_handle_closed",
|
||||
"filesystem_item_closed",
|
||||
item_timeout::name,
|
||||
filesystem_item_opened::name,
|
||||
filesystem_item_handle_opened::name,
|
||||
filesystem_item_handle_closed::name,
|
||||
filesystem_item_closed::name,
|
||||
});
|
||||
auto source_path = utils::path::combine(cfg->get_cache_directory(),
|
||||
{utils::create_uuid_string()});
|
||||
@@ -258,25 +272,23 @@ TEST_F(file_manager_test, can_open_and_close_file) {
|
||||
return api_error::success;
|
||||
});
|
||||
|
||||
event_consumer consumer("filesystem_item_opened", [&](const event &evt) {
|
||||
const auto &evt2 = dynamic_cast<const filesystem_item_opened &>(evt);
|
||||
EXPECT_STREQ("/test_open.txt",
|
||||
evt2.get_api_path().get<std::string>().c_str());
|
||||
EXPECT_STREQ(source_path.c_str(),
|
||||
evt2.get_source().get<std::string>().c_str());
|
||||
EXPECT_STREQ("0", evt2.get_directory().get<std::string>().c_str());
|
||||
});
|
||||
event_consumer consumer(
|
||||
filesystem_item_opened::name, [&](const i_event &evt) {
|
||||
const auto &evt2 = dynamic_cast<const filesystem_item_opened &>(evt);
|
||||
EXPECT_STREQ("/test_open.txt", evt2.api_path.c_str());
|
||||
EXPECT_STREQ(source_path.c_str(), evt2.source_path.c_str());
|
||||
EXPECT_FALSE(evt2.directory);
|
||||
});
|
||||
|
||||
event_consumer ec2("filesystem_item_handle_opened", [&](const event &evt) {
|
||||
const auto &evt2 =
|
||||
dynamic_cast<const filesystem_item_handle_opened &>(evt);
|
||||
EXPECT_STREQ("/test_open.txt",
|
||||
evt2.get_api_path().get<std::string>().c_str());
|
||||
EXPECT_STREQ(source_path.c_str(),
|
||||
evt2.get_source().get<std::string>().c_str());
|
||||
EXPECT_STREQ("0", evt2.get_directory().get<std::string>().c_str());
|
||||
EXPECT_STREQ("1", evt2.get_handle().get<std::string>().c_str());
|
||||
});
|
||||
event_consumer ec2(
|
||||
filesystem_item_handle_opened::name, [&](const i_event &evt) {
|
||||
const auto &evt2 =
|
||||
dynamic_cast<const filesystem_item_handle_opened &>(evt);
|
||||
EXPECT_STREQ("/test_open.txt", evt2.api_path.c_str());
|
||||
EXPECT_STREQ(source_path.c_str(), evt2.source_path.c_str());
|
||||
EXPECT_FALSE(evt2.directory);
|
||||
EXPECT_EQ(std::uint64_t(1U), evt2.handle);
|
||||
});
|
||||
|
||||
std::shared_ptr<i_open_file> open_file;
|
||||
#if defined(_WIN32)
|
||||
@@ -291,24 +303,22 @@ TEST_F(file_manager_test, can_open_and_close_file) {
|
||||
EXPECT_EQ(std::uint64_t(1U), handle);
|
||||
}
|
||||
|
||||
event_consumer ec3("filesystem_item_closed", [&](const event &evt) {
|
||||
event_consumer ec3(filesystem_item_closed::name, [&](const i_event &evt) {
|
||||
const auto &evt2 = dynamic_cast<const filesystem_item_closed &>(evt);
|
||||
EXPECT_STREQ("/test_open.txt",
|
||||
evt2.get_api_path().get<std::string>().c_str());
|
||||
EXPECT_STREQ(source_path.c_str(),
|
||||
evt2.get_source().get<std::string>().c_str());
|
||||
EXPECT_STREQ("0", evt2.get_directory().get<std::string>().c_str());
|
||||
EXPECT_STREQ("/test_open.txt", evt2.api_path.c_str());
|
||||
EXPECT_STREQ(source_path.c_str(), evt2.source_path.c_str());
|
||||
EXPECT_FALSE(evt2.directory);
|
||||
});
|
||||
|
||||
event_consumer ec4("filesystem_item_handle_closed", [&](const event &evt) {
|
||||
const auto &evt2 = dynamic_cast<const filesystem_item_handle_closed &>(evt);
|
||||
EXPECT_STREQ("/test_open.txt",
|
||||
evt2.get_api_path().get<std::string>().c_str());
|
||||
EXPECT_STREQ(source_path.c_str(),
|
||||
evt2.get_source().get<std::string>().c_str());
|
||||
EXPECT_STREQ("0", evt2.get_directory().get<std::string>().c_str());
|
||||
EXPECT_STREQ("1", evt2.get_handle().get<std::string>().c_str());
|
||||
});
|
||||
event_consumer ec4(
|
||||
filesystem_item_handle_closed::name, [&](const i_event &evt) {
|
||||
const auto &evt2 =
|
||||
dynamic_cast<const filesystem_item_handle_closed &>(evt);
|
||||
EXPECT_STREQ("/test_open.txt", evt2.api_path.c_str());
|
||||
EXPECT_STREQ(source_path.c_str(), evt2.source_path.c_str());
|
||||
EXPECT_FALSE(evt2.directory);
|
||||
EXPECT_EQ(std::uint64_t(1U), evt2.handle);
|
||||
});
|
||||
|
||||
mgr.close(handle);
|
||||
|
||||
@@ -396,18 +406,17 @@ TEST_F(file_manager_test,
|
||||
{utils::create_uuid_string()});
|
||||
|
||||
event_consumer consumer(
|
||||
"download_resume_added", [&source_path](const event &evt) {
|
||||
download_resume_added::name, [&source_path](const i_event &evt) {
|
||||
const auto &evt2 = dynamic_cast<const download_resume_added &>(evt);
|
||||
EXPECT_STREQ("/test_write_partial_download.txt",
|
||||
evt2.get_api_path().get<std::string>().c_str());
|
||||
EXPECT_STREQ(source_path.c_str(),
|
||||
evt2.get_dest_path().get<std::string>().c_str());
|
||||
EXPECT_STREQ("/test_write_partial_download.txt", evt2.api_path.c_str());
|
||||
EXPECT_STREQ(source_path.c_str(), evt2.dest_path.c_str());
|
||||
});
|
||||
|
||||
event_capture capture({"download_resume_added"}, {
|
||||
"file_upload_completed",
|
||||
"file_upload_queued",
|
||||
});
|
||||
event_capture capture({download_resume_added::name},
|
||||
{
|
||||
file_upload_completed::name,
|
||||
file_upload_queued::name,
|
||||
});
|
||||
|
||||
auto now = utils::time::get_time_now();
|
||||
auto meta = create_meta_attributes(
|
||||
@@ -494,10 +503,10 @@ TEST_F(file_manager_test,
|
||||
mgr.stop();
|
||||
capture.wait_for_empty();
|
||||
|
||||
event_capture ec2({"download_restored", "download_resume_added"},
|
||||
event_capture ec2({download_restored::name, download_resume_added::name},
|
||||
{
|
||||
"file_upload_completed",
|
||||
"file_upload_queued",
|
||||
file_upload_completed::name,
|
||||
file_upload_queued::name,
|
||||
});
|
||||
EXPECT_EQ(std::size_t(0u), mgr.get_open_file_count());
|
||||
EXPECT_EQ(std::size_t(0u), mgr.get_open_handle_count());
|
||||
@@ -518,13 +527,12 @@ TEST_F(file_manager_test,
|
||||
|
||||
mgr.start();
|
||||
|
||||
event_consumer es2("download_restored", [&source_path](const event &evt) {
|
||||
const auto &evt2 = dynamic_cast<const download_restored &>(evt);
|
||||
EXPECT_STREQ("/test_write_partial_download.txt",
|
||||
evt2.get_api_path().get<std::string>().c_str());
|
||||
EXPECT_STREQ(source_path.c_str(),
|
||||
evt2.get_dest_path().get<std::string>().c_str());
|
||||
});
|
||||
event_consumer es2(
|
||||
download_restored::name, [&source_path](const i_event &evt) {
|
||||
const auto &evt2 = dynamic_cast<const download_restored &>(evt);
|
||||
EXPECT_STREQ("/test_write_partial_download.txt", evt2.api_path.c_str());
|
||||
EXPECT_STREQ(source_path.c_str(), evt2.dest_path.c_str());
|
||||
});
|
||||
|
||||
EXPECT_EQ(std::size_t(1u), mgr.get_open_file_count());
|
||||
EXPECT_EQ(std::size_t(0u), mgr.get_open_handle_count());
|
||||
@@ -551,20 +559,17 @@ TEST_F(file_manager_test, upload_occurs_after_write_if_fully_downloaded) {
|
||||
{utils::create_uuid_string()});
|
||||
|
||||
event_consumer consumer(
|
||||
"file_upload_queued", [&source_path](const event &evt) {
|
||||
"file_upload_queued", [&source_path](const i_event &evt) {
|
||||
const auto &evt2 = dynamic_cast<const file_upload_queued &>(evt);
|
||||
EXPECT_STREQ("/test_write_full_download.txt",
|
||||
evt2.get_api_path().get<std::string>().c_str());
|
||||
EXPECT_STREQ(source_path.c_str(),
|
||||
evt2.get_source().get<std::string>().c_str());
|
||||
EXPECT_STREQ("/test_write_full_download.txt", evt2.api_path.c_str());
|
||||
EXPECT_STREQ(source_path.c_str(), evt2.source_path.c_str());
|
||||
});
|
||||
event_consumer es2(
|
||||
file_upload_completed::name, [&source_path](const i_event &evt) {
|
||||
const auto &evt2 = dynamic_cast<const file_upload_completed &>(evt);
|
||||
EXPECT_STREQ("/test_write_full_download.txt", evt2.api_path.c_str());
|
||||
EXPECT_STREQ(source_path.c_str(), evt2.source_path.c_str());
|
||||
});
|
||||
event_consumer es2("file_upload_completed", [&source_path](const event &evt) {
|
||||
const auto &evt2 = dynamic_cast<const file_upload_completed &>(evt);
|
||||
EXPECT_STREQ("/test_write_full_download.txt",
|
||||
evt2.get_api_path().get<std::string>().c_str());
|
||||
EXPECT_STREQ(source_path.c_str(),
|
||||
evt2.get_source().get<std::string>().c_str());
|
||||
});
|
||||
|
||||
auto now = utils::time::get_time_now();
|
||||
auto meta = create_meta_attributes(
|
||||
@@ -625,9 +630,9 @@ TEST_F(file_manager_test, upload_occurs_after_write_if_fully_downloaded) {
|
||||
}
|
||||
|
||||
event_capture capture({
|
||||
"item_timeout",
|
||||
"file_upload_queued",
|
||||
"file_upload_completed",
|
||||
item_timeout::name,
|
||||
file_upload_queued::name,
|
||||
file_upload_completed::name,
|
||||
});
|
||||
|
||||
EXPECT_CALL(mp, upload_file("/test_write_full_download.txt", source_path, _))
|
||||
@@ -664,11 +669,11 @@ TEST_F(file_manager_test, can_evict_file) {
|
||||
mgr.start();
|
||||
|
||||
event_capture capture({
|
||||
"filesystem_item_opened",
|
||||
"filesystem_item_handle_opened",
|
||||
"filesystem_item_handle_closed",
|
||||
"filesystem_item_closed",
|
||||
"file_upload_completed",
|
||||
filesystem_item_opened::name,
|
||||
filesystem_item_handle_opened::name,
|
||||
filesystem_item_handle_closed::name,
|
||||
filesystem_item_closed::name,
|
||||
file_upload_completed::name,
|
||||
});
|
||||
|
||||
auto source_path = utils::path::combine(cfg->get_cache_directory(),
|
||||
@@ -855,11 +860,11 @@ TEST_F(file_manager_test, evict_file_fails_if_file_is_uploading) {
|
||||
mgr.start();
|
||||
|
||||
event_capture capture({
|
||||
"filesystem_item_opened",
|
||||
"filesystem_item_handle_opened",
|
||||
"filesystem_item_handle_closed",
|
||||
"filesystem_item_closed",
|
||||
"file_upload_completed",
|
||||
filesystem_item_opened::name,
|
||||
filesystem_item_handle_opened::name,
|
||||
filesystem_item_handle_closed::name,
|
||||
filesystem_item_closed::name,
|
||||
file_upload_completed::name,
|
||||
});
|
||||
|
||||
auto source_path = utils::path::combine(cfg->get_cache_directory(),
|
||||
@@ -1041,11 +1046,15 @@ TEST_F(file_manager_test, can_get_directory_items) {
|
||||
"..",
|
||||
"",
|
||||
true,
|
||||
0U,
|
||||
{},
|
||||
});
|
||||
list.insert(list.begin(), directory_item{
|
||||
".",
|
||||
"",
|
||||
true,
|
||||
0U,
|
||||
{},
|
||||
});
|
||||
return api_error::success;
|
||||
});
|
||||
@@ -1405,8 +1414,8 @@ TEST_F(file_manager_test, can_remove_file) {
|
||||
|
||||
TEST_F(file_manager_test, can_queue_and_remove_upload) {
|
||||
event_capture capture({
|
||||
"file_upload_queued",
|
||||
"download_resume_removed",
|
||||
file_upload_queued::name,
|
||||
download_resume_removed::name,
|
||||
});
|
||||
|
||||
EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false));
|
||||
@@ -1441,10 +1450,9 @@ TEST_F(file_manager_test, file_is_closed_after_download_timeout) {
|
||||
auto source_path = utils::path::combine(cfg->get_cache_directory(),
|
||||
{utils::create_uuid_string()});
|
||||
|
||||
event_consumer consumer("item_timeout", [](const event &evt) {
|
||||
event_consumer consumer(item_timeout::name, [](const i_event &evt) {
|
||||
const auto &evt2 = dynamic_cast<const item_timeout &>(evt);
|
||||
EXPECT_STREQ("/test_download_timeout.txt",
|
||||
evt2.get_api_path().get<std::string>().c_str());
|
||||
EXPECT_STREQ("/test_download_timeout.txt", evt2.api_path.c_str());
|
||||
});
|
||||
|
||||
auto now = utils::time::get_time_now();
|
||||
@@ -1467,7 +1475,7 @@ TEST_F(file_manager_test, file_is_closed_after_download_timeout) {
|
||||
return api_error::success;
|
||||
});
|
||||
|
||||
event_capture capture({"item_timeout"});
|
||||
event_capture capture({item_timeout::name});
|
||||
|
||||
EXPECT_CALL(mp, read_file_bytes)
|
||||
.WillRepeatedly([](const std::string & /* api_path */, std::size_t size,
|
||||
@@ -1568,11 +1576,11 @@ TEST_F(file_manager_test,
|
||||
mgr.start();
|
||||
|
||||
event_capture capture({
|
||||
"item_timeout",
|
||||
"filesystem_item_opened",
|
||||
"filesystem_item_handle_opened",
|
||||
"filesystem_item_handle_closed",
|
||||
"filesystem_item_closed",
|
||||
item_timeout::name,
|
||||
filesystem_item_opened::name,
|
||||
filesystem_item_handle_opened::name,
|
||||
filesystem_item_handle_closed::name,
|
||||
filesystem_item_closed::name,
|
||||
});
|
||||
|
||||
std::uint64_t handle{};
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -21,7 +21,7 @@
|
||||
*/
|
||||
|
||||
#include "fixtures/file_mgr_db_fixture.hpp"
|
||||
#include <utils/time.hpp>
|
||||
#include "utils/time.hpp"
|
||||
|
||||
namespace repertory {
|
||||
TYPED_TEST_CASE(file_mgr_db_test, file_mgr_db_types);
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -103,7 +103,7 @@ TYPED_TEST(fuse_test, access_directory_permutations_test) {
|
||||
std::string dir_name{"access_test"};
|
||||
auto dir_path = this->create_directory_and_test(dir_name);
|
||||
|
||||
for (auto &&permutation : access_permutations) {
|
||||
for (const auto &permutation : access_permutations) {
|
||||
perform_access_test(permutation, dir_path);
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ TYPED_TEST(fuse_test, access_file_permutations_test) {
|
||||
std::string file_name{"access_test"};
|
||||
auto file_path = this->create_file_and_test(file_name);
|
||||
|
||||
for (auto &&permutation : access_permutations) {
|
||||
for (const auto &permutation : access_permutations) {
|
||||
perform_access_test(permutation, file_path);
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -41,7 +41,7 @@ TYPED_TEST(fuse_test, create_can_create_directory_with_specific_perms) {
|
||||
std::string dir_name{"create_test"};
|
||||
auto dir_path = this->create_directory_and_test(dir_name, S_IRUSR);
|
||||
|
||||
struct stat64 unix_st {};
|
||||
struct stat64 unix_st{};
|
||||
EXPECT_EQ(0, stat64(dir_path.c_str(), &unix_st));
|
||||
EXPECT_EQ(S_IRUSR, unix_st.st_mode & ACCESSPERMS);
|
||||
|
||||
@@ -52,7 +52,7 @@ TYPED_TEST(fuse_test, create_can_create_file_with_specific_perms) {
|
||||
std::string file_name{"create_test"};
|
||||
auto file_path = this->create_file_and_test(file_name, S_IRUSR);
|
||||
|
||||
struct stat64 unix_st {};
|
||||
struct stat64 unix_st{};
|
||||
EXPECT_EQ(0, stat64(file_path.c_str(), &unix_st));
|
||||
EXPECT_EQ(S_IRUSR, unix_st.st_mode & ACCESSPERMS);
|
||||
|
||||
@@ -376,7 +376,7 @@ TYPED_TEST(fuse_test, create_fails_with_excl_if_path_is_directory) {
|
||||
std::string dir_name{"create_test"};
|
||||
auto dir_path = this->create_directory_and_test(dir_name);
|
||||
|
||||
for (auto &&flags : ops) {
|
||||
for (const auto &flags : ops) {
|
||||
auto handle = open(dir_path.c_str(), flags, ACCESSPERMS);
|
||||
EXPECT_EQ(-1, handle);
|
||||
|
||||
@@ -396,7 +396,7 @@ TYPED_TEST(fuse_test, create_fails_with_excl_if_file_exists) {
|
||||
std::string file_name{"create_test"};
|
||||
auto file_path = this->create_file_and_test(file_name);
|
||||
|
||||
for (auto &&flags : ops) {
|
||||
for (const auto &flags : ops) {
|
||||
auto handle = open(file_path.c_str(), flags, ACCESSPERMS);
|
||||
EXPECT_EQ(-1, handle);
|
||||
|
||||
@@ -420,7 +420,7 @@ TYPED_TEST(fuse_test, create_fails_if_path_is_directory) {
|
||||
std::string dir_name{"create_test"};
|
||||
auto dir_path = this->create_directory_and_test(dir_name);
|
||||
|
||||
for (auto &&flags : ops) {
|
||||
for (const auto &flags : ops) {
|
||||
auto handle = open(dir_path.c_str(), flags, ACCESSPERMS);
|
||||
EXPECT_EQ(-1, handle);
|
||||
|
||||
@@ -447,7 +447,7 @@ TYPED_TEST(fuse_test, create_fails_if_parent_path_does_not_exist) {
|
||||
std::string file_name{"no_dir/create_test"};
|
||||
auto file_path = this->create_file_path(file_name);
|
||||
|
||||
for (auto &&flags : ops) {
|
||||
for (const auto &flags : ops) {
|
||||
auto handle = open(file_path.c_str(), flags, ACCESSPERMS);
|
||||
EXPECT_EQ(-1, handle);
|
||||
|
||||
@@ -463,7 +463,7 @@ TYPED_TEST(fuse_test, create_fails_if_invalid) {
|
||||
std::string file_name{"create_test"};
|
||||
auto file_path = this->create_file_path(file_name);
|
||||
|
||||
for (auto &&flags : ops) {
|
||||
for (const auto &flags : ops) {
|
||||
auto handle = open(file_path.c_str(), flags, ACCESSPERMS);
|
||||
EXPECT_EQ(-1, handle);
|
||||
|
||||
@@ -481,7 +481,7 @@ TYPED_TEST(fuse_test, create_open_fails_if_path_is_directory) {
|
||||
std::string dir_name{"create_test"};
|
||||
auto dir_path = this->create_directory_and_test(dir_name);
|
||||
|
||||
for (auto &&flags : ops) {
|
||||
for (const auto &flags : ops) {
|
||||
auto handle = open(dir_path.c_str(), flags);
|
||||
EXPECT_EQ(-1, handle);
|
||||
if (handle != -1) {
|
||||
@@ -510,7 +510,7 @@ TYPED_TEST(fuse_test, create_open_fails_if_path_does_not_exist) {
|
||||
std::string file_name{"create_test"};
|
||||
auto file_path = this->create_file_path(file_name);
|
||||
|
||||
for (auto &&flags : ops) {
|
||||
for (const auto &flags : ops) {
|
||||
auto handle = open(file_path.c_str(), flags);
|
||||
EXPECT_EQ(-1, handle);
|
||||
EXPECT_EQ(ENOENT, errno);
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -63,8 +63,8 @@ TYPED_TEST(fuse_test, rdrw_can_read_from_offset) {
|
||||
|
||||
data_buffer read_buffer(1U);
|
||||
for (std::size_t idx = 0U; idx < write_buffer.size(); ++idx) {
|
||||
auto bytes_read =
|
||||
pread64(handle, read_buffer.data(), read_buffer.size(), idx);
|
||||
auto bytes_read = pread64(handle, read_buffer.data(), read_buffer.size(),
|
||||
static_cast<off64_t>(idx));
|
||||
EXPECT_EQ(1U, bytes_read);
|
||||
|
||||
EXPECT_EQ(write_buffer.at(idx), read_buffer.at(0U));
|
||||
@@ -89,8 +89,8 @@ TYPED_TEST(fuse_test, rdrw_can_read_from_offset_after_eof) {
|
||||
|
||||
data_buffer read_buffer(1U);
|
||||
for (std::size_t idx = 0U; idx < write_buffer.size() + 1U; ++idx) {
|
||||
auto bytes_read =
|
||||
pread64(handle, read_buffer.data(), read_buffer.size(), idx);
|
||||
auto bytes_read = pread64(handle, read_buffer.data(), read_buffer.size(),
|
||||
static_cast<off64_t>(idx));
|
||||
if (idx == write_buffer.size()) {
|
||||
EXPECT_EQ(0U, bytes_read);
|
||||
} else {
|
||||
@@ -140,8 +140,7 @@ TYPED_TEST(fuse_test, rdrw_can_not_read_from_wo_file) {
|
||||
EXPECT_EQ(write_buffer.size(), bytes_written);
|
||||
|
||||
data_buffer read_buffer(1U);
|
||||
auto bytes_read =
|
||||
pread64(handle, read_buffer.data(), read_buffer.size(), idx);
|
||||
auto bytes_read = pread64(handle, read_buffer.data(), read_buffer.size(), 0);
|
||||
EXPECT_EQ(-1, bytes_read);
|
||||
EXPECT_EQ(EBADF, errno);
|
||||
|
||||
@@ -149,6 +148,63 @@ TYPED_TEST(fuse_test, rdrw_can_not_read_from_wo_file) {
|
||||
|
||||
this->unlink_file_and_test(file_path);
|
||||
}
|
||||
|
||||
TYPED_TEST(fuse_test, rdrw_can_not_read_or_write_to_directory) {
|
||||
std::string dir_name{"create_test"};
|
||||
auto dir_path = this->create_directory_and_test(dir_name);
|
||||
|
||||
auto handle = open(dir_path.c_str(), O_DIRECTORY);
|
||||
ASSERT_GT(handle, -1);
|
||||
|
||||
auto write_buffer = utils::generate_secure_random<data_buffer>(8096U);
|
||||
auto bytes_written =
|
||||
pwrite64(handle, write_buffer.data(), write_buffer.size(), 0U);
|
||||
EXPECT_EQ(-1, bytes_written);
|
||||
EXPECT_EQ(EBADF, errno);
|
||||
|
||||
data_buffer read_buffer(1U);
|
||||
auto bytes_read = pread64(handle, read_buffer.data(), read_buffer.size(), 0);
|
||||
EXPECT_EQ(-1, bytes_read);
|
||||
EXPECT_EQ(EISDIR, errno);
|
||||
|
||||
close(handle);
|
||||
|
||||
this->rmdir_and_test(dir_path);
|
||||
}
|
||||
|
||||
TYPED_TEST(fuse_test, rdrw_can_append_to_file) {
|
||||
std::string file_name{"append_test"};
|
||||
auto file_path = this->create_file_and_test(file_name);
|
||||
|
||||
auto handle = open(file_path.c_str(), O_WRONLY);
|
||||
ASSERT_GT(handle, -1);
|
||||
auto bytes_written = pwrite64(handle, "test_", 5U, 0);
|
||||
EXPECT_EQ(5U, bytes_written);
|
||||
close(handle);
|
||||
|
||||
handle = open(file_path.c_str(), O_WRONLY | O_APPEND);
|
||||
ASSERT_GT(handle, -1);
|
||||
bytes_written = write(handle, "cow_", 4U);
|
||||
EXPECT_EQ(4U, bytes_written);
|
||||
close(handle);
|
||||
|
||||
handle = open(file_path.c_str(), O_WRONLY | O_APPEND);
|
||||
ASSERT_GT(handle, -1);
|
||||
bytes_written = write(handle, "dog", 3U);
|
||||
EXPECT_EQ(3U, bytes_written);
|
||||
close(handle);
|
||||
|
||||
handle = open(file_path.c_str(), O_RDONLY);
|
||||
ASSERT_GT(handle, -1);
|
||||
std::string read_buffer;
|
||||
read_buffer.resize(12U);
|
||||
auto bytes_read = pread64(handle, read_buffer.data(), read_buffer.size(), 0);
|
||||
EXPECT_EQ(12U, bytes_read);
|
||||
EXPECT_STREQ("test_cow_dog", read_buffer.c_str());
|
||||
close(handle);
|
||||
|
||||
this->unlink_file_and_test(file_path);
|
||||
}
|
||||
} // namespace repertory
|
||||
|
||||
#endif // !defined(_WIN32)
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -615,4 +615,35 @@ TYPED_TEST(meta_db_test, check_set_item_meta_file_defaults) {
|
||||
EXPECT_EQ(0U, utils::string::to_uint64(meta[META_SIZE]));
|
||||
EXPECT_TRUE(meta[META_SOURCE].empty());
|
||||
}
|
||||
|
||||
TYPED_TEST(meta_db_test, can_enumerate_api_path_list) {
|
||||
this->meta_db->clear();
|
||||
|
||||
auto test_dir = create_test_file();
|
||||
EXPECT_EQ(api_error::success,
|
||||
this->meta_db->set_item_meta(
|
||||
test_dir, {
|
||||
{META_DIRECTORY, utils::string::from_bool(true)},
|
||||
}));
|
||||
|
||||
auto test_file = create_test_file();
|
||||
EXPECT_EQ(
|
||||
api_error::success,
|
||||
this->meta_db->set_item_meta(
|
||||
test_file, {
|
||||
{META_DIRECTORY, utils::string::from_bool(false)},
|
||||
}));
|
||||
|
||||
auto call_count{0U};
|
||||
const auto get_stop_requested = []() -> bool { return false; };
|
||||
|
||||
this->meta_db->enumerate_api_path_list(
|
||||
[&call_count](auto &&list) {
|
||||
EXPECT_EQ(std::size_t(2U), list.size());
|
||||
++call_count;
|
||||
},
|
||||
get_stop_requested);
|
||||
|
||||
EXPECT_EQ(std::size_t(1U), call_count);
|
||||
}
|
||||
} // namespace repertory
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -22,6 +22,10 @@
|
||||
#include "test_common.hpp"
|
||||
|
||||
#include "app_config.hpp"
|
||||
#include "events/types/filesystem_item_closed.hpp"
|
||||
#include "events/types/filesystem_item_handle_closed.hpp"
|
||||
#include "events/types/filesystem_item_handle_opened.hpp"
|
||||
#include "events/types/filesystem_item_opened.hpp"
|
||||
#include "file_manager/cache_size_mgr.hpp"
|
||||
#include "file_manager/open_file.hpp"
|
||||
#include "mocks/mock_provider.hpp"
|
||||
@@ -601,24 +605,21 @@ TEST_F(open_file_test, can_add_handle) {
|
||||
fsi.size = test_chunk_size * 4u;
|
||||
fsi.source_path = source_path;
|
||||
|
||||
event_consumer ec("filesystem_item_opened", [&fsi](const event &e) {
|
||||
event_consumer ec(filesystem_item_opened::name, [&fsi](const i_event &e) {
|
||||
const auto &ee = dynamic_cast<const filesystem_item_opened &>(e);
|
||||
EXPECT_STREQ(fsi.api_path.c_str(),
|
||||
ee.get_api_path().get<std::string>().c_str());
|
||||
EXPECT_STREQ(fsi.source_path.c_str(),
|
||||
ee.get_source().get<std::string>().c_str());
|
||||
EXPECT_STREQ("0", ee.get_directory().get<std::string>().c_str());
|
||||
EXPECT_STREQ(fsi.api_path.c_str(), ee.api_path.c_str());
|
||||
EXPECT_STREQ(fsi.source_path.c_str(), ee.source_path.c_str());
|
||||
EXPECT_FALSE(ee.directory);
|
||||
});
|
||||
|
||||
event_consumer ec2("filesystem_item_handle_opened", [&fsi](const event &e) {
|
||||
const auto &ee = dynamic_cast<const filesystem_item_handle_opened &>(e);
|
||||
EXPECT_STREQ(fsi.api_path.c_str(),
|
||||
ee.get_api_path().get<std::string>().c_str());
|
||||
EXPECT_STREQ(fsi.source_path.c_str(),
|
||||
ee.get_source().get<std::string>().c_str());
|
||||
EXPECT_STREQ("0", ee.get_directory().get<std::string>().c_str());
|
||||
EXPECT_STREQ("1", ee.get_handle().get<std::string>().c_str());
|
||||
});
|
||||
event_consumer ec2(
|
||||
filesystem_item_handle_opened::name, [&fsi](const i_event &e) {
|
||||
const auto &ee = dynamic_cast<const filesystem_item_handle_opened &>(e);
|
||||
EXPECT_STREQ(fsi.api_path.c_str(), ee.api_path.c_str());
|
||||
EXPECT_STREQ(fsi.source_path.c_str(), ee.source_path.c_str());
|
||||
EXPECT_FALSE(ee.directory);
|
||||
EXPECT_EQ(std::uint64_t(1U), ee.handle);
|
||||
});
|
||||
|
||||
EXPECT_CALL(provider, set_item_meta(fsi.api_path, META_SOURCE, _))
|
||||
.WillOnce(Return(api_error::success));
|
||||
@@ -629,8 +630,10 @@ TEST_F(open_file_test, can_add_handle) {
|
||||
EXPECT_EQ(fsi.source_path, source_path2);
|
||||
});
|
||||
|
||||
event_capture capture(
|
||||
{"filesystem_item_opened", "filesystem_item_handle_opened"});
|
||||
event_capture capture({
|
||||
filesystem_item_opened::name,
|
||||
filesystem_item_handle_opened::name,
|
||||
});
|
||||
|
||||
open_file o(test_chunk_size, 0U, fsi, provider, upload_mgr);
|
||||
#if defined(_WIN32)
|
||||
@@ -647,9 +650,10 @@ TEST_F(open_file_test, can_add_handle) {
|
||||
}
|
||||
|
||||
TEST_F(open_file_test, can_remove_handle) {
|
||||
event_system::instance().start();
|
||||
console_consumer c;
|
||||
|
||||
event_system::instance().start();
|
||||
|
||||
const auto source_path =
|
||||
test::generate_test_file_name("file_manager_open_file_test");
|
||||
|
||||
@@ -660,24 +664,21 @@ TEST_F(open_file_test, can_remove_handle) {
|
||||
fsi.size = test_chunk_size * 4u;
|
||||
fsi.source_path = source_path;
|
||||
|
||||
event_consumer ec("filesystem_item_closed", [&fsi](const event &e) {
|
||||
event_consumer ec(filesystem_item_closed::name, [&fsi](const i_event &e) {
|
||||
const auto &ee = dynamic_cast<const filesystem_item_closed &>(e);
|
||||
EXPECT_STREQ(fsi.api_path.c_str(),
|
||||
ee.get_api_path().get<std::string>().c_str());
|
||||
EXPECT_STREQ(fsi.source_path.c_str(),
|
||||
ee.get_source().get<std::string>().c_str());
|
||||
EXPECT_STREQ("0", ee.get_directory().get<std::string>().c_str());
|
||||
EXPECT_STREQ(fsi.api_path.c_str(), ee.api_path.c_str());
|
||||
EXPECT_STREQ(fsi.source_path.c_str(), ee.source_path.c_str());
|
||||
EXPECT_FALSE(ee.directory);
|
||||
});
|
||||
|
||||
event_consumer ec2("filesystem_item_handle_closed", [&fsi](const event &e) {
|
||||
const auto &ee = dynamic_cast<const filesystem_item_handle_closed &>(e);
|
||||
EXPECT_STREQ(fsi.api_path.c_str(),
|
||||
ee.get_api_path().get<std::string>().c_str());
|
||||
EXPECT_STREQ(fsi.source_path.c_str(),
|
||||
ee.get_source().get<std::string>().c_str());
|
||||
EXPECT_STREQ("0", ee.get_directory().get<std::string>().c_str());
|
||||
EXPECT_STREQ("1", ee.get_handle().get<std::string>().c_str());
|
||||
});
|
||||
event_consumer ec2(
|
||||
filesystem_item_handle_closed::name, [&fsi](const i_event &e) {
|
||||
const auto &ee = dynamic_cast<const filesystem_item_handle_closed &>(e);
|
||||
EXPECT_STREQ(fsi.api_path.c_str(), ee.api_path.c_str());
|
||||
EXPECT_STREQ(fsi.source_path.c_str(), ee.source_path.c_str());
|
||||
EXPECT_FALSE(ee.directory);
|
||||
EXPECT_EQ(std::uint64_t(1U), ee.handle);
|
||||
});
|
||||
|
||||
EXPECT_CALL(upload_mgr, remove_resume)
|
||||
.WillOnce(
|
||||
@@ -689,10 +690,10 @@ TEST_F(open_file_test, can_remove_handle) {
|
||||
.WillOnce(Return(api_error::success));
|
||||
|
||||
event_capture capture({
|
||||
"filesystem_item_opened",
|
||||
"filesystem_item_handle_opened",
|
||||
"filesystem_item_handle_closed",
|
||||
"filesystem_item_closed",
|
||||
filesystem_item_opened::name,
|
||||
filesystem_item_handle_opened::name,
|
||||
filesystem_item_handle_closed::name,
|
||||
filesystem_item_closed::name,
|
||||
});
|
||||
|
||||
open_file o(test_chunk_size, 0U, fsi, provider, upload_mgr);
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -421,19 +421,19 @@ static void get_directory_items(const app_config &cfg, i_provider &provider) {
|
||||
decrypt_parts(cfg, dir_item.api_path);
|
||||
}
|
||||
|
||||
auto dir = std::find_if(list_decrypted.begin(), list_decrypted.end(),
|
||||
[](const directory_item &dir_item) -> bool {
|
||||
return dir_item.directory;
|
||||
});
|
||||
auto dir =
|
||||
std::ranges::find_if(list_decrypted, [](auto &&dir_item) -> bool {
|
||||
return dir_item.directory;
|
||||
});
|
||||
EXPECT_LT(dir, list_decrypted.end());
|
||||
EXPECT_STREQ("/sub10", dir->api_path.c_str());
|
||||
EXPECT_STREQ("/", dir->api_parent.c_str());
|
||||
EXPECT_EQ(std::size_t(0U), dir->size);
|
||||
|
||||
auto file = std::find_if(list_decrypted.begin(), list_decrypted.end(),
|
||||
[](const directory_item &dir_item) -> bool {
|
||||
return not dir_item.directory;
|
||||
});
|
||||
auto file =
|
||||
std::ranges::find_if(list_decrypted, [](auto &&dir_item) -> bool {
|
||||
return not dir_item.directory;
|
||||
});
|
||||
EXPECT_LT(file, list_decrypted.end());
|
||||
EXPECT_STREQ("/test.txt", file->api_path.c_str());
|
||||
EXPECT_STREQ("/", file->api_parent.c_str());
|
||||
@@ -460,10 +460,10 @@ static void get_directory_items(const app_config &cfg, i_provider &provider) {
|
||||
decrypt_parts(cfg, dir_item.api_path);
|
||||
}
|
||||
|
||||
auto file2 = std::find_if(list_decrypted2.begin(), list_decrypted2.end(),
|
||||
[](const directory_item &dir_item) -> bool {
|
||||
return not dir_item.directory;
|
||||
});
|
||||
auto file2 =
|
||||
std::ranges::find_if(list_decrypted2, [](auto &&dir_item) -> bool {
|
||||
return not dir_item.directory;
|
||||
});
|
||||
EXPECT_LT(file2, list_decrypted2.end());
|
||||
EXPECT_STREQ("/sub10/moose.txt", file2->api_path.c_str());
|
||||
EXPECT_STREQ("/sub10", file2->api_parent.c_str());
|
||||
@@ -635,6 +635,7 @@ TEST(providers, encrypt_provider) {
|
||||
|
||||
console_consumer consumer{};
|
||||
event_system::instance().start();
|
||||
|
||||
{
|
||||
app_config cfg(provider_type::encrypt, config_path);
|
||||
|
||||
@@ -668,6 +669,7 @@ TEST(providers, encrypt_provider) {
|
||||
provider.stop();
|
||||
mgr.stop();
|
||||
}
|
||||
|
||||
event_system::instance().stop();
|
||||
}
|
||||
|
||||
@@ -677,6 +679,7 @@ TEST(providers, s3_provider) {
|
||||
|
||||
console_consumer consumer{};
|
||||
event_system::instance().start();
|
||||
|
||||
{
|
||||
app_config cfg(provider_type::s3, config_path);
|
||||
{
|
||||
@@ -706,6 +709,7 @@ TEST(providers, s3_provider) {
|
||||
provider.stop();
|
||||
mgr.stop();
|
||||
}
|
||||
|
||||
event_system::instance().stop();
|
||||
}
|
||||
|
||||
@@ -715,6 +719,7 @@ TEST(providers, sia_provider) {
|
||||
|
||||
console_consumer consumer{};
|
||||
event_system::instance().start();
|
||||
|
||||
{
|
||||
app_config cfg(provider_type::sia, config_path);
|
||||
{
|
||||
@@ -744,6 +749,7 @@ TEST(providers, sia_provider) {
|
||||
provider.stop();
|
||||
mgr.stop();
|
||||
}
|
||||
|
||||
event_system::instance().stop();
|
||||
}
|
||||
} // namespace repertory
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -45,9 +45,13 @@ public:
|
||||
mock_provider provider;
|
||||
|
||||
protected:
|
||||
void SetUp() override { event_system::instance().start(); }
|
||||
void SetUp() override {
|
||||
event_system::instance().start();
|
||||
}
|
||||
|
||||
void TearDown() override { event_system::instance().stop(); }
|
||||
void TearDown() override {
|
||||
event_system::instance().stop();
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(ring_buffer_open_file_test, can_forward_to_last_chunk) {
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -21,6 +21,7 @@
|
||||
*/
|
||||
#include "test_common.hpp"
|
||||
|
||||
#include "events/types/file_upload_completed.hpp"
|
||||
#include "file_manager/upload.hpp"
|
||||
#include "mocks/mock_provider.hpp"
|
||||
#include "utils/event_capture.hpp"
|
||||
@@ -44,15 +45,14 @@ TEST(upload, can_upload_a_valid_file) {
|
||||
fsi.size = test_chunk_size * 4U;
|
||||
fsi.source_path = source_path;
|
||||
|
||||
event_consumer evt_com("file_upload_completed", [&fsi](const event &evt) {
|
||||
const auto &comp_evt = dynamic_cast<const file_upload_completed &>(evt);
|
||||
EXPECT_STREQ(fsi.api_path.c_str(),
|
||||
comp_evt.get_api_path().get<std::string>().c_str());
|
||||
EXPECT_STREQ(fsi.source_path.c_str(),
|
||||
comp_evt.get_source().get<std::string>().c_str());
|
||||
EXPECT_STREQ("success", comp_evt.get_result().get<std::string>().c_str());
|
||||
EXPECT_STREQ("0", comp_evt.get_cancelled().get<std::string>().c_str());
|
||||
});
|
||||
event_consumer evt_com(
|
||||
file_upload_completed::name, [&fsi](const i_event &evt) {
|
||||
const auto &comp_evt = dynamic_cast<const file_upload_completed &>(evt);
|
||||
EXPECT_STREQ(fsi.api_path.c_str(), comp_evt.api_path.c_str());
|
||||
EXPECT_STREQ(fsi.source_path.c_str(), comp_evt.source_path.c_str());
|
||||
EXPECT_EQ(api_error::success, comp_evt.error);
|
||||
EXPECT_FALSE(comp_evt.cancelled);
|
||||
});
|
||||
|
||||
EXPECT_CALL(mock_prov, upload_file(fsi.api_path, fsi.source_path, _))
|
||||
.WillOnce([](const std::string &, const std::string &,
|
||||
@@ -62,7 +62,7 @@ TEST(upload, can_upload_a_valid_file) {
|
||||
});
|
||||
upload upload(fsi, mock_prov);
|
||||
|
||||
event_capture evt_cap({"file_upload_completed"});
|
||||
event_capture evt_cap({file_upload_completed::name});
|
||||
evt_cap.wait_for_empty();
|
||||
|
||||
EXPECT_EQ(api_error::success, upload.get_api_error());
|
||||
@@ -87,16 +87,14 @@ TEST(upload, can_cancel_upload) {
|
||||
fsi.size = test_chunk_size * 4U;
|
||||
fsi.source_path = source_path;
|
||||
|
||||
event_consumer evt_con("file_upload_completed", [&fsi](const event &evt) {
|
||||
const auto &comp_evt = dynamic_cast<const file_upload_completed &>(evt);
|
||||
EXPECT_STREQ(fsi.api_path.c_str(),
|
||||
comp_evt.get_api_path().get<std::string>().c_str());
|
||||
EXPECT_STREQ(fsi.source_path.c_str(),
|
||||
comp_evt.get_source().get<std::string>().c_str());
|
||||
EXPECT_STREQ("comm_error",
|
||||
comp_evt.get_result().get<std::string>().c_str());
|
||||
EXPECT_STREQ("1", comp_evt.get_cancelled().get<std::string>().c_str());
|
||||
});
|
||||
event_consumer evt_con(
|
||||
file_upload_completed::name, [&fsi](const i_event &evt) {
|
||||
const auto &comp_evt = dynamic_cast<const file_upload_completed &>(evt);
|
||||
EXPECT_STREQ(fsi.api_path.c_str(), comp_evt.api_path.c_str());
|
||||
EXPECT_STREQ(fsi.source_path.c_str(), comp_evt.source_path.c_str());
|
||||
EXPECT_EQ(api_error::comm_error, comp_evt.error);
|
||||
EXPECT_TRUE(comp_evt.cancelled);
|
||||
});
|
||||
|
||||
std::mutex mtx;
|
||||
std::condition_variable notify;
|
||||
@@ -128,7 +126,7 @@ TEST(upload, can_cancel_upload) {
|
||||
notify.notify_one();
|
||||
lock.unlock();
|
||||
|
||||
event_capture evt_cap({"file_upload_completed"});
|
||||
event_capture evt_cap({file_upload_completed::name});
|
||||
evt_cap.wait_for_empty();
|
||||
|
||||
EXPECT_EQ(api_error::comm_error, upload.get_api_error());
|
||||
@@ -153,15 +151,14 @@ TEST(upload, can_stop_upload) {
|
||||
fsi.size = test_chunk_size * 4U;
|
||||
fsi.source_path = source_path;
|
||||
|
||||
event_consumer evt_con("file_upload_completed", [&fsi](const event &evt) {
|
||||
const auto &evt_com = dynamic_cast<const file_upload_completed &>(evt);
|
||||
EXPECT_STREQ(fsi.api_path.c_str(),
|
||||
evt_com.get_api_path().get<std::string>().c_str());
|
||||
EXPECT_STREQ(fsi.source_path.c_str(),
|
||||
evt_com.get_source().get<std::string>().c_str());
|
||||
EXPECT_STREQ("comm_error", evt_com.get_result().get<std::string>().c_str());
|
||||
EXPECT_STREQ("0", evt_com.get_cancelled().get<std::string>().c_str());
|
||||
});
|
||||
event_consumer evt_con(
|
||||
file_upload_completed::name, [&fsi](const i_event &evt) {
|
||||
const auto &evt_com = dynamic_cast<const file_upload_completed &>(evt);
|
||||
EXPECT_STREQ(fsi.api_path.c_str(), evt_com.api_path.c_str());
|
||||
EXPECT_STREQ(fsi.source_path.c_str(), evt_com.source_path.c_str());
|
||||
EXPECT_EQ(api_error::comm_error, evt_com.error);
|
||||
EXPECT_FALSE(evt_com.cancelled);
|
||||
});
|
||||
|
||||
EXPECT_CALL(mock_provider, upload_file(fsi.api_path, fsi.source_path, _))
|
||||
.WillOnce([](const std::string &, const std::string &,
|
||||
@@ -171,7 +168,7 @@ TEST(upload, can_stop_upload) {
|
||||
return api_error::comm_error;
|
||||
});
|
||||
|
||||
event_capture evt_cap({"file_upload_completed"});
|
||||
event_capture evt_cap({file_upload_completed::name});
|
||||
|
||||
{
|
||||
upload upload(fsi, mock_provider);
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -97,7 +97,7 @@ TYPED_TEST(winfsp_test, cr8_file_can_delete_file_after_close) {
|
||||
|
||||
TYPED_TEST(winfsp_test,
|
||||
cr8_file_cannot_create_files_with_invalid_characters_in_path) {
|
||||
for (auto &&invalid_char : std::array<std::string, 7U>{
|
||||
for (const auto &invalid_char : std::array<std::string, 7U>{
|
||||
{"*", ":", "<", ">", "?", "|", "\""},
|
||||
}) {
|
||||
auto handle = ::CreateFileA(
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2025> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
Reference in New Issue
Block a user