fixes
Some checks failed
BlockStorage/repertory/pipeline/head There was a failure building this commit
Some checks failed
BlockStorage/repertory/pipeline/head There was a failure building this commit
This commit is contained in:
@ -114,7 +114,8 @@ auto encrypt_provider::create_api_file(
|
||||
file.creation_date =
|
||||
(static_cast<std::uint64_t>(ft.dwHighDateTime) << 32U) | ft.dwLowDateTime;
|
||||
|
||||
ft = utils::time::unix_time_to_filetime(utils::time::time64_to_unix_time(buf.st_mtime));
|
||||
ft = utils::time::unix_time_to_filetime(
|
||||
utils::time::time64_to_unix_time(buf.st_mtime));
|
||||
file.modified_date =
|
||||
(static_cast<std::uint64_t>(ft.dwHighDateTime) << 32U) | ft.dwLowDateTime;
|
||||
#else
|
||||
|
@ -196,8 +196,8 @@ 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);
|
||||
const auto source_path = nf.get_path().string();
|
||||
|
||||
mock_provider mp;
|
||||
mock_upload_manager um;
|
||||
|
@ -437,10 +437,9 @@ 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 =
|
||||
test::generate_test_file_name("ring_buffer_open_file");
|
||||
const auto download_source_path = nf.get_path().string();
|
||||
|
||||
const auto dest_path = test::generate_test_file_name("ring_buffer_open_file");
|
||||
const auto dest_path = test::generate_test_file_name("test");
|
||||
|
||||
mock_provider mp;
|
||||
|
||||
@ -450,7 +449,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 = test::generate_test_file_name("ring_buffer_open_file");
|
||||
fsi.source_path = test::generate_test_file_name("test");
|
||||
|
||||
EXPECT_CALL(mp, read_file_bytes)
|
||||
.WillRepeatedly([&nf](const std::string & /* api_path */,
|
||||
@ -471,6 +470,8 @@ TEST(ring_buffer_open_file, read_full_file_in_partial_chunks) {
|
||||
|
||||
auto nf2 = utils::file::file::open_or_create_file(dest_path);
|
||||
EXPECT_TRUE(nf2);
|
||||
// EXPECT_EQ(api_error::success, native_file::create_or_open(dest_path,
|
||||
// nf2));
|
||||
|
||||
auto total_read = std::uint64_t(0u);
|
||||
|
||||
@ -479,7 +480,8 @@ 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(data, total_read, &bytes_written));
|
||||
EXPECT_TRUE(
|
||||
nf2.write(data.data(), data.size(), total_read, &bytes_written));
|
||||
total_read += data.size();
|
||||
}
|
||||
nf2.close();
|
||||
|
@ -42,13 +42,13 @@ auto file::attach_file(native_handle handle, bool read_only) -> file {
|
||||
static_cast<DWORD>(path.size()),
|
||||
FILE_NAME_NORMALIZED | VOLUME_NAME_DOS);
|
||||
#else // !defined(_WIN32)
|
||||
source_path.resize(PATH_MAX + 1);
|
||||
path.resize(PATH_MAX + 1);
|
||||
|
||||
#if defined(__APPLE__)
|
||||
fcntl(handle, F_GETPATH, source_path.data());
|
||||
#else // !defined(__APPLE__)
|
||||
readlink(("/proc/self/fd/" + std::to_string(handle)).c_str(),
|
||||
source_path.data(), source_path.size());
|
||||
readlink(("/proc/self/fd/" + std::to_string(handle)).c_str(), path.data(),
|
||||
path.size());
|
||||
#endif // defined(__APPLE__)
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
@ -87,14 +87,6 @@ auto file::open_file(std::filesystem::path path, bool read_only) -> file {
|
||||
throw std::runtime_error("file not found: " + path.string());
|
||||
}
|
||||
|
||||
if (not read_only) {
|
||||
#if defined(_WIN32)
|
||||
_chmod(path.string().c_str(), 0600U);
|
||||
#else // !defined(_WIN32)
|
||||
chmod(path.string().c_str(), 0600U);
|
||||
#endif // defined(_WIN32)
|
||||
}
|
||||
|
||||
#if defined(_WIN32)
|
||||
auto *ptr =
|
||||
_fsopen(path.string().c_str(), read_only ? "rb" : "rb+", _SH_DENYNO);
|
||||
@ -121,9 +113,9 @@ auto file::open_or_create_file(std::filesystem::path path,
|
||||
|
||||
#if defined(_WIN32)
|
||||
int old_mode{};
|
||||
_umask_s(0600U, &old_mode);
|
||||
_umask_s(077, &old_mode);
|
||||
#else // !defined(_WIN32)
|
||||
auto old_mode = umask(0600U);
|
||||
auto old_mode = umask(077);
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
#if defined(_WIN32)
|
||||
@ -361,7 +353,7 @@ auto file::write(const unsigned char *data, std::size_t to_write,
|
||||
auto bytes_written =
|
||||
fwrite(reinterpret_cast<const char *>(data), 1U, to_write, file_.get());
|
||||
if (not feof(file_.get()) && ferror(file_.get())) {
|
||||
throw std::runtime_error("failed to read file bytes");
|
||||
throw std::runtime_error("failed to write file bytes");
|
||||
}
|
||||
|
||||
flush();
|
||||
|
@ -22,6 +22,58 @@
|
||||
#include "test.hpp"
|
||||
|
||||
namespace repertory {
|
||||
TEST(utils_file, can_create_file) {
|
||||
auto path = test::generate_test_file_name("utils_file");
|
||||
EXPECT_FALSE(utils::file::is_file(path) || utils::file::is_directory(path));
|
||||
|
||||
auto file = utils::file::file::open_or_create_file(path);
|
||||
EXPECT_TRUE(file);
|
||||
|
||||
EXPECT_TRUE(utils::file::is_file(path));
|
||||
}
|
||||
|
||||
TEST(utils_file, can_open_file) {
|
||||
auto path = test::generate_test_file_name("utils_file");
|
||||
|
||||
{
|
||||
auto file = utils::file::file::open_or_create_file(path);
|
||||
EXPECT_TRUE(file);
|
||||
}
|
||||
|
||||
{
|
||||
auto file = utils::file::file::open_file(path);
|
||||
EXPECT_TRUE(file);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(utils_file, open_file_fails_if_not_found) {
|
||||
auto path = test::generate_test_file_name("utils_file");
|
||||
|
||||
auto file = utils::file::file::open_file(path);
|
||||
EXPECT_FALSE(file);
|
||||
}
|
||||
|
||||
TEST(utils_file, write_fails_for_read_only_file) {
|
||||
auto path = test::generate_test_file_name("utils_file");
|
||||
|
||||
auto file = utils::file::file::open_or_create_file(path, true);
|
||||
EXPECT_TRUE(utils::file::is_file(path));
|
||||
EXPECT_TRUE(file);
|
||||
std::size_t bytes_written{};
|
||||
EXPECT_FALSE(file.write(reinterpret_cast<const unsigned char *>("0"), 1U, 0U,
|
||||
&bytes_written));
|
||||
EXPECT_EQ(0U, bytes_written);
|
||||
}
|
||||
|
||||
TEST(utils_file, can_attach_file) {
|
||||
auto path = test::generate_test_file_name("utils_file");
|
||||
auto file = utils::file::file::open_or_create_file(path);
|
||||
auto file2 = utils::file::file::attach_file(file.get_handle());
|
||||
EXPECT_TRUE(file);
|
||||
EXPECT_TRUE(file2);
|
||||
EXPECT_EQ(file.get_path(), file2.get_path());
|
||||
}
|
||||
|
||||
#if defined(PROJECT_ENABLE_JSON)
|
||||
TEST(utils_file, read_and_write_json_file) {
|
||||
auto path = test::generate_test_file_name("utils_file");
|
||||
|
Reference in New Issue
Block a user