updated build system
This commit is contained in:
@ -23,7 +23,7 @@
|
||||
#define INCLUDE_COMM_CURL_CURL_REQUESTS_HTTP_REQUEST_BASE_HPP_
|
||||
|
||||
#include "types/repertory.hpp"
|
||||
#include "utils/native_file.hpp"
|
||||
#include "utils/file.hpp"
|
||||
|
||||
namespace repertory::curl::requests {
|
||||
using read_callback = size_t (*)(char *, size_t, size_t, void *);
|
||||
@ -33,7 +33,7 @@ using response_callback =
|
||||
|
||||
struct read_file_info final {
|
||||
stop_type &stop_requested;
|
||||
native_file::native_file_ptr nf{};
|
||||
utils::file::file file{};
|
||||
std::uint64_t offset{};
|
||||
};
|
||||
|
||||
@ -41,9 +41,9 @@ inline const auto read_file_data = static_cast<read_callback>(
|
||||
[](char *buffer, size_t size, size_t nitems, void *instream) -> size_t {
|
||||
auto *read_info = reinterpret_cast<read_file_info *>(instream);
|
||||
std::size_t bytes_read{};
|
||||
auto ret = read_info->nf->read_bytes(
|
||||
reinterpret_cast<unsigned char *>(buffer), size * nitems,
|
||||
read_info->offset, bytes_read);
|
||||
auto ret =
|
||||
read_info->file.read(reinterpret_cast<unsigned char *>(buffer),
|
||||
size * nitems, read_info->offset, &bytes_read);
|
||||
if (ret) {
|
||||
read_info->offset += bytes_read;
|
||||
}
|
||||
|
@ -61,14 +61,11 @@ inline constexpr const std::uint64_t REPERTORY_CONFIG_VERSION = 0ULL;
|
||||
inline constexpr const std::string_view REPERTORY_DATA_NAME = "repertory2";
|
||||
inline constexpr const std::string_view REPERTORY_MIN_REMOTE_VERSION = "2.0.0";
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define REPERTORY_INVALID_HANDLE INVALID_HANDLE_VALUE
|
||||
#if defined(_WIN32)
|
||||
#define REPERTORY_API_INVALID_HANDLE static_cast<std::uint64_t>(-1)
|
||||
using native_handle = HANDLE;
|
||||
#else
|
||||
#define REPERTORY_INVALID_HANDLE (-1)
|
||||
#define REPERTORY_API_INVALID_HANDLE REPERTORY_INVALID_HANDLE
|
||||
using native_handle = int;
|
||||
#endif
|
||||
|
||||
inline constexpr const auto NANOS_PER_SECOND = 1000000000L;
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include "file_manager/i_upload_manager.hpp"
|
||||
#include "platform/platform.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "utils/native_file.hpp"
|
||||
#include "utils/file.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class app_config;
|
||||
@ -131,7 +131,7 @@ public:
|
||||
std::atomic<std::chrono::system_clock::time_point> last_access_{
|
||||
std::chrono::system_clock::now()};
|
||||
bool modified_{false};
|
||||
native_file_ptr nf_;
|
||||
utils::file::file nf_;
|
||||
mutable std::mutex io_thread_mtx_;
|
||||
std::condition_variable io_thread_notify_;
|
||||
std::deque<std::shared_ptr<io_item>> io_thread_queue_;
|
||||
|
@ -51,8 +51,6 @@ const std::vector<std::string> META_USED_NAMES = {
|
||||
|
||||
using api_meta_map = std::map<std::string, std::string>;
|
||||
|
||||
using stop_type = std::atomic<bool>;
|
||||
|
||||
enum class api_error {
|
||||
success = 0,
|
||||
access_denied,
|
||||
|
@ -1,140 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2024> <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
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_UTILS_ENCRYPTING_READER_HPP_
|
||||
#define INCLUDE_UTILS_ENCRYPTING_READER_HPP_
|
||||
|
||||
#include "types/repertory.hpp"
|
||||
#include "utils/encryption.hpp"
|
||||
#include "utils/native_file.hpp"
|
||||
|
||||
namespace repertory::utils::encryption {
|
||||
class encrypting_reader final {
|
||||
public:
|
||||
encrypting_reader(std::string_view file_name, std::string_view source_path,
|
||||
stop_type &stop_requested, std::string_view token,
|
||||
std::optional<std::string_view> relative_parent_path,
|
||||
std::size_t error_return = 0U);
|
||||
|
||||
encrypting_reader(std::string_view encrypted_file_path,
|
||||
std::string_view source_path, stop_type &stop_requested,
|
||||
std::string_view token, std::size_t error_return = 0U);
|
||||
|
||||
encrypting_reader(
|
||||
std::string_view encrypted_file_path, std::string_view source_path,
|
||||
stop_type &stop_requested, std::string_view token,
|
||||
std::vector<std::array<unsigned char,
|
||||
crypto_aead_xchacha20poly1305_IETF_NPUBBYTES>>
|
||||
iv_list,
|
||||
std::size_t error_return = 0U);
|
||||
|
||||
encrypting_reader(const encrypting_reader &reader);
|
||||
encrypting_reader(encrypting_reader &&) = delete;
|
||||
|
||||
auto operator=(const encrypting_reader &) -> encrypting_reader & = delete;
|
||||
auto operator=(encrypting_reader &&) -> encrypting_reader & = delete;
|
||||
|
||||
~encrypting_reader();
|
||||
|
||||
public:
|
||||
using iostream = std::basic_iostream<char, std::char_traits<char>>;
|
||||
using streambuf = std::basic_streambuf<char, std::char_traits<char>>;
|
||||
|
||||
private:
|
||||
utils::encryption::hash_256_t key_;
|
||||
stop_type &stop_requested_;
|
||||
size_t error_return_;
|
||||
std::unordered_map<std::size_t, data_buffer> chunk_buffers_;
|
||||
std::string encrypted_file_name_;
|
||||
std::string encrypted_file_path_;
|
||||
std::vector<
|
||||
std::array<unsigned char, crypto_aead_xchacha20poly1305_IETF_NPUBBYTES>>
|
||||
iv_list_;
|
||||
std::size_t last_data_chunk_{};
|
||||
std::size_t last_data_chunk_size_{};
|
||||
std::uint64_t read_offset_{};
|
||||
native_file_ptr source_file_;
|
||||
std::uint64_t total_size_{};
|
||||
|
||||
private:
|
||||
static const std::size_t header_size_;
|
||||
static const std::size_t data_chunk_size_;
|
||||
static const std::size_t encrypted_chunk_size_;
|
||||
|
||||
private:
|
||||
auto reader_function(char *buffer, size_t size, size_t nitems) -> size_t;
|
||||
|
||||
public:
|
||||
[[nodiscard]] static auto
|
||||
calculate_decrypted_size(std::uint64_t total_size) -> std::uint64_t;
|
||||
|
||||
[[nodiscard]] static auto
|
||||
calculate_encrypted_size(std::string_view source_path) -> std::uint64_t;
|
||||
|
||||
[[nodiscard]] auto create_iostream() const -> std::shared_ptr<iostream>;
|
||||
|
||||
[[nodiscard]] static constexpr auto
|
||||
get_encrypted_chunk_size() -> std::size_t {
|
||||
return encrypted_chunk_size_;
|
||||
}
|
||||
|
||||
[[nodiscard]] static constexpr auto get_data_chunk_size() -> std::size_t {
|
||||
return data_chunk_size_;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_encrypted_file_name() const -> std::string {
|
||||
return encrypted_file_name_;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_encrypted_file_path() const -> std::string {
|
||||
return encrypted_file_path_;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_error_return() const -> std::size_t {
|
||||
return error_return_;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_iv_list()
|
||||
-> std::vector<std::array<unsigned char,
|
||||
crypto_aead_xchacha20poly1305_IETF_NPUBBYTES>> {
|
||||
return iv_list_;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_stop_requested() const -> bool {
|
||||
return stop_requested_;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_total_size() const -> std::uint64_t {
|
||||
return total_size_;
|
||||
}
|
||||
|
||||
[[nodiscard]] static auto reader_function(char *buffer, size_t size,
|
||||
size_t nitems,
|
||||
void *instream) -> size_t {
|
||||
return reinterpret_cast<encrypting_reader *>(instream)->reader_function(
|
||||
buffer, size, nitems);
|
||||
}
|
||||
|
||||
void set_read_position(std::uint64_t position) { read_offset_ = position; }
|
||||
};
|
||||
} // namespace repertory::utils::encryption
|
||||
|
||||
#endif // INCLUDE_UTILS_ENCRYPTING_READER_HPP_
|
@ -24,7 +24,6 @@
|
||||
|
||||
#include "types/repertory.hpp"
|
||||
#include "utils/file.hpp"
|
||||
#include "utils/native_file.hpp"
|
||||
|
||||
namespace repertory::utils::file {
|
||||
// Prototypes
|
||||
|
@ -24,8 +24,8 @@
|
||||
#include "utils/string.hpp"
|
||||
|
||||
namespace repertory::curl::requests {
|
||||
auto http_put_file::set_method(CURL *curl, stop_type &stop_requested) const
|
||||
-> bool {
|
||||
auto http_put_file::set_method(CURL *curl,
|
||||
stop_type &stop_requested) const -> bool {
|
||||
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");
|
||||
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
|
||||
|
||||
@ -46,19 +46,14 @@ auto http_put_file::set_method(CURL *curl, stop_type &stop_requested) const
|
||||
|
||||
read_info = std::make_shared<read_file_info>(read_file_info{
|
||||
stop_requested,
|
||||
utils::file::file::open_or_create_file(source_path),
|
||||
});
|
||||
|
||||
if (native_file::create_or_open(source_path, read_info->nf) !=
|
||||
api_error::success) {
|
||||
if (not read_info->file) {
|
||||
return false;
|
||||
}
|
||||
|
||||
read_info->nf->set_auto_close(true);
|
||||
|
||||
std::uint64_t file_size{};
|
||||
if (not read_info->nf->get_file_size(file_size)) {
|
||||
return false;
|
||||
}
|
||||
auto file_size = read_info->file.size();
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_READDATA, read_info.get());
|
||||
curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_file_data);
|
||||
|
@ -66,8 +66,9 @@ file_manager::open_file::open_file(
|
||||
}
|
||||
|
||||
if (not fsi.directory) {
|
||||
set_api_error(native_file::create_or_open(fsi.source_path,
|
||||
provider_.is_direct_only(), nf_));
|
||||
nf_ = utils::file::file::open_or_create_file(fsi.source_path,
|
||||
provider_.is_direct_only());
|
||||
set_api_error(nf_ ? api_error::success : api_error::os_error);
|
||||
if (get_api_error() == api_error::success) {
|
||||
if (read_state.has_value()) {
|
||||
read_state_ = read_state.value();
|
||||
@ -77,20 +78,16 @@ file_manager::open_file::open_file(
|
||||
fsi_.size, chunk_size)),
|
||||
false);
|
||||
|
||||
std::uint64_t file_size{};
|
||||
if (nf_->get_file_size(file_size)) {
|
||||
if (provider_.is_direct_only() || file_size == fsi.size) {
|
||||
read_state_.set(0U, read_state_.size(), true);
|
||||
} else if (not nf_->truncate(fsi.size)) {
|
||||
set_api_error(api_error::os_error);
|
||||
}
|
||||
} else {
|
||||
auto file_size = nf_.size();
|
||||
if (provider_.is_direct_only() || file_size == fsi.size) {
|
||||
read_state_.set(0U, read_state_.size(), true);
|
||||
} else if (not nf_.truncate(fsi.size)) {
|
||||
set_api_error(api_error::os_error);
|
||||
}
|
||||
}
|
||||
|
||||
if (get_api_error() != api_error::success && nf_) {
|
||||
nf_->close();
|
||||
nf_.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -185,8 +182,7 @@ void file_manager::open_file::download_chunk(std::size_t chunk,
|
||||
|
||||
res = do_io([&]() -> api_error {
|
||||
std::size_t bytes_written{};
|
||||
if (not nf_->write_bytes(data.data(), data.size(), data_offset,
|
||||
bytes_written)) {
|
||||
if (not nf_.write(data, data_offset, &bytes_written)) {
|
||||
return api_error::os_error;
|
||||
}
|
||||
|
||||
@ -246,7 +242,7 @@ auto file_manager::open_file::native_operation(
|
||||
}
|
||||
file_lock.unlock();
|
||||
|
||||
return do_io([&]() -> api_error { return callback(nf_->get_handle()); });
|
||||
return do_io([&]() -> api_error { return callback(nf_.get_handle()); });
|
||||
}
|
||||
|
||||
auto file_manager::open_file::native_operation(
|
||||
@ -287,7 +283,7 @@ auto file_manager::open_file::native_operation(
|
||||
|
||||
const auto original_file_size = get_file_size();
|
||||
|
||||
auto res = do_io([&]() -> api_error { return callback(nf_->get_handle()); });
|
||||
auto res = do_io([&]() -> api_error { return callback(nf_.get_handle()); });
|
||||
if (res != api_error::success) {
|
||||
utils::error::raise_api_path_error(function_name, get_api_path(),
|
||||
utils::get_last_error_code(),
|
||||
@ -296,14 +292,7 @@ auto file_manager::open_file::native_operation(
|
||||
}
|
||||
|
||||
{
|
||||
std::uint64_t file_size{};
|
||||
if (not nf_->get_file_size(file_size)) {
|
||||
utils::error::raise_api_path_error(function_name, get_api_path(),
|
||||
utils::get_last_error_code(),
|
||||
"failed to get file size");
|
||||
return set_api_error(api_error::os_error);
|
||||
}
|
||||
|
||||
auto file_size = nf_.size();
|
||||
if (file_size != new_file_size) {
|
||||
utils::error::raise_api_path_error(
|
||||
function_name, get_api_path(), api_error::file_size_mismatch,
|
||||
@ -372,7 +361,7 @@ auto file_manager::open_file::read(std::size_t read_size,
|
||||
|
||||
data.resize(read_size);
|
||||
std::size_t bytes_read{};
|
||||
return nf_->read_bytes(data.data(), read_size, read_offset, bytes_read)
|
||||
return nf_.read(data.data(), read_size, read_offset, &bytes_read)
|
||||
? api_error::success
|
||||
: api_error::os_error;
|
||||
});
|
||||
@ -423,8 +412,8 @@ auto file_manager::open_file::resize(std::uint64_t new_file_size) -> api_error {
|
||||
|
||||
return native_operation(
|
||||
new_file_size, [this, &new_file_size](native_handle) -> api_error {
|
||||
return nf_->truncate(new_file_size) ? api_error::success
|
||||
: api_error::os_error;
|
||||
return nf_.truncate(new_file_size) ? api_error::success
|
||||
: api_error::os_error;
|
||||
});
|
||||
}
|
||||
|
||||
@ -460,8 +449,7 @@ auto file_manager::open_file::close() -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
nf_->close();
|
||||
nf_.reset();
|
||||
nf_.close();
|
||||
|
||||
if (modified_ && (get_api_error() == api_error::success)) {
|
||||
mgr_.queue_upload(*this);
|
||||
@ -587,8 +575,7 @@ auto file_manager::open_file::write(std::uint64_t write_offset,
|
||||
}
|
||||
|
||||
auto res = do_io([&]() -> api_error {
|
||||
if (not nf_->write_bytes(data.data(), data.size(), write_offset,
|
||||
bytes_written)) {
|
||||
if (not nf_.write(data.data(), data.size(), write_offset, &bytes_written)) {
|
||||
return api_error::os_error;
|
||||
}
|
||||
|
||||
|
@ -72,14 +72,14 @@ file_manager::ring_buffer_open_file::ring_buffer_open_file(
|
||||
|
||||
fsi_.source_path =
|
||||
utils::path::combine(buffer_directory, {utils::create_uuid_string()});
|
||||
auto res = native_file::create_or_open(fsi_.source_path, nf_);
|
||||
if (res != api_error::success) {
|
||||
nf_ = utils::file::file::open_or_create_file(fsi_.source_path);
|
||||
if (not nf_) {
|
||||
throw std::runtime_error("failed to create buffer file|err|" +
|
||||
std::to_string(utils::get_last_error_code()));
|
||||
}
|
||||
|
||||
if (not nf_->truncate(ring_state_.size() * chunk_size)) {
|
||||
nf_->close();
|
||||
if (not nf_.truncate(ring_state_.size() * chunk_size)) {
|
||||
nf_.close();
|
||||
throw std::runtime_error("failed to resize buffer file|err|" +
|
||||
std::to_string(utils::get_last_error_code()));
|
||||
}
|
||||
@ -92,7 +92,7 @@ file_manager::ring_buffer_open_file::~ring_buffer_open_file() {
|
||||
|
||||
close();
|
||||
|
||||
nf_->close();
|
||||
nf_.close();
|
||||
if (not utils::file::retry_delete_file(fsi_.source_path)) {
|
||||
utils::error::raise_api_path_error(
|
||||
function_name, fsi_.api_path, fsi_.source_path,
|
||||
@ -128,9 +128,8 @@ auto file_manager::file_manager::ring_buffer_open_file::download_chunk(
|
||||
if (res == api_error::success) {
|
||||
res = do_io([&]() -> api_error {
|
||||
std::size_t bytes_written{};
|
||||
if (not nf_->write_bytes(buffer.data(), buffer.size(),
|
||||
(chunk % ring_state_.size()) * chunk_size_,
|
||||
bytes_written)) {
|
||||
if (not nf_.write(buffer, (chunk % ring_state_.size()) * chunk_size_,
|
||||
&bytes_written)) {
|
||||
return api_error::os_error;
|
||||
}
|
||||
|
||||
@ -201,7 +200,7 @@ auto file_manager::ring_buffer_open_file::is_download_complete() const -> bool {
|
||||
|
||||
auto file_manager::ring_buffer_open_file::native_operation(
|
||||
i_open_file::native_operation_callback callback) -> api_error {
|
||||
return do_io([&]() -> api_error { return callback(nf_->get_handle()); });
|
||||
return do_io([&]() -> api_error { return callback(nf_.get_handle()); });
|
||||
}
|
||||
|
||||
void file_manager::ring_buffer_open_file::reverse(std::size_t count) {
|
||||
@ -270,11 +269,11 @@ auto file_manager::ring_buffer_open_file::read(std::size_t read_size,
|
||||
res = do_io([this, &buffer, &chunk, &data, read_offset,
|
||||
&to_read]() -> api_error {
|
||||
std::size_t bytes_read{};
|
||||
auto ret = nf_->read_bytes(buffer.data(), buffer.size(),
|
||||
((chunk % ring_state_.size()) * chunk_size_),
|
||||
bytes_read)
|
||||
? api_error::success
|
||||
: api_error::os_error;
|
||||
auto ret =
|
||||
nf_.read(buffer, ((chunk % ring_state_.size()) * chunk_size_),
|
||||
&bytes_read)
|
||||
? api_error::success
|
||||
: api_error::os_error;
|
||||
if (ret == api_error::success) {
|
||||
data.insert(data.end(),
|
||||
buffer.begin() + static_cast<std::int64_t>(read_offset),
|
||||
|
@ -1,405 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2024> <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
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#include "utils/encrypting_reader.hpp"
|
||||
|
||||
#include "platform/platform.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
#include "utils/collection.hpp"
|
||||
#include "utils/common.hpp"
|
||||
#include "utils/error_utils.hpp"
|
||||
#include "utils/file.hpp"
|
||||
|
||||
namespace repertory::utils::encryption {
|
||||
class encrypting_streambuf final : public encrypting_reader::streambuf {
|
||||
public:
|
||||
encrypting_streambuf(const encrypting_streambuf &) = default;
|
||||
encrypting_streambuf(encrypting_streambuf &&) = delete;
|
||||
auto
|
||||
operator=(const encrypting_streambuf &) -> encrypting_streambuf & = delete;
|
||||
auto operator=(encrypting_streambuf &&) -> encrypting_streambuf & = delete;
|
||||
|
||||
explicit encrypting_streambuf(const encrypting_reader &reader)
|
||||
: reader_(reader) {
|
||||
setg(reinterpret_cast<char *>(0), reinterpret_cast<char *>(0),
|
||||
reinterpret_cast<char *>(reader_.get_total_size()));
|
||||
}
|
||||
|
||||
~encrypting_streambuf() override = default;
|
||||
|
||||
private:
|
||||
encrypting_reader reader_;
|
||||
|
||||
protected:
|
||||
auto seekoff(off_type off, std::ios_base::seekdir dir,
|
||||
std::ios_base::openmode which = std::ios_base::out |
|
||||
std::ios_base::in)
|
||||
-> pos_type override {
|
||||
if ((which & std::ios_base::in) != std::ios_base::in) {
|
||||
throw std::runtime_error("output is not supported");
|
||||
}
|
||||
|
||||
const auto set_position = [this](char *next) -> pos_type {
|
||||
if ((next <= egptr()) && (next >= eback())) {
|
||||
setg(eback(), next, reinterpret_cast<char *>(reader_.get_total_size()));
|
||||
return static_cast<std::streamoff>(
|
||||
reinterpret_cast<std::uintptr_t>(gptr()));
|
||||
}
|
||||
|
||||
return {traits_type::eof()};
|
||||
};
|
||||
|
||||
switch (dir) {
|
||||
case std::ios_base::beg:
|
||||
return set_position(eback() + off);
|
||||
|
||||
case std::ios_base::cur:
|
||||
return set_position(gptr() + off);
|
||||
|
||||
case std::ios_base::end:
|
||||
return set_position(egptr() + off);
|
||||
}
|
||||
|
||||
return encrypting_reader::streambuf::seekoff(off, dir, which);
|
||||
}
|
||||
|
||||
auto seekpos(pos_type pos, std::ios_base::openmode which =
|
||||
std::ios_base::out |
|
||||
std::ios_base::in) -> pos_type override {
|
||||
return seekoff(pos, std::ios_base::beg, which);
|
||||
}
|
||||
|
||||
auto uflow() -> int_type override {
|
||||
auto ret = underflow();
|
||||
if (ret == traits_type::eof()) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
gbump(1);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
auto underflow() -> int_type override {
|
||||
if (gptr() == egptr()) {
|
||||
return traits_type::eof();
|
||||
}
|
||||
|
||||
reader_.set_read_position(reinterpret_cast<std::uintptr_t>(gptr()));
|
||||
|
||||
char c{};
|
||||
const auto res = encrypting_reader::reader_function(&c, 1U, 1U, &reader_);
|
||||
if (res != 1) {
|
||||
return traits_type::eof();
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
auto xsgetn(char *ptr, std::streamsize count) -> std::streamsize override {
|
||||
if (gptr() == egptr()) {
|
||||
return traits_type::eof();
|
||||
}
|
||||
|
||||
reader_.set_read_position(reinterpret_cast<std::uintptr_t>(gptr()));
|
||||
|
||||
const auto res = encrypting_reader::reader_function(
|
||||
ptr, 1U, static_cast<std::size_t>(count), &reader_);
|
||||
if ((res == reader_.get_error_return()) ||
|
||||
(reader_.get_stop_requested() && (res == CURL_READFUNC_ABORT))) {
|
||||
return traits_type::eof();
|
||||
}
|
||||
|
||||
setg(eback(), gptr() + res,
|
||||
reinterpret_cast<char *>(reader_.get_total_size()));
|
||||
return static_cast<std::streamsize>(res);
|
||||
}
|
||||
};
|
||||
|
||||
class encrypting_reader_iostream final : public encrypting_reader::iostream {
|
||||
public:
|
||||
encrypting_reader_iostream(const encrypting_reader_iostream &) = delete;
|
||||
encrypting_reader_iostream(encrypting_reader_iostream &&) = delete;
|
||||
|
||||
auto operator=(const encrypting_reader_iostream &)
|
||||
-> encrypting_reader_iostream & = delete;
|
||||
auto operator=(encrypting_reader_iostream &&)
|
||||
-> encrypting_reader_iostream & = delete;
|
||||
|
||||
explicit encrypting_reader_iostream(
|
||||
std::unique_ptr<encrypting_streambuf> buffer)
|
||||
: encrypting_reader::iostream(buffer.get()), buffer_(std::move(buffer)) {}
|
||||
|
||||
~encrypting_reader_iostream() override = default;
|
||||
|
||||
private:
|
||||
std::unique_ptr<encrypting_streambuf> buffer_;
|
||||
};
|
||||
|
||||
const std::size_t encrypting_reader::header_size_ = ([]() {
|
||||
return crypto_aead_xchacha20poly1305_IETF_NPUBBYTES +
|
||||
crypto_aead_xchacha20poly1305_IETF_ABYTES;
|
||||
})();
|
||||
const std::size_t encrypting_reader::data_chunk_size_ = (8UL * 1024UL * 1024UL);
|
||||
const std::size_t encrypting_reader::encrypted_chunk_size_ =
|
||||
data_chunk_size_ + header_size_;
|
||||
|
||||
encrypting_reader::encrypting_reader(
|
||||
std::string_view file_name, std::string_view source_path,
|
||||
stop_type &stop_requested, std::string_view token,
|
||||
std::optional<std::string_view> relative_parent_path,
|
||||
std::size_t error_return)
|
||||
: key_(utils::encryption::generate_key<utils::encryption::hash_256_t>(
|
||||
token)),
|
||||
stop_requested_(stop_requested),
|
||||
error_return_(error_return) {
|
||||
const auto res = native_file::create_or_open(source_path, true, source_file_);
|
||||
if (res != api_error::success) {
|
||||
throw std::runtime_error("file open failed|src|" +
|
||||
std::string{source_path} + '|' +
|
||||
api_error_to_string(res));
|
||||
}
|
||||
|
||||
data_buffer result;
|
||||
utils::encryption::encrypt_data(
|
||||
key_, reinterpret_cast<const unsigned char *>(file_name.data()),
|
||||
file_name.size(), result);
|
||||
encrypted_file_name_ = utils::collection::to_hex_string(result);
|
||||
|
||||
if (relative_parent_path.has_value()) {
|
||||
for (auto &&part : std::filesystem::path(relative_parent_path.value())) {
|
||||
utils::encryption::encrypt_data(
|
||||
key_, reinterpret_cast<const unsigned char *>(part.string().c_str()),
|
||||
strnlen(part.string().c_str(), part.string().size()), result);
|
||||
encrypted_file_path_ += '/' + utils::collection::to_hex_string(result);
|
||||
}
|
||||
encrypted_file_path_ += '/' + encrypted_file_name_;
|
||||
}
|
||||
|
||||
std::uint64_t file_size{};
|
||||
if (not utils::file::get_file_size(source_path, file_size)) {
|
||||
throw std::runtime_error("get file size failed|src|" +
|
||||
std::string{source_path} + '|' +
|
||||
std::to_string(utils::get_last_error_code()));
|
||||
}
|
||||
|
||||
const auto total_chunks = utils::divide_with_ceiling(
|
||||
file_size, static_cast<std::uint64_t>(data_chunk_size_));
|
||||
total_size_ = file_size + (total_chunks * encryption_header_size);
|
||||
last_data_chunk_ = total_chunks - 1U;
|
||||
last_data_chunk_size_ = (file_size <= data_chunk_size_) ? file_size
|
||||
: (file_size % data_chunk_size_) == 0U
|
||||
? data_chunk_size_
|
||||
: file_size % data_chunk_size_;
|
||||
iv_list_.resize(total_chunks);
|
||||
for (auto &iv : iv_list_) {
|
||||
randombytes_buf(iv.data(), iv.size());
|
||||
}
|
||||
}
|
||||
|
||||
encrypting_reader::encrypting_reader(std::string_view encrypted_file_path,
|
||||
std::string_view source_path,
|
||||
stop_type &stop_requested,
|
||||
std::string_view token,
|
||||
std::size_t error_return)
|
||||
: key_(utils::encryption::generate_key<utils::encryption::hash_256_t>(
|
||||
token)),
|
||||
stop_requested_(stop_requested),
|
||||
error_return_(error_return) {
|
||||
const auto res = native_file::create_or_open(source_path, true, source_file_);
|
||||
if (res != api_error::success) {
|
||||
throw std::runtime_error("file open failed|src|" +
|
||||
std::string{source_path} + '|' +
|
||||
api_error_to_string(res));
|
||||
}
|
||||
|
||||
encrypted_file_path_ = encrypted_file_path;
|
||||
encrypted_file_name_ =
|
||||
std::filesystem::path(encrypted_file_path_).filename().string();
|
||||
|
||||
std::uint64_t file_size{};
|
||||
if (not utils::file::get_file_size(source_path, file_size)) {
|
||||
throw std::runtime_error("get file size failed|src|" +
|
||||
std::string{source_path} + '|' +
|
||||
std::to_string(utils::get_last_error_code()));
|
||||
}
|
||||
|
||||
const auto total_chunks = utils::divide_with_ceiling(
|
||||
file_size, static_cast<std::uint64_t>(data_chunk_size_));
|
||||
total_size_ = file_size + (total_chunks * encryption_header_size);
|
||||
last_data_chunk_ = total_chunks - 1U;
|
||||
last_data_chunk_size_ = (file_size <= data_chunk_size_) ? file_size
|
||||
: (file_size % data_chunk_size_) == 0U
|
||||
? data_chunk_size_
|
||||
: file_size % data_chunk_size_;
|
||||
iv_list_.resize(total_chunks);
|
||||
for (auto &iv : iv_list_) {
|
||||
randombytes_buf(iv.data(), iv.size());
|
||||
}
|
||||
}
|
||||
|
||||
encrypting_reader::encrypting_reader(
|
||||
std::string_view encrypted_file_path, std::string_view source_path,
|
||||
stop_type &stop_requested, std::string_view token,
|
||||
std::vector<
|
||||
std::array<unsigned char, crypto_aead_xchacha20poly1305_IETF_NPUBBYTES>>
|
||||
iv_list,
|
||||
std::size_t error_return)
|
||||
: key_(utils::encryption::generate_key<utils::encryption::hash_256_t>(
|
||||
token)),
|
||||
stop_requested_(stop_requested),
|
||||
error_return_(error_return) {
|
||||
const auto res = native_file::create_or_open(source_path, true, source_file_);
|
||||
if (res != api_error::success) {
|
||||
throw std::runtime_error("file open failed|src|" +
|
||||
std::string{source_path} + '|' +
|
||||
api_error_to_string(res));
|
||||
}
|
||||
|
||||
encrypted_file_path_ = encrypted_file_path;
|
||||
encrypted_file_name_ =
|
||||
std::filesystem::path(encrypted_file_path_).filename().string();
|
||||
|
||||
std::uint64_t file_size{};
|
||||
if (not utils::file::get_file_size(source_path, file_size)) {
|
||||
throw std::runtime_error("get file size failed|src|" +
|
||||
std::string{source_path} + '|' +
|
||||
std::to_string(utils::get_last_error_code()));
|
||||
}
|
||||
|
||||
const auto total_chunks = utils::divide_with_ceiling(
|
||||
file_size, static_cast<std::uint64_t>(data_chunk_size_));
|
||||
total_size_ = file_size + (total_chunks * encryption_header_size);
|
||||
last_data_chunk_ = total_chunks - 1U;
|
||||
last_data_chunk_size_ = (file_size <= data_chunk_size_) ? file_size
|
||||
: (file_size % data_chunk_size_) == 0U
|
||||
? data_chunk_size_
|
||||
: file_size % data_chunk_size_;
|
||||
iv_list_ = std::move(iv_list);
|
||||
}
|
||||
|
||||
encrypting_reader::encrypting_reader(const encrypting_reader &reader)
|
||||
: key_(reader.key_),
|
||||
stop_requested_(reader.stop_requested_),
|
||||
error_return_(reader.error_return_),
|
||||
chunk_buffers_(reader.chunk_buffers_),
|
||||
encrypted_file_name_(reader.encrypted_file_name_),
|
||||
encrypted_file_path_(reader.encrypted_file_path_),
|
||||
iv_list_(reader.iv_list_),
|
||||
last_data_chunk_(reader.last_data_chunk_),
|
||||
last_data_chunk_size_(reader.last_data_chunk_size_),
|
||||
read_offset_(reader.read_offset_),
|
||||
source_file_(native_file::clone(reader.source_file_)),
|
||||
total_size_(reader.total_size_) {}
|
||||
|
||||
encrypting_reader::~encrypting_reader() {
|
||||
if (source_file_) {
|
||||
source_file_->close();
|
||||
}
|
||||
}
|
||||
|
||||
auto encrypting_reader::calculate_decrypted_size(std::uint64_t total_size)
|
||||
-> std::uint64_t {
|
||||
return total_size - (utils::divide_with_ceiling(
|
||||
total_size, static_cast<std::uint64_t>(
|
||||
get_encrypted_chunk_size())) *
|
||||
encryption_header_size);
|
||||
}
|
||||
|
||||
auto encrypting_reader::calculate_encrypted_size(std::string_view source_path)
|
||||
-> std::uint64_t {
|
||||
std::uint64_t file_size{};
|
||||
if (not utils::file::get_file_size(source_path, file_size)) {
|
||||
throw std::runtime_error("get file size failed|src|" +
|
||||
std::string{source_path} + '|' +
|
||||
std::to_string(utils::get_last_error_code()));
|
||||
}
|
||||
|
||||
const auto total_chunks = utils::divide_with_ceiling(
|
||||
file_size, static_cast<std::uint64_t>(data_chunk_size_));
|
||||
return file_size + (total_chunks * encryption_header_size);
|
||||
}
|
||||
|
||||
auto encrypting_reader::create_iostream() const
|
||||
-> std::shared_ptr<encrypting_reader::iostream> {
|
||||
return std::make_shared<encrypting_reader_iostream>(
|
||||
std::make_unique<encrypting_streambuf>(*this));
|
||||
}
|
||||
|
||||
auto encrypting_reader::reader_function(char *buffer, size_t size,
|
||||
size_t nitems) -> size_t {
|
||||
static constexpr const std::string_view function_name{
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
};
|
||||
|
||||
const auto read_size = static_cast<std::size_t>(std::min(
|
||||
static_cast<std::uint64_t>(size * nitems), total_size_ - read_offset_));
|
||||
|
||||
auto chunk = read_offset_ / encrypted_chunk_size_;
|
||||
auto chunk_offset = read_offset_ % encrypted_chunk_size_;
|
||||
std::size_t total_read{};
|
||||
|
||||
auto ret = false;
|
||||
if (read_offset_ < total_size_) {
|
||||
try {
|
||||
ret = true;
|
||||
auto remain = read_size;
|
||||
while (not stop_requested_ && ret && (remain != 0U)) {
|
||||
if (chunk_buffers_.find(chunk) == chunk_buffers_.end()) {
|
||||
auto &chunk_buffer = chunk_buffers_[chunk];
|
||||
data_buffer file_data(chunk == last_data_chunk_
|
||||
? last_data_chunk_size_
|
||||
: data_chunk_size_);
|
||||
chunk_buffer.resize(file_data.size() + encryption_header_size);
|
||||
|
||||
std::size_t bytes_read{};
|
||||
if ((ret = source_file_->read_bytes(&file_data[0u], file_data.size(),
|
||||
chunk * data_chunk_size_,
|
||||
bytes_read))) {
|
||||
utils::encryption::encrypt_data(iv_list_.at(chunk), key_, file_data,
|
||||
chunk_buffer);
|
||||
}
|
||||
} else if (chunk) {
|
||||
chunk_buffers_.erase(chunk - 1u);
|
||||
}
|
||||
|
||||
auto &chunk_buffer = chunk_buffers_[chunk];
|
||||
const auto to_read = std::min(
|
||||
static_cast<std::size_t>(chunk_buffer.size() - chunk_offset),
|
||||
remain);
|
||||
std::memcpy(buffer + total_read, &chunk_buffer[chunk_offset], to_read);
|
||||
total_read += to_read;
|
||||
remain -= to_read;
|
||||
chunk_offset = 0u;
|
||||
chunk++;
|
||||
read_offset_ += to_read;
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
utils::error::raise_error(function_name, e, "exception occurred");
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
|
||||
return stop_requested_ ? CURL_READFUNC_ABORT
|
||||
: ret ? total_read
|
||||
: error_return_;
|
||||
}
|
||||
} // namespace repertory::utils::encryption
|
@ -277,8 +277,8 @@ auto generate_sha256(const std::string &file_path) -> std::string {
|
||||
std::to_string(res));
|
||||
}
|
||||
|
||||
native_file_ptr nf;
|
||||
if (native_file::open(file_path, nf) != api_error::success) {
|
||||
auto nf = util::file::file::open_file(file_path);
|
||||
if (not nf) {
|
||||
throw std::runtime_error("failed to open file|" + file_path);
|
||||
}
|
||||
|
||||
@ -286,8 +286,7 @@ auto generate_sha256(const std::string &file_path) -> std::string {
|
||||
data_buffer buffer(1048576u);
|
||||
std::uint64_t read_offset = 0U;
|
||||
std::size_t bytes_read = 0U;
|
||||
while (
|
||||
nf->read_bytes(buffer.data(), buffer.size(), read_offset, bytes_read)) {
|
||||
while (nf.read(buffer, read_offset, &bytes_read)) {
|
||||
if (not bytes_read) {
|
||||
break;
|
||||
}
|
||||
@ -297,12 +296,10 @@ auto generate_sha256(const std::string &file_path) -> std::string {
|
||||
&state, reinterpret_cast<const unsigned char *>(buffer.data()),
|
||||
bytes_read);
|
||||
if (res != 0) {
|
||||
nf->close();
|
||||
throw std::runtime_error("failed to update sha256|" +
|
||||
std::to_string(res));
|
||||
}
|
||||
}
|
||||
nf->close();
|
||||
}
|
||||
|
||||
std::array<unsigned char, crypto_hash_sha256_BYTES> out{};
|
||||
|
@ -28,7 +28,6 @@
|
||||
#include "types/startup_exception.hpp"
|
||||
#include "utils/com_init_wrapper.hpp"
|
||||
#include "utils/common.hpp"
|
||||
#include "utils/native_file.hpp"
|
||||
#include "utils/path.hpp"
|
||||
#include "utils/string.hpp"
|
||||
#include "utils/time.hpp"
|
||||
|
@ -19,8 +19,8 @@
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef REPERTORY_WINFSP_FIXTURE_HPP
|
||||
#define REPERTORY_WINFSP_FIXTURE_HPP
|
||||
#ifndef REPERTORY_TEST_INCLUDE_FIXTURES_WINFSP_FIXTURE_HPP
|
||||
#define REPERTORY_TEST_INCLUDE_FIXTURES_WINFSP_FIXTURE_HPP
|
||||
#if defined(_WIN32)
|
||||
|
||||
#include "test_common.hpp"
|
||||
@ -48,13 +48,14 @@ protected:
|
||||
if (PROVIDER_INDEX != 0) {
|
||||
if (PROVIDER_INDEX == 1) {
|
||||
EXPECT_TRUE(utils::file::delete_directory_recursively(
|
||||
"./test_config/winfsp_test" + std::to_string(PROVIDER_INDEX)));
|
||||
utils::path::combine(test::get_test_output_dir(), {"winfsp_test" + std::to_string(PROVIDER_INDEX)}));
|
||||
|
||||
app_config src_cfg(provider_type::s3,
|
||||
utils::path::combine(get_test_dir(), {"storj"}));
|
||||
app_config src_cfg(
|
||||
provider_type::s3,
|
||||
utils::path::combine(test::get_test_input_dir(), {"storj"}));
|
||||
config = std::make_unique<app_config>(
|
||||
provider_type::s3,
|
||||
"./test_config/winfsp_test" + std::to_string(PROVIDER_INDEX));
|
||||
utils::path::combine(test::get_test_output_dir(), {"winfsp_test" + std::to_string(PROVIDER_INDEX)}));
|
||||
EXPECT_FALSE(config
|
||||
->set_value_by_name("S3Config.AccessKey",
|
||||
src_cfg.get_s3_config().access_key)
|
||||
@ -89,14 +90,19 @@ protected:
|
||||
}
|
||||
|
||||
if (PROVIDER_INDEX == 2) {
|
||||
EXPECT_TRUE(utils::file::delete_directory_recursively(
|
||||
"./test_config/winfsp_test" + std::to_string(PROVIDER_INDEX)));
|
||||
EXPECT_TRUE(
|
||||
utils::file::delete_directory_recursively(utils::path::combine(
|
||||
test::get_test_output_dir(),
|
||||
{"winfsp_test" + std::to_string(PROVIDER_INDEX)})));
|
||||
|
||||
app_config src_cfg(provider_type::sia,
|
||||
utils::path::combine(get_test_dir(), {"sia"}));
|
||||
app_config src_cfg(
|
||||
provider_type::sia,
|
||||
utils::path::combine(test::get_test_input_dir(), {"sia"}));
|
||||
config = std::make_unique<app_config>(
|
||||
provider_type::sia,
|
||||
"./test_config/winfsp_test" + std::to_string(PROVIDER_INDEX));
|
||||
utils::path::combine(
|
||||
test::get_test_output_dir(),
|
||||
{"winfsp_test" + std::to_string(PROVIDER_INDEX)}));
|
||||
[[maybe_unused]] auto val = config->set_value_by_name(
|
||||
"HostConfig.AgentString", src_cfg.get_host_config().agent_string);
|
||||
EXPECT_FALSE(
|
||||
@ -135,12 +141,14 @@ protected:
|
||||
config.reset();
|
||||
|
||||
event_system::instance().stop();
|
||||
EXPECT_TRUE(utils::file::delete_directory_recursively(
|
||||
"./test_config/winfsp_test" + std::to_string(PROVIDER_INDEX)));
|
||||
EXPECT_TRUE(
|
||||
utils::file::delete_directory_recursively(utils::path::combine(
|
||||
test::get_test_output_dir(),
|
||||
{"winfsp_test" + std::to_string(PROVIDER_INDEX)})));
|
||||
}
|
||||
}
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif
|
||||
#endif // REPERTORY_WINFSP_FIXTURE_HPP
|
||||
#endif // REPERTORY_TEST_INCLUDE_FIXTURES_WINFSP_FIXTURE_HPP
|
||||
|
@ -19,8 +19,8 @@
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef TESTS_MOCKS_MOCK_FUSE_DRIVE_HPP_
|
||||
#define TESTS_MOCKS_MOCK_FUSE_DRIVE_HPP_
|
||||
#ifndef REPERTORY_TEST_INCLUDE_FIXTURES_MOCKS_MOCK_FUSE_DRIVE_HPP_
|
||||
#define REPERTORY_TEST_INCLUDE_FIXTURES_MOCKS_MOCK_FUSE_DRIVE_HPP_
|
||||
#if !defined(_WIN32)
|
||||
|
||||
#include "test_common.hpp"
|
||||
@ -156,4 +156,4 @@ public:
|
||||
} // namespace repertory
|
||||
|
||||
#endif // _WIN32
|
||||
#endif // TESTS_MOCKS_MOCK_FUSE_DRIVE_HPP_
|
||||
#endif // REPERTORY_TEST_INCLUDE_FIXTURES_MOCKS_MOCK_FUSE_DRIVE_HPP_
|
||||
|
@ -19,8 +19,8 @@
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef TESTS_MOCKS_MOCK_OPEN_FILE_HPP_
|
||||
#define TESTS_MOCKS_MOCK_OPEN_FILE_HPP_
|
||||
#ifndef REPERTORY_TEST_INCLUDE_MOCKS_MOCK_OPEN_FILE_HPP_
|
||||
#define REPERTORY_TEST_INCLUDE_MOCKS_MOCK_OPEN_FILE_HPP_
|
||||
|
||||
#include "test_common.hpp"
|
||||
|
||||
@ -95,4 +95,4 @@ public:
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // TESTS_MOCKS_MOCK_OPEN_FILE_HPP_
|
||||
#endif // REPERTORY_TEST_INCLUDE_MOCKS_MOCK_OPEN_FILE_HPP_
|
||||
|
@ -19,8 +19,8 @@
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef TESTS_MOCKS_MOCK_PROVIDER_HPP_
|
||||
#define TESTS_MOCKS_MOCK_PROVIDER_HPP_
|
||||
#ifndef REPERTORY_TEST_INCLUDE_MOCKS_MOCK_PROVIDER_HPP_
|
||||
#define REPERTORY_TEST_INCLUDE_MOCKS_MOCK_PROVIDER_HPP_
|
||||
|
||||
#include "test_common.hpp"
|
||||
|
||||
@ -159,4 +159,4 @@ public:
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // TESTS_MOCKS_MOCK_PROVIDER_HPP_
|
||||
#endif // REPERTORY_TEST_INCLUDE_MOCKS_MOCK_PROVIDER_HPP_
|
||||
|
@ -19,8 +19,8 @@
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef TESTS_MOCKS_MOCK_UPLOAD_MANAGER_HPP_
|
||||
#define TESTS_MOCKS_MOCK_UPLOAD_MANAGER_HPP_
|
||||
#ifndef REPERTORY_TEST_INCLUDE_MOCKS_MOCK_UPLOAD_MANAGER_HPP_
|
||||
#define REPERTORY_TEST_INCLUDE_MOCKS_MOCK_UPLOAD_MANAGER_HPP_
|
||||
|
||||
#include "test_common.hpp"
|
||||
|
||||
@ -41,4 +41,4 @@ public:
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // TESTS_MOCKS_MOCK_UPLOAD_MANAGER_HPP_
|
||||
#endif // REPERTORY_TEST_INCLUDE_MOCKS_MOCK_UPLOAD_MANAGER_HPP_
|
||||
|
@ -19,8 +19,8 @@
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef TESTS_MOCKS_MOCK_WINFSP_DRIVE_HPP_
|
||||
#define TESTS_MOCKS_MOCK_WINFSP_DRIVE_HPP_
|
||||
#ifndef REPERTORY_TEST_INCLUDE_MOCKS_MOCK_WINFSP_DRIVE_HPP_
|
||||
#define REPERTORY_TEST_INCLUDE_MOCKS_MOCK_WINFSP_DRIVE_HPP_
|
||||
#if defined(_WIN32)
|
||||
|
||||
#include "test_common.hpp"
|
||||
@ -167,4 +167,4 @@ public:
|
||||
} // namespace repertory
|
||||
|
||||
#endif // _WIN32
|
||||
#endif // TESTS_MOCKS_MOCK_WINFSP_DRIVE_HPP_
|
||||
#endif // REPERTORY_TEST_INCLUDE_MOCKS_MOCK_WINFSP_DRIVE_HPP_
|
||||
|
@ -19,47 +19,15 @@
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef TESTS_TEST_COMMON_HPP_
|
||||
#define TESTS_TEST_COMMON_HPP_
|
||||
|
||||
#if defined(U)
|
||||
#undef U
|
||||
#endif
|
||||
#ifndef REPERTORY_TEST_INCLUDE_TEST_COMMON_HPP_
|
||||
#define REPERTORY_TEST_INCLUDE_TEST_COMMON_HPP_
|
||||
|
||||
REPERTORY_IGNORE_WARNINGS_ENABLE()
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include "test.hpp"
|
||||
REPERTORY_IGNORE_WARNINGS_DISABLE()
|
||||
|
||||
#include "events/consumers/console_consumer.hpp"
|
||||
#include "events/event_system.hpp"
|
||||
#include "events/events.hpp"
|
||||
#include "utils/encrypt.hpp"
|
||||
#include "utils/file_utils.hpp"
|
||||
#include "utils/native_file.hpp"
|
||||
|
||||
#define COMMA ,
|
||||
|
||||
using ::testing::_;
|
||||
using namespace ::testing;
|
||||
|
||||
namespace repertory {
|
||||
[[nodiscard]] auto create_random_file(std::string path,
|
||||
std::size_t size) -> native_file_ptr;
|
||||
|
||||
void delete_generated_files();
|
||||
|
||||
[[nodiscard]] auto generate_test_file_name(
|
||||
const std::string &directory,
|
||||
const std::string &file_name_no_extension) -> std::string;
|
||||
|
||||
template <typename T, typename T2>
|
||||
static void decrypt_and_verify(const T &buffer, const std::string &token,
|
||||
T2 &result) {
|
||||
EXPECT_TRUE(utils::encryption::decrypt_data(token, buffer, result));
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_test_dir() -> std::string;
|
||||
} // namespace repertory
|
||||
|
||||
#endif // TESTS_TEST_COMMON_HPP_
|
||||
#endif // REPERTORY_TEST_INCLUDE_TEST_COMMON_HPP_
|
||||
|
@ -19,8 +19,8 @@
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef TESTS_UTILS_EVENT_CAPTURE_HPP_
|
||||
#define TESTS_UTILS_EVENT_CAPTURE_HPP_
|
||||
#ifndef REPERTORY_TEST_INCLUDE_UTILS_EVENT_CAPTURE_HPP_
|
||||
#define REPERTORY_TEST_INCLUDE_UTILS_EVENT_CAPTURE_HPP_
|
||||
|
||||
#include "test_common.hpp"
|
||||
|
||||
@ -106,4 +106,4 @@ public:
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // TESTS_UTILS_EVENT_CAPTURE_HPP_
|
||||
#endif // REPERTORY_TEST_INCLUDE_UTILS_EVENT_CAPTURE_HPP_
|
||||
|
@ -33,20 +33,20 @@ public:
|
||||
static console_consumer cs;
|
||||
|
||||
std::string s3_directory{
|
||||
utils::path::combine("./test_config", {"config_test", "s3"})};
|
||||
utils::path::combine(test::get_test_output_dir(), {"config_test", "s3"})};
|
||||
|
||||
std::string sia_directory{
|
||||
utils::path::combine("./test_config", {"config_test", "sia"})};
|
||||
std::string sia_directory{utils::path::combine(test::get_test_output_dir(),
|
||||
{"config_test", "sia"})};
|
||||
|
||||
void SetUp() override {
|
||||
event_system::instance().start();
|
||||
ASSERT_TRUE(utils::file::delete_directory_recursively(
|
||||
utils::path::combine("./test_config", {"config_test"})));
|
||||
utils::path::combine(test::get_test_output_dir(), {"config_test"})));
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
ASSERT_TRUE(utils::file::delete_directory_recursively(
|
||||
utils::path::combine("./test_config", {"config_test"})));
|
||||
utils::path::combine(test::get_test_output_dir(), {"config_test"})));
|
||||
event_system::instance().stop();
|
||||
}
|
||||
};
|
||||
|
@ -35,8 +35,9 @@ TEST(database, db_insert) {
|
||||
{
|
||||
sqlite3 *db3_ptr{nullptr};
|
||||
auto res = sqlite3_open_v2(
|
||||
utils::path::combine(get_test_dir(), {"test.db3"}).c_str(), &db3_ptr,
|
||||
SQLITE_OPEN_READWRITE, nullptr);
|
||||
utils::path::combine(test::get_test_input_dir(), {"test.db3"})
|
||||
.c_str(),
|
||||
&db3_ptr, SQLITE_OPEN_READWRITE, nullptr);
|
||||
ASSERT_EQ(SQLITE_OK, res);
|
||||
ASSERT_TRUE(db3_ptr != nullptr);
|
||||
|
||||
@ -78,8 +79,9 @@ TEST(database, db_select) {
|
||||
{
|
||||
sqlite3 *db3_ptr{nullptr};
|
||||
auto res = sqlite3_open_v2(
|
||||
utils::path::combine(get_test_dir(), {"test.db3"}).c_str(), &db3_ptr,
|
||||
SQLITE_OPEN_READWRITE, nullptr);
|
||||
utils::path::combine(test::get_test_input_dir(), {"test.db3"})
|
||||
.c_str(),
|
||||
&db3_ptr, SQLITE_OPEN_READWRITE, nullptr);
|
||||
ASSERT_EQ(SQLITE_OK, res);
|
||||
ASSERT_TRUE(db3_ptr != nullptr);
|
||||
|
||||
|
@ -27,11 +27,7 @@
|
||||
#include "utils/path.hpp"
|
||||
|
||||
namespace repertory {
|
||||
static auto get_source_file_name() -> std::string {
|
||||
return generate_test_file_name("./test_data", "encrypting_reader");
|
||||
}
|
||||
|
||||
TEST(encrypting_reader, get_encrypted_file_name) {
|
||||
/* TEST(encrypting_reader, get_encrypted_file_name) {
|
||||
const auto source_file_name = get_source_file_name();
|
||||
ASSERT_TRUE(utils::file::retry_delete_file(source_file_name));
|
||||
|
||||
@ -41,7 +37,7 @@ TEST(encrypting_reader, get_encrypted_file_name) {
|
||||
if (source_file) {
|
||||
stop_type stop_requested = false;
|
||||
utils::encryption::encrypting_reader reader(
|
||||
"test.dat", source_file_name, stop_requested, token, std::nullopt);
|
||||
"test.dat", source_file_name, stop_requested, token, std::nullopt);
|
||||
|
||||
auto file_name = reader.get_encrypted_file_name();
|
||||
|
||||
@ -53,231 +49,5 @@ TEST(encrypting_reader, get_encrypted_file_name) {
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::retry_delete_file(source_file_name));
|
||||
}
|
||||
|
||||
TEST(encrypting_reader, file_data) {
|
||||
const auto source_file_name = get_source_file_name();
|
||||
EXPECT_TRUE(utils::file::retry_delete_file(source_file_name));
|
||||
|
||||
const auto token = std::string("moose");
|
||||
auto source_file = create_random_file(
|
||||
source_file_name,
|
||||
8U * utils::encryption::encrypting_reader::get_data_chunk_size());
|
||||
EXPECT_TRUE(source_file != nullptr);
|
||||
if (source_file) {
|
||||
stop_type stop_requested = false;
|
||||
utils::encryption::encrypting_reader reader("test.dat", source_file_name,
|
||||
stop_requested, token);
|
||||
|
||||
for (std::uint8_t i = 0U; i < 8U; i++) {
|
||||
data_buffer buffer(
|
||||
utils::encryption::encrypting_reader::get_encrypted_chunk_size());
|
||||
for (std::uint8_t j = 0U; j < 2U; j++) {
|
||||
EXPECT_EQ(
|
||||
buffer.size() / 2U,
|
||||
utils::encryption::encrypting_reader::reader_function(
|
||||
reinterpret_cast<char *>(&buffer[(buffer.size() / 2U) * j]),
|
||||
buffer.size() / 2U, 1U, &reader));
|
||||
}
|
||||
|
||||
data_buffer decrypted_data;
|
||||
EXPECT_TRUE(
|
||||
utils::encryption::decrypt_data(token, buffer, decrypted_data));
|
||||
|
||||
EXPECT_EQ(utils::encryption::encrypting_reader::get_data_chunk_size(),
|
||||
decrypted_data.size());
|
||||
|
||||
std::size_t bytes_read{};
|
||||
data_buffer file_data(decrypted_data.size());
|
||||
EXPECT_TRUE(source_file->read_bytes(
|
||||
file_data.data(), file_data.size(),
|
||||
utils::encryption::encrypting_reader::get_data_chunk_size() * i,
|
||||
bytes_read));
|
||||
EXPECT_EQ(0, std::memcmp(file_data.data(), decrypted_data.data(),
|
||||
file_data.size()));
|
||||
}
|
||||
|
||||
source_file->close();
|
||||
}
|
||||
EXPECT_TRUE(utils::file::retry_delete_file(source_file_name));
|
||||
}
|
||||
|
||||
TEST(encrypting_reader, file_data_in_multiple_chunks) {
|
||||
const auto source_file_name = get_source_file_name();
|
||||
ASSERT_TRUE(utils::file::retry_delete_file(source_file_name));
|
||||
|
||||
const auto token = std::string("moose");
|
||||
auto source_file = create_random_file(
|
||||
source_file_name,
|
||||
8U * utils::encryption::encrypting_reader::get_data_chunk_size());
|
||||
EXPECT_TRUE(source_file != nullptr);
|
||||
if (source_file) {
|
||||
stop_type stop_requested = false;
|
||||
utils::encryption::encrypting_reader reader("test.dat", source_file_name,
|
||||
stop_requested, token);
|
||||
|
||||
for (std::uint8_t i = 0U; i < 8U; i += 2U) {
|
||||
data_buffer buffer(
|
||||
utils::encryption::encrypting_reader::get_encrypted_chunk_size() *
|
||||
2U);
|
||||
EXPECT_EQ(buffer.size(),
|
||||
utils::encryption::encrypting_reader::reader_function(
|
||||
reinterpret_cast<char *>(buffer.data()), buffer.size(), 1U,
|
||||
&reader));
|
||||
|
||||
for (std::uint8_t j = 0U; j < 2U; j++) {
|
||||
data_buffer decrypted_data;
|
||||
const auto offset = (j * (buffer.size() / 2U));
|
||||
EXPECT_TRUE(utils::encryption::decrypt_data(
|
||||
token,
|
||||
data_buffer(
|
||||
std::next(buffer.begin(), static_cast<std::int64_t>(offset)),
|
||||
std::next(buffer.begin(), static_cast<std::int64_t>(
|
||||
offset + (buffer.size() / 2U)))),
|
||||
decrypted_data));
|
||||
|
||||
EXPECT_EQ(utils::encryption::encrypting_reader::get_data_chunk_size(),
|
||||
decrypted_data.size());
|
||||
|
||||
std::size_t bytes_read{};
|
||||
data_buffer file_data(decrypted_data.size());
|
||||
EXPECT_TRUE(source_file->read_bytes(
|
||||
file_data.data(), file_data.size(),
|
||||
(utils::encryption::encrypting_reader::get_data_chunk_size() * i) +
|
||||
(j *
|
||||
utils::encryption::encrypting_reader::get_data_chunk_size()),
|
||||
bytes_read));
|
||||
EXPECT_EQ(0, std::memcmp(file_data.data(), decrypted_data.data(),
|
||||
file_data.size()));
|
||||
}
|
||||
}
|
||||
|
||||
source_file->close();
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::retry_delete_file(source_file_name));
|
||||
}
|
||||
|
||||
TEST(encrypting_reader, file_data_as_stream) {
|
||||
const auto source_file_name = get_source_file_name();
|
||||
ASSERT_TRUE(utils::file::retry_delete_file(source_file_name));
|
||||
|
||||
const auto token = std::string("moose");
|
||||
auto source_file = create_random_file(
|
||||
source_file_name,
|
||||
8U * utils::encryption::encrypting_reader::get_data_chunk_size());
|
||||
EXPECT_TRUE(source_file != nullptr);
|
||||
if (source_file) {
|
||||
stop_type stop_requested = false;
|
||||
utils::encryption::encrypting_reader reader("test.dat", source_file_name,
|
||||
stop_requested, token);
|
||||
auto io_stream = reader.create_iostream();
|
||||
EXPECT_FALSE(io_stream->seekg(0, std::ios_base::end).fail());
|
||||
EXPECT_TRUE(io_stream->good());
|
||||
EXPECT_EQ(reader.get_total_size(),
|
||||
static_cast<std::uint64_t>(io_stream->tellg()));
|
||||
EXPECT_FALSE(io_stream->seekg(0, std::ios_base::beg).fail());
|
||||
EXPECT_TRUE(io_stream->good());
|
||||
|
||||
for (std::uint8_t i = 0U; i < 8U; i++) {
|
||||
data_buffer buffer(
|
||||
utils::encryption::encrypting_reader::get_encrypted_chunk_size());
|
||||
EXPECT_FALSE(
|
||||
io_stream->seekg(static_cast<std::streamoff>(i * buffer.size()))
|
||||
.fail());
|
||||
EXPECT_TRUE(io_stream->good());
|
||||
for (std::uint8_t j = 0U; j < 2U; j++) {
|
||||
EXPECT_FALSE(
|
||||
io_stream
|
||||
->read(
|
||||
reinterpret_cast<char *>(&buffer[(buffer.size() / 2U) * j]),
|
||||
static_cast<std::streamsize>(buffer.size()) / 2U)
|
||||
.fail());
|
||||
EXPECT_TRUE(io_stream->good());
|
||||
}
|
||||
|
||||
data_buffer decrypted_data;
|
||||
EXPECT_TRUE(
|
||||
utils::encryption::decrypt_data(token, buffer, decrypted_data));
|
||||
|
||||
EXPECT_EQ(utils::encryption::encrypting_reader::get_data_chunk_size(),
|
||||
decrypted_data.size());
|
||||
|
||||
std::size_t bytes_read{};
|
||||
data_buffer file_data(decrypted_data.size());
|
||||
EXPECT_TRUE(source_file->read_bytes(
|
||||
file_data.data(), file_data.size(),
|
||||
utils::encryption::encrypting_reader::get_data_chunk_size() * i,
|
||||
bytes_read));
|
||||
EXPECT_EQ(0, std::memcmp(file_data.data(), decrypted_data.data(),
|
||||
file_data.size()));
|
||||
}
|
||||
|
||||
source_file->close();
|
||||
}
|
||||
EXPECT_TRUE(utils::file::retry_delete_file(source_file_name));
|
||||
}
|
||||
|
||||
TEST(encrypting_reader, file_data_in_multiple_chunks_as_stream) {
|
||||
const auto source_file_name = get_source_file_name();
|
||||
ASSERT_TRUE(utils::file::retry_delete_file(source_file_name));
|
||||
|
||||
const auto token = std::string("moose");
|
||||
auto source_file = create_random_file(
|
||||
source_file_name,
|
||||
8u * utils::encryption::encrypting_reader::get_data_chunk_size());
|
||||
EXPECT_TRUE(source_file != nullptr);
|
||||
if (source_file) {
|
||||
stop_type stop_requested = false;
|
||||
utils::encryption::encrypting_reader reader("test.dat", source_file_name,
|
||||
stop_requested, token);
|
||||
auto io_stream = reader.create_iostream();
|
||||
EXPECT_FALSE(io_stream->seekg(0, std::ios_base::end).fail());
|
||||
EXPECT_TRUE(io_stream->good());
|
||||
EXPECT_EQ(reader.get_total_size(),
|
||||
static_cast<std::uint64_t>(io_stream->tellg()));
|
||||
EXPECT_FALSE(io_stream->seekg(0, std::ios_base::beg).fail());
|
||||
EXPECT_TRUE(io_stream->good());
|
||||
|
||||
for (std::uint8_t i = 0U; i < 8U; i += 2U) {
|
||||
data_buffer buffer(
|
||||
utils::encryption::encrypting_reader::get_encrypted_chunk_size() *
|
||||
2U);
|
||||
EXPECT_FALSE(io_stream
|
||||
->read(reinterpret_cast<char *>(buffer.data()),
|
||||
static_cast<std::streamsize>(buffer.size()))
|
||||
.fail());
|
||||
EXPECT_TRUE(io_stream->good());
|
||||
|
||||
for (std::uint8_t j = 0U; j < 2U; j++) {
|
||||
data_buffer decrypted_data;
|
||||
const auto offset = (j * (buffer.size() / 2U));
|
||||
EXPECT_TRUE(utils::encryption::decrypt_data(
|
||||
token,
|
||||
data_buffer(
|
||||
std::next(buffer.begin(), static_cast<std::int64_t>(offset)),
|
||||
std::next(buffer.begin(), static_cast<std::int64_t>(
|
||||
offset + (buffer.size() / 2U)))),
|
||||
decrypted_data));
|
||||
|
||||
EXPECT_EQ(utils::encryption::encrypting_reader::get_data_chunk_size(),
|
||||
decrypted_data.size());
|
||||
|
||||
std::size_t bytes_read{};
|
||||
data_buffer file_data(decrypted_data.size());
|
||||
EXPECT_TRUE(source_file->read_bytes(
|
||||
file_data.data(), file_data.size(),
|
||||
(utils::encryption::encrypting_reader::get_data_chunk_size() * i) +
|
||||
(j *
|
||||
utils::encryption::encrypting_reader::get_data_chunk_size()),
|
||||
bytes_read));
|
||||
EXPECT_EQ(0, std::memcmp(file_data.data(), decrypted_data.data(),
|
||||
file_data.size()));
|
||||
}
|
||||
}
|
||||
|
||||
source_file->close();
|
||||
}
|
||||
EXPECT_TRUE(utils::file::retry_delete_file(source_file_name));
|
||||
}
|
||||
} */
|
||||
} // namespace repertory
|
||||
|
@ -55,7 +55,7 @@ static void validate_write(file_manager::open_file &o, std::size_t offset,
|
||||
|
||||
TEST(open_file, properly_initializes_state_for_0_byte_file) {
|
||||
const auto source_path =
|
||||
generate_test_file_name("./test_config", "file_manager_open_file_test");
|
||||
test::generate_test_file_name("file_manager_open_file_test");
|
||||
|
||||
mock_provider mp;
|
||||
mock_upload_manager um;
|
||||
@ -76,7 +76,7 @@ TEST(open_file, properly_initializes_state_for_0_byte_file) {
|
||||
|
||||
TEST(open_file, properly_initializes_state_based_on_chunk_size) {
|
||||
const auto source_path =
|
||||
generate_test_file_name("./test_config", "file_manager_open_file_test");
|
||||
test::generate_test_file_name("file_manager_open_file_test");
|
||||
|
||||
mock_provider mp;
|
||||
mock_upload_manager um;
|
||||
@ -109,7 +109,7 @@ TEST(open_file, properly_initializes_state_based_on_chunk_size) {
|
||||
|
||||
TEST(open_file, will_not_change_source_path_for_0_byte_file) {
|
||||
const auto source_path =
|
||||
generate_test_file_name("./test_config", "file_manager_open_file_test");
|
||||
test::generate_test_file_name("file_manager_open_file_test");
|
||||
|
||||
mock_provider mp;
|
||||
mock_upload_manager um;
|
||||
@ -133,7 +133,7 @@ TEST(open_file, will_not_change_source_path_for_0_byte_file) {
|
||||
|
||||
TEST(open_file, will_change_source_path_if_file_size_is_greater_than_0) {
|
||||
const auto source_path =
|
||||
generate_test_file_name("./test_config", "file_manager_open_file_test");
|
||||
test::generate_test_file_name("file_manager_open_file_test");
|
||||
|
||||
mock_provider mp;
|
||||
mock_upload_manager um;
|
||||
@ -171,9 +171,9 @@ TEST(open_file, will_change_source_path_if_file_size_is_greater_than_0) {
|
||||
|
||||
TEST(open_file,
|
||||
will_not_change_source_path_if_file_size_matches_existing_source) {
|
||||
const auto source_path =
|
||||
generate_test_file_name("./test_config", "file_manager_open_file_test");
|
||||
create_random_file(source_path, test_chunk_size)->close();
|
||||
auto rf = test::create_random_file(test_chunk_size);
|
||||
const auto source_path = rf.get_path().string();
|
||||
rf.close();
|
||||
|
||||
mock_provider mp;
|
||||
mock_upload_manager um;
|
||||
@ -196,11 +196,8 @@ TEST(open_file,
|
||||
}
|
||||
|
||||
TEST(open_file, write_with_incomplete_download) {
|
||||
const auto source_path =
|
||||
generate_test_file_name("./test_config", "file_manager_open_file_test");
|
||||
auto nf = create_random_file(
|
||||
generate_test_file_name("./test_config", "file_manager_open_file_test"),
|
||||
test_chunk_size * 2u);
|
||||
auto nf = test::create_random_file(test_chunk_size * 2u);
|
||||
const auto source_path = nf.get_path().string();
|
||||
|
||||
mock_provider mp;
|
||||
mock_upload_manager um;
|
||||
@ -236,9 +233,8 @@ TEST(open_file, write_with_incomplete_download) {
|
||||
if (offset == 0u) {
|
||||
std::size_t bytes_read{};
|
||||
data.resize(size);
|
||||
auto ret = nf->read_bytes(&data[0u], size, offset, bytes_read)
|
||||
? api_error::success
|
||||
: api_error::os_error;
|
||||
auto ret = nf.read(data, offset, &bytes_read) ? api_error::success
|
||||
: api_error::os_error;
|
||||
EXPECT_EQ(bytes_read, data.size());
|
||||
return ret;
|
||||
}
|
||||
@ -289,7 +285,7 @@ TEST(open_file, write_with_incomplete_download) {
|
||||
|
||||
TEST(open_file, write_new_file) {
|
||||
const auto source_path =
|
||||
generate_test_file_name("./test_config", "file_manager_open_file_test");
|
||||
test::generate_test_file_name("file_manager_open_file_test");
|
||||
|
||||
mock_provider mp;
|
||||
mock_upload_manager um;
|
||||
@ -362,7 +358,7 @@ TEST(open_file, write_new_file) {
|
||||
|
||||
TEST(open_file, write_new_file_multiple_chunks) {
|
||||
const auto source_path =
|
||||
generate_test_file_name("./test_config", "file_manager_open_file_test");
|
||||
test::generate_test_file_name("file_manager_open_file_test");
|
||||
|
||||
mock_provider mp;
|
||||
mock_upload_manager um;
|
||||
@ -453,9 +449,9 @@ TEST(open_file, write_new_file_multiple_chunks) {
|
||||
}
|
||||
|
||||
TEST(open_file, resize_file_to_0_bytes) {
|
||||
const auto source_path =
|
||||
generate_test_file_name("./test_config", "file_manager_open_file_test");
|
||||
create_random_file(source_path, test_chunk_size * 4u)->close();
|
||||
auto rf = test::create_random_file(test_chunk_size * 4u);
|
||||
const auto source_path = rf.get_path().string();
|
||||
rf.close();
|
||||
|
||||
mock_provider mp;
|
||||
mock_upload_manager um;
|
||||
@ -503,9 +499,9 @@ TEST(open_file, resize_file_to_0_bytes) {
|
||||
}
|
||||
|
||||
TEST(open_file, resize_file_by_full_chunk) {
|
||||
const auto source_path =
|
||||
generate_test_file_name("./test_config", "file_manager_open_file_test");
|
||||
create_random_file(source_path, test_chunk_size * 4u)->close();
|
||||
auto rf = test::create_random_file(test_chunk_size * 4u);
|
||||
const auto source_path = rf.get_path().string();
|
||||
rf.close();
|
||||
|
||||
mock_provider mp;
|
||||
mock_upload_manager um;
|
||||
@ -556,7 +552,7 @@ TEST(open_file, can_add_handle) {
|
||||
event_system::instance().start();
|
||||
console_consumer c;
|
||||
const auto source_path =
|
||||
generate_test_file_name("./test_config", "file_manager_open_file_test");
|
||||
test::generate_test_file_name("file_manager_open_file_test");
|
||||
|
||||
mock_provider mp;
|
||||
mock_upload_manager um;
|
||||
@ -618,7 +614,7 @@ TEST(open_file, can_remove_handle) {
|
||||
console_consumer c;
|
||||
|
||||
const auto source_path =
|
||||
generate_test_file_name("./test_config", "file_manager_open_file_test");
|
||||
test::generate_test_file_name("file_manager_open_file_test");
|
||||
|
||||
mock_provider mp;
|
||||
mock_upload_manager um;
|
||||
|
@ -31,11 +31,11 @@
|
||||
namespace repertory {
|
||||
static constexpr const std::size_t test_chunk_size = 1024u;
|
||||
static std::string ring_buffer_dir = utils::path::combine(
|
||||
"./test_config", {"file_manager_ring_buffer_open_file_test"});
|
||||
test::get_test_output_dir(), {"file_manager_ring_buffer_open_file_test"});
|
||||
|
||||
TEST(ring_buffer_open_file, can_forward_to_last_chunk) {
|
||||
const auto source_path =
|
||||
generate_test_file_name("./test_config", "ring_buffer_open_file");
|
||||
test::generate_test_file_name("ring_buffer_open_file");
|
||||
|
||||
mock_provider mp;
|
||||
|
||||
@ -67,7 +67,7 @@ TEST(ring_buffer_open_file, can_forward_to_last_chunk) {
|
||||
TEST(ring_buffer_open_file,
|
||||
can_forward_to_last_chunk_if_count_is_greater_than_remaining) {
|
||||
const auto source_path =
|
||||
generate_test_file_name("./test_config", "ring_buffer_open_file");
|
||||
test::generate_test_file_name("ring_buffer_open_file");
|
||||
|
||||
mock_provider mp;
|
||||
|
||||
@ -98,7 +98,7 @@ TEST(ring_buffer_open_file,
|
||||
|
||||
TEST(ring_buffer_open_file, can_forward_after_last_chunk) {
|
||||
const auto source_path =
|
||||
generate_test_file_name("./test_config", "ring_buffer_open_file");
|
||||
test::generate_test_file_name("ring_buffer_open_file");
|
||||
|
||||
mock_provider mp;
|
||||
|
||||
@ -130,7 +130,7 @@ TEST(ring_buffer_open_file, can_forward_after_last_chunk) {
|
||||
|
||||
TEST(ring_buffer_open_file, can_forward_and_rollover_after_last_chunk) {
|
||||
const auto source_path =
|
||||
generate_test_file_name("./test_config", "ring_buffer_open_file");
|
||||
test::generate_test_file_name("ring_buffer_open_file");
|
||||
|
||||
mock_provider mp;
|
||||
|
||||
@ -158,7 +158,7 @@ TEST(ring_buffer_open_file, can_forward_and_rollover_after_last_chunk) {
|
||||
|
||||
TEST(ring_buffer_open_file, can_reverse_to_first_chunk) {
|
||||
const auto source_path =
|
||||
generate_test_file_name("./test_config", "ring_buffer_open_file");
|
||||
test::generate_test_file_name("ring_buffer_open_file");
|
||||
|
||||
mock_provider mp;
|
||||
|
||||
@ -190,7 +190,7 @@ TEST(ring_buffer_open_file, can_reverse_to_first_chunk) {
|
||||
TEST(ring_buffer_open_file,
|
||||
can_reverse_to_first_chunk_if_count_is_greater_than_remaining) {
|
||||
const auto source_path =
|
||||
generate_test_file_name("./test_config", "ring_buffer_open_file");
|
||||
test::generate_test_file_name("ring_buffer_open_file");
|
||||
|
||||
mock_provider mp;
|
||||
|
||||
@ -221,7 +221,7 @@ TEST(ring_buffer_open_file,
|
||||
|
||||
TEST(ring_buffer_open_file, can_reverse_before_first_chunk) {
|
||||
const auto source_path =
|
||||
generate_test_file_name("./test_config", "ring_buffer_open_file");
|
||||
test::generate_test_file_name("ring_buffer_open_file");
|
||||
|
||||
mock_provider mp;
|
||||
|
||||
@ -253,7 +253,7 @@ TEST(ring_buffer_open_file, can_reverse_before_first_chunk) {
|
||||
|
||||
TEST(ring_buffer_open_file, can_reverse_and_rollover_before_first_chunk) {
|
||||
const auto source_path =
|
||||
generate_test_file_name("./test_config", "ring_buffer_open_file");
|
||||
test::generate_test_file_name("ring_buffer_open_file");
|
||||
|
||||
mock_provider mp;
|
||||
|
||||
@ -289,7 +289,7 @@ TEST(ring_buffer_open_file, can_reverse_and_rollover_before_first_chunk) {
|
||||
|
||||
TEST(ring_buffer_open_file, can_reverse_full_ring) {
|
||||
const auto source_path =
|
||||
generate_test_file_name("./test_config", "ring_buffer_open_file");
|
||||
test::generate_test_file_name("ring_buffer_open_file");
|
||||
|
||||
mock_provider mp;
|
||||
|
||||
@ -320,12 +320,10 @@ TEST(ring_buffer_open_file, can_reverse_full_ring) {
|
||||
}
|
||||
|
||||
TEST(ring_buffer_open_file, read_full_file) {
|
||||
const auto download_source_path =
|
||||
generate_test_file_name("./test_config", "ring_buffer_open_file");
|
||||
auto nf = create_random_file(download_source_path, test_chunk_size * 32u);
|
||||
auto nf = test::create_random_file(test_chunk_size * 32u);
|
||||
const auto download_source_path = nf.get_path().string();
|
||||
|
||||
const auto dest_path =
|
||||
generate_test_file_name("./test_config", "ring_buffer_open_file");
|
||||
const auto dest_path = test::generate_test_file_name("ring_buffer_open_file");
|
||||
|
||||
mock_provider mp;
|
||||
|
||||
@ -335,8 +333,7 @@ TEST(ring_buffer_open_file, read_full_file) {
|
||||
fsi.directory = false;
|
||||
fsi.api_path = "/test.txt";
|
||||
fsi.size = test_chunk_size * 32u;
|
||||
fsi.source_path =
|
||||
generate_test_file_name("./test_config", "ring_buffer_open_file");
|
||||
fsi.source_path = test::generate_test_file_name("ring_buffer_open_file");
|
||||
|
||||
EXPECT_CALL(mp, read_file_bytes)
|
||||
.WillRepeatedly([&nf](const std::string & /* api_path */,
|
||||
@ -346,9 +343,8 @@ TEST(ring_buffer_open_file, read_full_file) {
|
||||
EXPECT_FALSE(stop_requested);
|
||||
std::size_t bytes_read{};
|
||||
data.resize(size);
|
||||
auto ret = nf->read_bytes(&data[0u], size, offset, bytes_read)
|
||||
? api_error::success
|
||||
: api_error::os_error;
|
||||
auto ret = nf.read(data, offset, &bytes_read) ? api_error::success
|
||||
: api_error::os_error;
|
||||
EXPECT_EQ(bytes_read, data.size());
|
||||
return ret;
|
||||
});
|
||||
@ -356,8 +352,8 @@ TEST(ring_buffer_open_file, read_full_file) {
|
||||
file_manager::ring_buffer_open_file rb(ring_buffer_dir, test_chunk_size,
|
||||
30U, fsi, mp, 8u);
|
||||
|
||||
native_file_ptr nf2;
|
||||
EXPECT_EQ(api_error::success, native_file::create_or_open(dest_path, nf2));
|
||||
auto nf2 = utils::file::file::open_or_create_file(dest_path);
|
||||
EXPECT_TRUE(nf2);
|
||||
|
||||
auto to_read = fsi.size;
|
||||
std::size_t chunk = 0u;
|
||||
@ -367,13 +363,12 @@ TEST(ring_buffer_open_file, read_full_file) {
|
||||
rb.read(test_chunk_size, chunk * test_chunk_size, data));
|
||||
|
||||
std::size_t bytes_written{};
|
||||
EXPECT_TRUE(nf2->write_bytes(data.data(), data.size(),
|
||||
chunk * test_chunk_size, bytes_written));
|
||||
EXPECT_TRUE(nf2.write(data, chunk * test_chunk_size, &bytes_written));
|
||||
chunk++;
|
||||
to_read -= data.size();
|
||||
}
|
||||
nf2->close();
|
||||
nf->close();
|
||||
nf2.close();
|
||||
nf.close();
|
||||
|
||||
EXPECT_STREQ(utils::file::generate_sha256(download_source_path).c_str(),
|
||||
utils::file::generate_sha256(dest_path).c_str());
|
||||
@ -383,12 +378,10 @@ TEST(ring_buffer_open_file, read_full_file) {
|
||||
}
|
||||
|
||||
TEST(ring_buffer_open_file, read_full_file_in_reverse) {
|
||||
const auto download_source_path =
|
||||
generate_test_file_name("./test_config", "ring_buffer_open_file");
|
||||
auto nf = create_random_file(download_source_path, test_chunk_size * 32u);
|
||||
auto nf = test::create_random_file(test_chunk_size * 32u);
|
||||
const auto download_source_path = nf.get_path().string();
|
||||
|
||||
const auto dest_path =
|
||||
generate_test_file_name("./test_config", "ring_buffer_open_file");
|
||||
const auto dest_path = test::generate_test_file_name("ring_buffer_open_file");
|
||||
|
||||
mock_provider mp;
|
||||
|
||||
@ -398,8 +391,7 @@ TEST(ring_buffer_open_file, read_full_file_in_reverse) {
|
||||
fsi.directory = false;
|
||||
fsi.api_path = "/test.txt";
|
||||
fsi.size = test_chunk_size * 32u;
|
||||
fsi.source_path =
|
||||
generate_test_file_name("./test_config", "ring_buffer_open_file");
|
||||
fsi.source_path = test::generate_test_file_name("ring_buffer_open_file");
|
||||
|
||||
EXPECT_CALL(mp, read_file_bytes)
|
||||
.WillRepeatedly([&nf](const std::string & /* api_path */,
|
||||
@ -409,7 +401,7 @@ TEST(ring_buffer_open_file, read_full_file_in_reverse) {
|
||||
EXPECT_FALSE(stop_requested);
|
||||
std::size_t bytes_read{};
|
||||
data.resize(size);
|
||||
auto ret = nf->read_bytes(&data[0u], size, offset, bytes_read)
|
||||
auto ret = nf.read_bytes(data, offset, &bytes_read)
|
||||
? api_error::success
|
||||
: api_error::os_error;
|
||||
EXPECT_EQ(bytes_read, data.size());
|
||||
@ -419,8 +411,8 @@ TEST(ring_buffer_open_file, read_full_file_in_reverse) {
|
||||
file_manager::ring_buffer_open_file rb(ring_buffer_dir, test_chunk_size,
|
||||
30U, fsi, mp, 8u);
|
||||
|
||||
native_file_ptr nf2;
|
||||
EXPECT_EQ(api_error::success, native_file::create_or_open(dest_path, nf2));
|
||||
auto nf2 = utils::file::file::open_or_create_file(dest_path);
|
||||
EXPECT_TRUE(nf2);
|
||||
|
||||
auto to_read = fsi.size;
|
||||
std::size_t chunk = rb.get_total_chunks() - 1u;
|
||||
@ -430,13 +422,12 @@ TEST(ring_buffer_open_file, read_full_file_in_reverse) {
|
||||
rb.read(test_chunk_size, chunk * test_chunk_size, data));
|
||||
|
||||
std::size_t bytes_written{};
|
||||
EXPECT_TRUE(nf2->write_bytes(data.data(), data.size(),
|
||||
chunk * test_chunk_size, bytes_written));
|
||||
EXPECT_TRUE(nf2.write(data, chunk * test_chunk_size, &bytes_written));
|
||||
chunk--;
|
||||
to_read -= data.size();
|
||||
}
|
||||
nf2->close();
|
||||
nf->close();
|
||||
nf2.close();
|
||||
nf.close();
|
||||
|
||||
EXPECT_STREQ(utils::file::generate_sha256(download_source_path).c_str(),
|
||||
utils::file::generate_sha256(dest_path).c_str());
|
||||
@ -446,12 +437,11 @@ TEST(ring_buffer_open_file, read_full_file_in_reverse) {
|
||||
}
|
||||
|
||||
TEST(ring_buffer_open_file, read_full_file_in_partial_chunks) {
|
||||
auto nf = test::create_random_file(test_chunk_size * 32u);
|
||||
const auto download_source_path =
|
||||
generate_test_file_name("./test_config", "ring_buffer_open_file");
|
||||
auto nf = create_random_file(download_source_path, test_chunk_size * 32u);
|
||||
test::generate_test_file_name("ring_buffer_open_file");
|
||||
|
||||
const auto dest_path =
|
||||
generate_test_file_name("./test_config", "ring_buffer_open_file");
|
||||
const auto dest_path = test::generate_test_file_name("ring_buffer_open_file");
|
||||
|
||||
mock_provider mp;
|
||||
|
||||
@ -461,8 +451,7 @@ TEST(ring_buffer_open_file, read_full_file_in_partial_chunks) {
|
||||
fsi.directory = false;
|
||||
fsi.api_path = "/test.txt";
|
||||
fsi.size = test_chunk_size * 32u;
|
||||
fsi.source_path =
|
||||
generate_test_file_name("./test_config", "ring_buffer_open_file");
|
||||
fsi.source_path = test::generate_test_file_name("ring_buffer_open_file");
|
||||
|
||||
EXPECT_CALL(mp, read_file_bytes)
|
||||
.WillRepeatedly([&nf](const std::string & /* api_path */,
|
||||
@ -472,7 +461,7 @@ TEST(ring_buffer_open_file, read_full_file_in_partial_chunks) {
|
||||
EXPECT_FALSE(stop_requested);
|
||||
std::size_t bytes_read{};
|
||||
data.resize(size);
|
||||
auto ret = nf->read_bytes(&data[0u], size, offset, bytes_read)
|
||||
auto ret = nf.read_bytes(data, offset, &bytes_read)
|
||||
? api_error::success
|
||||
: api_error::os_error;
|
||||
EXPECT_EQ(bytes_read, data.size());
|
||||
@ -482,8 +471,8 @@ TEST(ring_buffer_open_file, read_full_file_in_partial_chunks) {
|
||||
file_manager::ring_buffer_open_file rb(ring_buffer_dir, test_chunk_size,
|
||||
30U, fsi, mp, 8u);
|
||||
|
||||
native_file_ptr nf2;
|
||||
EXPECT_EQ(api_error::success, native_file::create_or_open(dest_path, nf2));
|
||||
auto nf2 =
|
||||
utils::file::file::open_or_create_file(dest_path) : EXPECT_TRUE(nf2);
|
||||
|
||||
auto total_read = std::uint64_t(0u);
|
||||
|
||||
@ -492,12 +481,11 @@ TEST(ring_buffer_open_file, read_full_file_in_partial_chunks) {
|
||||
EXPECT_EQ(api_error::success, rb.read(3u, total_read, data));
|
||||
|
||||
std::size_t bytes_written{};
|
||||
EXPECT_TRUE(nf2->write_bytes(data.data(), data.size(), total_read,
|
||||
bytes_written));
|
||||
EXPECT_TRUE(nf2.write_bytes(data, total_read, &bytes_written));
|
||||
total_read += data.size();
|
||||
}
|
||||
nf2->close();
|
||||
nf->close();
|
||||
nf2.close();
|
||||
nf.close();
|
||||
|
||||
EXPECT_STREQ(utils::file::generate_sha256(download_source_path).c_str(),
|
||||
utils::file::generate_sha256(dest_path).c_str());
|
||||
@ -508,11 +496,10 @@ TEST(ring_buffer_open_file, read_full_file_in_partial_chunks) {
|
||||
|
||||
TEST(ring_buffer_open_file, read_full_file_in_partial_chunks_in_reverse) {
|
||||
const auto download_source_path =
|
||||
generate_test_file_name("./test_config", "ring_buffer_open_file");
|
||||
test::generate_test_file_name("ring_buffer_open_file");
|
||||
auto nf = create_random_file(download_source_path, test_chunk_size * 32u);
|
||||
|
||||
const auto dest_path =
|
||||
generate_test_file_name("./test_config", "ring_buffer_open_file");
|
||||
const auto dest_path = test::generate_test_file_name("ring_buffer_open_file");
|
||||
|
||||
mock_provider mp;
|
||||
|
||||
@ -522,8 +509,7 @@ TEST(ring_buffer_open_file, read_full_file_in_partial_chunks_in_reverse) {
|
||||
fsi.directory = false;
|
||||
fsi.api_path = "/test.txt";
|
||||
fsi.size = test_chunk_size * 32u;
|
||||
fsi.source_path =
|
||||
generate_test_file_name("./test_config", "ring_buffer_open_file");
|
||||
fsi.source_path = test::generate_test_file_name("ring_buffer_open_file");
|
||||
|
||||
EXPECT_CALL(mp, read_file_bytes)
|
||||
.WillRepeatedly([&nf](const std::string & /* api_path */,
|
||||
@ -533,9 +519,8 @@ TEST(ring_buffer_open_file, read_full_file_in_partial_chunks_in_reverse) {
|
||||
EXPECT_FALSE(stop_requested);
|
||||
std::size_t bytes_read{};
|
||||
data.resize(size);
|
||||
auto ret = nf->read_bytes(&data[0u], size, offset, bytes_read)
|
||||
? api_error::success
|
||||
: api_error::os_error;
|
||||
auto ret = nf.read(data, offset, &bytes_read) ? api_error::success
|
||||
: api_error::os_error;
|
||||
EXPECT_EQ(bytes_read, data.size());
|
||||
return ret;
|
||||
});
|
||||
@ -543,8 +528,8 @@ TEST(ring_buffer_open_file, read_full_file_in_partial_chunks_in_reverse) {
|
||||
file_manager::ring_buffer_open_file rb(ring_buffer_dir, test_chunk_size,
|
||||
30U, fsi, mp, 8u);
|
||||
|
||||
native_file_ptr nf2;
|
||||
EXPECT_EQ(api_error::success, native_file::create_or_open(dest_path, nf2));
|
||||
auto nf2 = utils::file::file::open_or_create_file(dest_path);
|
||||
EXPERT_TRUE(nf2);
|
||||
|
||||
auto total_read = std::uint64_t(0u);
|
||||
const auto read_size = 3u;
|
||||
@ -560,13 +545,12 @@ TEST(ring_buffer_open_file, read_full_file_in_partial_chunks_in_reverse) {
|
||||
(remain >= read_size) ? offset : 0u, data));
|
||||
|
||||
std::size_t bytes_written{};
|
||||
EXPECT_TRUE(nf2->write_bytes(data.data(), data.size(),
|
||||
(remain >= read_size) ? offset : 0u,
|
||||
bytes_written));
|
||||
EXPECT_TRUE(
|
||||
nf2.write(data, (remain >= read_size) ? offset : 0u, &bytes_written));
|
||||
total_read += data.size();
|
||||
}
|
||||
nf2->close();
|
||||
nf->close();
|
||||
nf2.close();
|
||||
nf.close();
|
||||
|
||||
EXPECT_STREQ(utils::file::generate_sha256(download_source_path).c_str(),
|
||||
utils::file::generate_sha256(dest_path).c_str());
|
||||
|
@ -34,7 +34,6 @@
|
||||
#include "utils/encrypting_reader.hpp"
|
||||
#include "utils/event_capture.hpp"
|
||||
#include "utils/file_utils.hpp"
|
||||
#include "utils/native_file.hpp"
|
||||
#include "utils/path.hpp"
|
||||
#include "utils/polling.hpp"
|
||||
#include "utils/string.hpp"
|
||||
@ -43,7 +42,7 @@
|
||||
|
||||
namespace repertory {
|
||||
static std::string file_manager_dir =
|
||||
utils::path::combine("./test_config", {"file_manager_test"});
|
||||
utils::path::combine(test::get_test_output_dir(), {"file_manager_test"});
|
||||
|
||||
auto file_manager::open(std::shared_ptr<i_closeable_open_file> of,
|
||||
const open_file_data &ofd, std::uint64_t &handle,
|
||||
@ -426,9 +425,8 @@ TEST(file_manager, download_is_stored_after_write_if_partially_downloaded) {
|
||||
false, 1, "key", 2, now + 3u, 3u, 4u,
|
||||
utils::encryption::encrypting_reader::get_data_chunk_size() * 4u,
|
||||
source_path, 10, now + 4u);
|
||||
auto nf = create_random_file(
|
||||
generate_test_file_name("./test_config", "file_manage_test"),
|
||||
utils::string::to_uint64(meta[META_SIZE]));
|
||||
auto nf =
|
||||
test::create_random_file(utils::string::to_uint64(meta[META_SIZE]));
|
||||
|
||||
EXPECT_CALL(mp, get_filesystem_item)
|
||||
.WillRepeatedly([&meta](const std::string &api_path, bool directory,
|
||||
@ -465,9 +463,8 @@ TEST(file_manager, download_is_stored_after_write_if_partially_downloaded) {
|
||||
if (offset == 0u) {
|
||||
std::size_t bytes_read{};
|
||||
data.resize(size);
|
||||
auto ret = nf->read_bytes(&data[0u], size, offset, bytes_read)
|
||||
? api_error::success
|
||||
: api_error::os_error;
|
||||
auto ret = nf.read(data, offset, &bytes_read) ? api_error::success
|
||||
: api_error::os_error;
|
||||
EXPECT_EQ(bytes_read, data.size());
|
||||
return ret;
|
||||
}
|
||||
@ -542,7 +539,7 @@ TEST(file_manager, download_is_stored_after_write_if_partially_downloaded) {
|
||||
EXPECT_EQ(std::size_t(0u), fm.get_open_file_count());
|
||||
EXPECT_EQ(std::size_t(0u), fm.get_open_handle_count());
|
||||
|
||||
nf->close();
|
||||
nf.close();
|
||||
}
|
||||
|
||||
event_system::instance().stop();
|
||||
@ -589,9 +586,8 @@ TEST(file_manager, upload_occurs_after_write_if_fully_downloaded) {
|
||||
false, 1, "key", 2, now + 3u, 3u, 4u,
|
||||
utils::encryption::encrypting_reader::get_data_chunk_size() * 4u,
|
||||
source_path, 10, now + 4u);
|
||||
auto nf = create_random_file(
|
||||
generate_test_file_name("./test_config", "file_manage_test"),
|
||||
utils::string::to_uint64(meta[META_SIZE]));
|
||||
auto nf =
|
||||
test::create_random_file(utils::string::to_uint64(meta[META_SIZE]));
|
||||
|
||||
EXPECT_CALL(mp, get_filesystem_item)
|
||||
.WillRepeatedly([&meta](const std::string &api_path, bool directory,
|
||||
@ -623,9 +619,8 @@ TEST(file_manager, upload_occurs_after_write_if_fully_downloaded) {
|
||||
stop_type & /* stop_requested */) -> api_error {
|
||||
std::size_t bytes_read{};
|
||||
data.resize(size);
|
||||
auto ret = nf->read_bytes(&data[0u], size, offset, bytes_read)
|
||||
? api_error::success
|
||||
: api_error::os_error;
|
||||
auto ret = nf.read(data, offset, &bytes_read) ? api_error::success
|
||||
: api_error::os_error;
|
||||
EXPECT_EQ(bytes_read, data.size());
|
||||
return ret;
|
||||
});
|
||||
@ -660,7 +655,7 @@ TEST(file_manager, upload_occurs_after_write_if_fully_downloaded) {
|
||||
|
||||
fm.stop();
|
||||
|
||||
nf->close();
|
||||
nf.close();
|
||||
}
|
||||
|
||||
polling::instance().stop();
|
||||
@ -1601,10 +1596,9 @@ TEST(file_manager, can_remove_file) {
|
||||
|
||||
file_manager fm(cfg, mp);
|
||||
|
||||
native_file::native_file_ptr f{};
|
||||
EXPECT_EQ(api_error::success,
|
||||
native_file::create_or_open("./test_remove.txt", f));
|
||||
f->close();
|
||||
auto file = utils::file::file::open_or_create_file("./test_remove.txt");
|
||||
EXPECT_TRUE(file);
|
||||
file.close();
|
||||
EXPECT_TRUE(utils::file::is_file("./test_remove.txt"));
|
||||
|
||||
EXPECT_CALL(mp, get_filesystem_item)
|
||||
|
@ -35,8 +35,7 @@ TEST(upload, can_upload_a_valid_file) {
|
||||
|
||||
event_system::instance().start();
|
||||
|
||||
const auto source_path =
|
||||
generate_test_file_name("./test_config", "upload_test");
|
||||
const auto source_path = test::generate_test_file_name("upload_test");
|
||||
|
||||
mock_provider mp;
|
||||
|
||||
@ -79,8 +78,7 @@ TEST(upload, can_cancel_upload) {
|
||||
|
||||
event_system::instance().start();
|
||||
|
||||
const auto source_path =
|
||||
generate_test_file_name("./test_config", "upload_test");
|
||||
const auto source_path = test::generate_test_file_name("upload_test");
|
||||
|
||||
mock_provider mp;
|
||||
|
||||
@ -145,8 +143,7 @@ TEST(upload, can_stop_upload) {
|
||||
|
||||
event_system::instance().start();
|
||||
|
||||
const auto source_path =
|
||||
generate_test_file_name("./test_config", "upload_test");
|
||||
const auto source_path = test::generate_test_file_name("upload_test");
|
||||
|
||||
mock_provider mp;
|
||||
|
||||
|
@ -515,7 +515,7 @@ TEST(fuse_drive, all_tests) {
|
||||
std::filesystem::current_path(current_directory);
|
||||
|
||||
const auto test_directory = utils::path::combine(
|
||||
"./test_config", {"fuse_drive" + std::to_string(idx)});
|
||||
test::get_test_output_dir(), {"fuse_drive" + std::to_string(idx)});
|
||||
EXPECT_TRUE(utils::file::delete_directory_recursively(test_directory));
|
||||
|
||||
const auto mount_location =
|
||||
@ -538,8 +538,9 @@ TEST(fuse_drive, all_tests) {
|
||||
config_ptr =
|
||||
std::make_unique<app_config>(provider_type::s3, cfg_directory);
|
||||
{
|
||||
app_config src_cfg(provider_type::s3,
|
||||
utils::path::combine(get_test_dir(), {"storj"}));
|
||||
app_config src_cfg(
|
||||
provider_type::s3,
|
||||
utils::path::combine(test::get_test_input_dir(), {"storj"}));
|
||||
config_ptr->set_enable_drive_events(true);
|
||||
config_ptr->set_event_level(event_level::trace);
|
||||
config_ptr->set_s3_config(src_cfg.get_s3_config());
|
||||
@ -554,8 +555,9 @@ TEST(fuse_drive, all_tests) {
|
||||
config_ptr =
|
||||
std::make_unique<app_config>(provider_type::sia, cfg_directory);
|
||||
{
|
||||
app_config src_cfg(provider_type::sia,
|
||||
utils::path::combine(get_test_dir(), {"sia"}));
|
||||
app_config src_cfg(
|
||||
provider_type::sia,
|
||||
utils::path::combine(test::get_test_input_dir(), {"sia"}));
|
||||
config_ptr->set_enable_drive_events(true);
|
||||
config_ptr->set_event_level(event_level::debug);
|
||||
config_ptr->set_host_config(src_cfg.get_host_config());
|
||||
|
@ -107,8 +107,7 @@ const auto create_directory = [](repertory::i_provider &provider,
|
||||
|
||||
const auto create_file = [](repertory::i_provider &provider,
|
||||
const std::string &api_path) {
|
||||
auto source_path =
|
||||
repertory::generate_test_file_name("./test_config", "providers_test");
|
||||
auto source_path = repertory::test::generate_test_file_name("providers_test");
|
||||
|
||||
auto date = repertory::utils::time::get_file_time_now();
|
||||
auto meta = repertory::create_meta_attributes(
|
||||
@ -398,7 +397,7 @@ static void get_directory_item_count(const app_config &cfg,
|
||||
EXPECT_EQ(std::size_t(0U), provider.get_directory_item_count("/not_found"));
|
||||
|
||||
const auto source_path =
|
||||
utils::path::combine("./test_data/encrypt", {"sub10"});
|
||||
utils::path::combine(test::get_test_input_dir(), {"encrypt", "sub10"});
|
||||
|
||||
std::string api_path{};
|
||||
EXPECT_EQ(api_error::success,
|
||||
@ -630,7 +629,7 @@ static void run_tests(const app_config &cfg, i_provider &provider) {
|
||||
|
||||
TEST(providers, encrypt_provider) {
|
||||
const auto config_path =
|
||||
utils::path::combine("./test_config", {"encrypt_provider"});
|
||||
utils::path::combine(test::get_test_output_dir(), {"encrypt_provider"});
|
||||
ASSERT_TRUE(utils::file::delete_directory_recursively(config_path));
|
||||
|
||||
console_consumer consumer{};
|
||||
@ -639,7 +638,7 @@ TEST(providers, encrypt_provider) {
|
||||
app_config cfg(provider_type::encrypt, config_path);
|
||||
|
||||
const auto encrypt_path =
|
||||
utils::path::combine("./test_data/encrypt", {"encrypt"});
|
||||
utils::path::combine(test::get_test_input_dir(), {"encrypt"});
|
||||
|
||||
EXPECT_STREQ(
|
||||
encrypt_path.c_str(),
|
||||
@ -673,7 +672,7 @@ TEST(providers, encrypt_provider) {
|
||||
|
||||
TEST(providers, s3_provider) {
|
||||
const auto config_path =
|
||||
utils::path::combine("./test_config", {"s3_provider"});
|
||||
utils::path::combine(test::get_test_output_dir(), {"s3_provider"});
|
||||
ASSERT_TRUE(utils::file::delete_directory_recursively(config_path));
|
||||
|
||||
console_consumer consumer{};
|
||||
@ -681,8 +680,9 @@ TEST(providers, s3_provider) {
|
||||
{
|
||||
app_config cfg(provider_type::s3, config_path);
|
||||
{
|
||||
app_config src_cfg(provider_type::s3,
|
||||
utils::path::combine(get_test_dir(), {"storj"}));
|
||||
app_config src_cfg(
|
||||
provider_type::s3,
|
||||
utils::path::combine(test::get_test_input_dir(), {"storj"}));
|
||||
cfg.set_s3_config(src_cfg.get_s3_config());
|
||||
}
|
||||
|
||||
@ -711,7 +711,7 @@ TEST(providers, s3_provider) {
|
||||
|
||||
TEST(providers, sia_provider) {
|
||||
const auto config_path =
|
||||
utils::path::combine("./test_config", {"sia_provider"});
|
||||
utils::path::combine(test::get_test_output_dir(), {"sia_provider"});
|
||||
ASSERT_TRUE(utils::file::delete_directory_recursively(config_path));
|
||||
|
||||
console_consumer consumer{};
|
||||
@ -719,8 +719,9 @@ TEST(providers, sia_provider) {
|
||||
{
|
||||
app_config cfg(provider_type::sia, config_path);
|
||||
{
|
||||
app_config src_cfg(provider_type::sia,
|
||||
utils::path::combine(get_test_dir(), {"sia"}));
|
||||
app_config src_cfg(
|
||||
provider_type::sia,
|
||||
utils::path::combine(test::get_test_input_dir(), {"sia"}));
|
||||
cfg.set_host_config(src_cfg.get_host_config());
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ using namespace repertory::remote_fuse;
|
||||
namespace fuse_test {
|
||||
static std::string mount_location_;
|
||||
static std::string fuse_remote_dir =
|
||||
utils::path::combine("./test_config", {"fuse_remote_test"});
|
||||
utils::path::combine(test::get_test_output_dir(), {"fuse_remote_test"});
|
||||
|
||||
static void access_test(repertory::remote_fuse::remote_client &client) {
|
||||
const auto test_file = utils::path::combine(fuse_remote_dir, {"access.txt"});
|
||||
@ -934,7 +934,7 @@ TEST(remote_fuse, all_tests) {
|
||||
|
||||
event_system::instance().start();
|
||||
#if defined(_WIN32)
|
||||
mount_location_ = std::string("./test_config").substr(0, 2);
|
||||
mount_location_ = std::string(test::get_test_output_dir(), 2);
|
||||
mock_winfsp_drive drive(mount_location_);
|
||||
remote_server server(config, drive, mount_location_);
|
||||
#else
|
||||
|
@ -40,7 +40,7 @@ using namespace repertory::remote_winfsp;
|
||||
namespace winfsp_test {
|
||||
static std::string mount_location_;
|
||||
static std::string win_remote_dir =
|
||||
utils::path::combine("./test_config", {"win_remote_test"});
|
||||
utils::path::combine(test::get_test_output_dir(), {"win_remote_test"});
|
||||
|
||||
static void can_delete_test(remote_client &client) {
|
||||
const auto test_file =
|
||||
@ -49,15 +49,14 @@ static void can_delete_test(remote_client &client) {
|
||||
auto api_path =
|
||||
utils::string::from_utf8(test_file).substr(mount_location_.size());
|
||||
|
||||
native_file::native_file_ptr nf;
|
||||
EXPECT_EQ(api_error::success, native_file::create_or_open(test_file, nf));
|
||||
auto nf = utils::file::file::open_or_create_file(test_file);
|
||||
EXPECT_TRUE(nf);
|
||||
if (nf) {
|
||||
EXPECT_EQ(STATUS_INVALID_HANDLE,
|
||||
client.winfsp_can_delete(
|
||||
reinterpret_cast<PVOID>(nf->get_handle()), &api_path[0]));
|
||||
reinterpret_cast<PVOID>(nf.get_handle()), api_path.c_str());
|
||||
|
||||
nf->close();
|
||||
nf.close();
|
||||
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
|
||||
}
|
||||
}
|
||||
@ -502,7 +501,7 @@ TEST(remote_winfsp, all_tests) {
|
||||
|
||||
event_system::instance().start();
|
||||
#if defined(_WIN32)
|
||||
mount_location_ = std::string("./test_config").substr(0, 2);
|
||||
mount_location_ = std::string(test::get_test_output_dir(), 2);
|
||||
mock_winfsp_drive drive(mount_location_);
|
||||
remote_server server(config, drive, mount_location_);
|
||||
#else
|
||||
|
@ -1,73 +0,0 @@
|
||||
/*
|
||||
Copyright <2018-2024> <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
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#include "test_common.hpp"
|
||||
|
||||
#include "types/repertory.hpp"
|
||||
#include "utils/common.hpp"
|
||||
#include "utils/path.hpp"
|
||||
|
||||
namespace repertory {
|
||||
std::vector<std::string> generated_files;
|
||||
|
||||
void delete_generated_files() {
|
||||
for (const auto &file : generated_files) {
|
||||
EXPECT_TRUE(utils::file::retry_delete_file(file));
|
||||
}
|
||||
}
|
||||
|
||||
auto create_random_file(std::string path, std::size_t size) -> native_file_ptr {
|
||||
native_file_ptr file;
|
||||
if (native_file::create_or_open(path, file) == api_error::success) {
|
||||
generated_files.emplace_back(utils::path::absolute(path));
|
||||
|
||||
EXPECT_TRUE(file->truncate(0U));
|
||||
|
||||
data_buffer buf(size);
|
||||
randombytes_buf(buf.data(), buf.size());
|
||||
|
||||
std::size_t bytes_written{};
|
||||
EXPECT_TRUE(file->write_bytes(buf.data(), buf.size(), 0U, bytes_written));
|
||||
file->flush();
|
||||
|
||||
std::uint64_t current_size{};
|
||||
EXPECT_TRUE(utils::file::get_file_size(path, current_size));
|
||||
EXPECT_EQ(size, current_size);
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
auto generate_test_file_name(const std::string &directory,
|
||||
const std::string &file_name_no_extension)
|
||||
-> std::string {
|
||||
static std::atomic<std::uint32_t> idx{0U};
|
||||
auto path = utils::path::combine(
|
||||
directory, {file_name_no_extension + std::to_string(idx++) + ".dat"});
|
||||
generated_files.emplace_back(path);
|
||||
return path;
|
||||
}
|
||||
|
||||
auto get_test_dir() -> std::string {
|
||||
auto dir = utils::get_environment_variable("PROJECT_TEST_DIR");
|
||||
return utils::path::combine(dir.empty() ? "." : dir, {"test_config"});
|
||||
}
|
||||
} // namespace repertory
|
Reference in New Issue
Block a user