updated build system
This commit is contained in:
@ -33,7 +33,7 @@ using response_callback =
|
||||
|
||||
struct read_file_info final {
|
||||
stop_type &stop_requested;
|
||||
utils::file::file file{};
|
||||
std::unique_ptr<utils::file::i_file> file{};
|
||||
std::uint64_t offset{};
|
||||
};
|
||||
|
||||
@ -42,8 +42,8 @@ inline const auto read_file_data = static_cast<read_callback>(
|
||||
auto *read_info = reinterpret_cast<read_file_info *>(instream);
|
||||
std::size_t bytes_read{};
|
||||
auto ret =
|
||||
read_info->file.read(reinterpret_cast<unsigned char *>(buffer),
|
||||
size * nitems, read_info->offset, &bytes_read);
|
||||
read_info->file->read(reinterpret_cast<unsigned char *>(buffer),
|
||||
size * nitems, read_info->offset, &bytes_read);
|
||||
if (ret) {
|
||||
read_info->offset += bytes_read;
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ public:
|
||||
std::atomic<std::chrono::system_clock::time_point> last_access_{
|
||||
std::chrono::system_clock::now()};
|
||||
bool modified_{false};
|
||||
utils::file::file nf_;
|
||||
std::unique_ptr<utils::file::i_file> nf_;
|
||||
mutable std::mutex io_thread_mtx_;
|
||||
std::condition_variable io_thread_notify_;
|
||||
std::deque<std::shared_ptr<io_item>> io_thread_queue_;
|
||||
|
@ -49,11 +49,11 @@ auto http_put_file::set_method(CURL *curl,
|
||||
utils::file::file::open_or_create_file(source_path),
|
||||
});
|
||||
|
||||
if (not read_info->file) {
|
||||
if (not *read_info->file) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto file_size = read_info->file.size();
|
||||
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);
|
||||
|
@ -68,7 +68,7 @@ file_manager::open_file::open_file(
|
||||
if (not fsi.directory) {
|
||||
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);
|
||||
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();
|
||||
@ -78,16 +78,16 @@ file_manager::open_file::open_file(
|
||||
fsi_.size, chunk_size)),
|
||||
false);
|
||||
|
||||
auto file_size = nf_.size();
|
||||
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)) {
|
||||
} else if (not nf_->truncate(fsi.size)) {
|
||||
set_api_error(api_error::os_error);
|
||||
}
|
||||
}
|
||||
|
||||
if (get_api_error() != api_error::success && nf_) {
|
||||
nf_.close();
|
||||
if (get_api_error() != api_error::success && *nf_) {
|
||||
nf_->close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -182,7 +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(data, data_offset, &bytes_written)) {
|
||||
if (not nf_->write(data, data_offset, &bytes_written)) {
|
||||
return api_error::os_error;
|
||||
}
|
||||
|
||||
@ -242,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(
|
||||
@ -283,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(),
|
||||
@ -292,7 +292,7 @@ auto file_manager::open_file::native_operation(
|
||||
}
|
||||
|
||||
{
|
||||
auto file_size = nf_.size();
|
||||
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,
|
||||
@ -361,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(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;
|
||||
});
|
||||
@ -412,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;
|
||||
});
|
||||
}
|
||||
|
||||
@ -449,7 +449,7 @@ auto file_manager::open_file::close() -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
nf_.close();
|
||||
nf_->close();
|
||||
|
||||
if (modified_ && (get_api_error() == api_error::success)) {
|
||||
mgr_.queue_upload(*this);
|
||||
@ -575,7 +575,7 @@ auto file_manager::open_file::write(std::uint64_t write_offset,
|
||||
}
|
||||
|
||||
auto res = do_io([&]() -> api_error {
|
||||
if (not nf_.write(data, write_offset, &bytes_written)) {
|
||||
if (not nf_->write(data, write_offset, &bytes_written)) {
|
||||
return api_error::os_error;
|
||||
}
|
||||
|
||||
|
@ -73,13 +73,13 @@ file_manager::ring_buffer_open_file::ring_buffer_open_file(
|
||||
fsi_.source_path =
|
||||
utils::path::combine(buffer_directory, {utils::create_uuid_string()});
|
||||
nf_ = utils::file::file::open_or_create_file(fsi_.source_path);
|
||||
if (not nf_) {
|
||||
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,8 +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(buffer, (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;
|
||||
}
|
||||
|
||||
@ -200,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,8 +270,8 @@ auto file_manager::ring_buffer_open_file::read(std::size_t read_size,
|
||||
&to_read]() -> api_error {
|
||||
std::size_t bytes_read{};
|
||||
auto ret =
|
||||
nf_.read(buffer, ((chunk % ring_state_.size()) * chunk_size_),
|
||||
&bytes_read)
|
||||
nf_->read(buffer, ((chunk % ring_state_.size()) * chunk_size_),
|
||||
&bytes_read)
|
||||
? api_error::success
|
||||
: api_error::os_error;
|
||||
if (ret == api_error::success) {
|
||||
|
@ -278,15 +278,15 @@ auto generate_sha256(const std::string &file_path) -> std::string {
|
||||
}
|
||||
|
||||
auto nf = utils::file::file::open_file(file_path);
|
||||
if (not nf) {
|
||||
if (not *nf) {
|
||||
throw std::runtime_error("failed to open file|" + file_path);
|
||||
}
|
||||
|
||||
{
|
||||
data_buffer buffer(1048576u);
|
||||
std::uint64_t read_offset = 0U;
|
||||
std::size_t bytes_read = 0U;
|
||||
while (nf.read(buffer, read_offset, &bytes_read)) {
|
||||
data_buffer buffer(nf->get_read_buffer_size());
|
||||
std::uint64_t read_offset{0U};
|
||||
std::size_t bytes_read{0U};
|
||||
while (nf->read(buffer, read_offset, &bytes_read)) {
|
||||
if (not bytes_read) {
|
||||
break;
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ namespace repertory {
|
||||
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, 1024UL);
|
||||
auto &source_file = create_random_file(source_file_name, 1024UL);
|
||||
EXPECT_TRUE(source_file != nullptr);
|
||||
if (source_file) {
|
||||
stop_type stop_requested = false;
|
||||
|
@ -171,7 +171,7 @@ 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) {
|
||||
auto rf = test::create_random_file(test_chunk_size);
|
||||
auto &rf = test::create_random_file(test_chunk_size);
|
||||
const auto source_path = rf.get_path().string();
|
||||
rf.close();
|
||||
|
||||
@ -197,7 +197,7 @@ TEST(open_file,
|
||||
|
||||
TEST(open_file, write_with_incomplete_download) {
|
||||
const auto source_path = test::generate_test_file_name("test");
|
||||
auto nf = test::create_random_file(test_chunk_size * 2u);
|
||||
auto &nf = test::create_random_file(test_chunk_size * 2u);
|
||||
|
||||
mock_provider mp;
|
||||
mock_upload_manager um;
|
||||
@ -449,7 +449,7 @@ TEST(open_file, write_new_file_multiple_chunks) {
|
||||
}
|
||||
|
||||
TEST(open_file, resize_file_to_0_bytes) {
|
||||
auto rf = test::create_random_file(test_chunk_size * 4u);
|
||||
auto &rf = test::create_random_file(test_chunk_size * 4u);
|
||||
const auto source_path = rf.get_path().string();
|
||||
rf.close();
|
||||
|
||||
@ -499,7 +499,7 @@ TEST(open_file, resize_file_to_0_bytes) {
|
||||
}
|
||||
|
||||
TEST(open_file, resize_file_by_full_chunk) {
|
||||
auto rf = test::create_random_file(test_chunk_size * 4u);
|
||||
auto &rf = test::create_random_file(test_chunk_size * 4u);
|
||||
const auto source_path = rf.get_path().string();
|
||||
rf.close();
|
||||
|
||||
|
@ -320,7 +320,7 @@ TEST(ring_buffer_open_file, can_reverse_full_ring) {
|
||||
}
|
||||
|
||||
TEST(ring_buffer_open_file, read_full_file) {
|
||||
auto nf = test::create_random_file(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 = test::generate_test_file_name("ring_buffer_open_file");
|
||||
@ -352,7 +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);
|
||||
|
||||
auto nf2 = utils::file::file::open_or_create_file(dest_path);
|
||||
auto ptr = utils::file::file::open_or_create_file(dest_path);
|
||||
auto &nf2 = *ptr;
|
||||
EXPECT_TRUE(nf2);
|
||||
|
||||
auto to_read = fsi.size;
|
||||
@ -378,7 +379,7 @@ TEST(ring_buffer_open_file, read_full_file) {
|
||||
}
|
||||
|
||||
TEST(ring_buffer_open_file, read_full_file_in_reverse) {
|
||||
auto nf = test::create_random_file(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 = test::generate_test_file_name("ring_buffer_open_file");
|
||||
@ -410,7 +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);
|
||||
|
||||
auto nf2 = utils::file::file::open_or_create_file(dest_path);
|
||||
auto ptr = utils::file::file::open_or_create_file(dest_path);
|
||||
auto &nf2 = *ptr;
|
||||
EXPECT_TRUE(nf2);
|
||||
|
||||
auto to_read = fsi.size;
|
||||
@ -436,7 +438,7 @@ 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);
|
||||
auto &nf = test::create_random_file(test_chunk_size * 32u);
|
||||
const auto download_source_path = nf.get_path().string();
|
||||
|
||||
const auto dest_path = test::generate_test_file_name("test");
|
||||
@ -468,7 +470,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);
|
||||
|
||||
auto nf2 = utils::file::file::open_or_create_file(dest_path);
|
||||
auto ptr = utils::file::file::open_or_create_file(dest_path);
|
||||
auto &nf2 = *ptr;
|
||||
EXPECT_TRUE(nf2);
|
||||
// EXPECT_EQ(api_error::success, native_file::create_or_open(dest_path,
|
||||
// nf2));
|
||||
@ -495,7 +498,7 @@ TEST(ring_buffer_open_file, read_full_file_in_partial_chunks) {
|
||||
}
|
||||
|
||||
TEST(ring_buffer_open_file, read_full_file_in_partial_chunks_in_reverse) {
|
||||
auto nf = test::create_random_file(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 = test::generate_test_file_name("ring_buffer_open_file");
|
||||
@ -527,7 +530,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);
|
||||
|
||||
auto nf2 = utils::file::file::open_or_create_file(dest_path);
|
||||
auto ptr = utils::file::file::open_or_create_file(dest_path);
|
||||
auto &nf2 = *ptr;
|
||||
EXPECT_TRUE(nf2);
|
||||
|
||||
std::uint64_t total_read{0U};
|
||||
|
@ -425,7 +425,7 @@ 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 =
|
||||
auto &nf =
|
||||
test::create_random_file(utils::string::to_uint64(meta[META_SIZE]));
|
||||
|
||||
EXPECT_CALL(mp, get_filesystem_item)
|
||||
@ -586,7 +586,7 @@ 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 =
|
||||
auto &nf =
|
||||
test::create_random_file(utils::string::to_uint64(meta[META_SIZE]));
|
||||
|
||||
EXPECT_CALL(mp, get_filesystem_item)
|
||||
@ -1596,9 +1596,10 @@ TEST(file_manager, can_remove_file) {
|
||||
|
||||
file_manager fm(cfg, mp);
|
||||
|
||||
auto file = utils::file::file::open_or_create_file("./test_remove.txt");
|
||||
EXPECT_TRUE(file);
|
||||
file.close();
|
||||
{
|
||||
auto file = utils::file::file::open_or_create_file("./test_remove.txt");
|
||||
EXPECT_TRUE(*file);
|
||||
}
|
||||
EXPECT_TRUE(utils::file::is_file("./test_remove.txt"));
|
||||
|
||||
EXPECT_CALL(mp, get_filesystem_item)
|
||||
|
@ -49,7 +49,8 @@ static void can_delete_test(remote_client &client) {
|
||||
auto api_path =
|
||||
utils::string::from_utf8(test_file).substr(mount_location_.size());
|
||||
|
||||
auto nf = utils::file::file::open_or_create_file(test_file);
|
||||
auto ptr = utils::file::file::open_or_create_file(test_file);
|
||||
auto &nf = *ptr;
|
||||
EXPECT_TRUE(nf);
|
||||
if (nf) {
|
||||
EXPECT_EQ(STATUS_INVALID_HANDLE,
|
||||
|
Reference in New Issue
Block a user