[unit test] Complete all providers unit tests #12
This commit is contained in:
@@ -79,6 +79,9 @@ public:
|
||||
std::uint32_t osx_flags, std::uint64_t size, const std::string &source_path,
|
||||
std::uint32_t uid, std::uint64_t written_date) -> api_meta_map;
|
||||
|
||||
[[nodiscard]] auto provider_meta_creator(bool directory, const api_file &file)
|
||||
-> api_meta_map;
|
||||
|
||||
[[nodiscard]] auto provider_meta_handler(i_provider &provider, bool directory,
|
||||
const api_file &file) -> api_error;
|
||||
} // namespace repertory
|
||||
|
@@ -66,6 +66,9 @@ public:
|
||||
std::uint32_t osx_flags, std::uint64_t size, const std::string &source_path,
|
||||
std::uint32_t uid, std::uint64_t written_date) -> api_meta_map;
|
||||
|
||||
[[nodiscard]] auto provider_meta_creator(bool directory, const api_file &file)
|
||||
-> api_meta_map;
|
||||
|
||||
[[nodiscard]] auto provider_meta_handler(i_provider &provider, bool directory,
|
||||
const api_file &file) -> api_error;
|
||||
} // namespace repertory
|
||||
|
@@ -235,11 +235,9 @@ auto create_meta_attributes(
|
||||
};
|
||||
}
|
||||
|
||||
auto provider_meta_handler(i_provider &provider, bool directory,
|
||||
const api_file &file) -> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
auto meta = create_meta_attributes(
|
||||
auto provider_meta_creator(bool directory, const api_file &file)
|
||||
-> api_meta_map {
|
||||
return create_meta_attributes(
|
||||
file.accessed_date,
|
||||
directory ? FILE_ATTRIBUTE_DIRECTORY : FILE_ATTRIBUTE_ARCHIVE,
|
||||
file.changed_date, file.creation_date, directory, getgid(), file.key,
|
||||
@@ -247,6 +245,13 @@ auto provider_meta_handler(i_provider &provider, bool directory,
|
||||
: S_IFREG | S_IRUSR | S_IWUSR,
|
||||
file.modified_date, 0U, 0U, file.file_size, file.source_path, getuid(),
|
||||
file.modified_date);
|
||||
}
|
||||
|
||||
auto provider_meta_handler(i_provider &provider, bool directory,
|
||||
const api_file &file) -> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
auto meta = provider_meta_creator(directory, file);
|
||||
auto res = provider.set_item_meta(file.api_path, meta);
|
||||
if (res == api_error::success) {
|
||||
event_system::instance().raise<filesystem_item_added>(
|
||||
|
@@ -217,16 +217,21 @@ auto create_meta_attributes(
|
||||
};
|
||||
}
|
||||
|
||||
auto provider_meta_handler(i_provider &provider, bool directory,
|
||||
const api_file &file) -> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
const auto meta = create_meta_attributes(
|
||||
auto provider_meta_creator(bool directory, const api_file &file)
|
||||
-> api_meta_map {
|
||||
return create_meta_attributes(
|
||||
file.accessed_date,
|
||||
directory ? FILE_ATTRIBUTE_DIRECTORY : FILE_ATTRIBUTE_ARCHIVE,
|
||||
file.changed_date, file.creation_date, directory, 0u, file.key,
|
||||
directory ? S_IFDIR : S_IFREG, file.modified_date, 0u, 0u, file.file_size,
|
||||
file.source_path, 0u, file.modified_date);
|
||||
}
|
||||
|
||||
auto provider_meta_handler(i_provider &provider, bool directory,
|
||||
const api_file &file) -> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
auto meta = provider_meta_creator(directory, file);
|
||||
auto res = provider.set_item_meta(file.api_path, meta);
|
||||
if (res == api_error::success) {
|
||||
event_system::instance().raise<filesystem_item_added>(
|
||||
|
@@ -31,6 +31,7 @@
|
||||
#include "events/types/service_start_end.hpp"
|
||||
#include "events/types/service_stop_begin.hpp"
|
||||
#include "events/types/service_stop_end.hpp"
|
||||
#include "platform/platform.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "types/startup_exception.hpp"
|
||||
#include "utils/base64.hpp"
|
||||
@@ -83,29 +84,22 @@ void encrypt_provider::create_item_meta(api_meta_map &meta, bool directory,
|
||||
stat(file.source_path.c_str(), &buf);
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
meta[META_ACCESSED] = std::to_string(file.accessed_date);
|
||||
meta = provider_meta_creator(directory, file);
|
||||
|
||||
#if defined(_WIN32)
|
||||
meta[META_ATTRIBUTES] =
|
||||
std::to_string(::GetFileAttributesA(file.source_path.c_str()) &
|
||||
~static_cast<DWORD>(FILE_ATTRIBUTE_REPARSE_POINT));
|
||||
|
||||
#endif // defined(_WIN32)
|
||||
#if defined(__APPLE__)
|
||||
meta[META_BACKUP];
|
||||
#endif // defined(__APPLE__)
|
||||
meta[META_CHANGED] = std::to_string(file.changed_date);
|
||||
meta[META_CREATION] = std::to_string(file.creation_date);
|
||||
meta[META_DIRECTORY] = utils::string::from_bool(directory);
|
||||
meta[META_GID] = std::to_string(buf.st_gid);
|
||||
|
||||
meta[META_MODE] = std::to_string(buf.st_mode);
|
||||
meta[META_MODIFIED] = std::to_string(file.modified_date);
|
||||
meta[META_GID] = std::to_string(buf.st_gid);
|
||||
meta[META_UID] = std::to_string(buf.st_uid);
|
||||
|
||||
#if defined(__APPLE__)
|
||||
meta[META_BACKUP] = std::to_string(buf.st_bkuptime);
|
||||
meta[META_OSXFLAGS] = std::to_string(buf.st_flags);
|
||||
#endif // defined(__APPLE__)
|
||||
meta[META_SIZE] = std::to_string(file.file_size);
|
||||
meta[META_SOURCE] = file.source_path;
|
||||
meta[META_UID] = std::to_string(buf.st_uid);
|
||||
meta[META_WRITTEN] = std::to_string(file.modified_date);
|
||||
}
|
||||
|
||||
auto encrypt_provider::create_directory(const std::string &api_path,
|
||||
|
@@ -809,6 +809,23 @@ auto sia_provider::rename_file(const std::string &from_api_path,
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
try {
|
||||
bool exists{};
|
||||
auto res = is_file(to_api_path, exists);
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
}
|
||||
if (exists) {
|
||||
return api_error::item_exists;
|
||||
}
|
||||
|
||||
res = is_directory(to_api_path, exists);
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
}
|
||||
if (exists) {
|
||||
return api_error::directory_exists;
|
||||
}
|
||||
|
||||
curl::requests::http_post post{};
|
||||
post.json = nlohmann::json({
|
||||
{"bucket", get_sia_config().bucket},
|
||||
@@ -842,7 +859,7 @@ auto sia_provider::rename_file(const std::string &from_api_path,
|
||||
function_name, fmt::format("{}|{}", from_api_path, to_api_path),
|
||||
response_code,
|
||||
fmt::format("failed to rename file file|response|{}", error_data));
|
||||
return api_error::comm_error;
|
||||
return api_error::item_not_found;
|
||||
}
|
||||
|
||||
return get_db().rename_item_meta(from_api_path, to_api_path);
|
||||
|
Reference in New Issue
Block a user