time fixes

This commit is contained in:
2025-09-25 18:47:37 -05:00
parent 144708a604
commit 1fe61f2d5e
21 changed files with 151 additions and 114 deletions

View File

@@ -1,15 +1,15 @@
set(BINUTILS_VERSION 2.44) set(BINUTILS_VERSION 2.44)
set(BOOST_MAJOR_VERSION 1)
set(BOOST_MINOR_VERSION 88)
set(BOOST_PATCH_VERSION 0)
set(BOOST2_MAJOR_VERSION 1) set(BOOST2_MAJOR_VERSION 1)
set(BOOST2_MINOR_VERSION 76) set(BOOST2_MINOR_VERSION 76)
set(BOOST2_PATCH_VERSION 0) set(BOOST2_PATCH_VERSION 0)
set(BOOST_MAJOR_VERSION 1)
set(BOOST_MINOR_VERSION 88)
set(BOOST_PATCH_VERSION 0)
set(CPP_HTTPLIB_VERSION 0.23.1) set(CPP_HTTPLIB_VERSION 0.23.1)
set(CURL_VERSION 8.15.0)
set(CURL2_VERSION 8_15_0) set(CURL2_VERSION 8_15_0)
set(EXPAT_VERSION 2.7.1) set(CURL_VERSION 8.15.0)
set(EXPAT2_VERSION 2_7_1) set(EXPAT2_VERSION 2_7_1)
set(EXPAT_VERSION 2.7.1)
set(GCC_VERSION 15.1.0) set(GCC_VERSION 15.1.0)
set(GTEST_VERSION 1.17.0) set(GTEST_VERSION 1.17.0)
set(ICU_VERSION 76-1) set(ICU_VERSION 76-1)
@@ -22,9 +22,9 @@ set(PKG_CONFIG_VERSION 0.29.2)
set(PUGIXML_VERSION 1.15) set(PUGIXML_VERSION 1.15)
set(ROCKSDB_VERSION 10.4.2) set(ROCKSDB_VERSION 10.4.2)
set(SPDLOG_VERSION 1.15.3) set(SPDLOG_VERSION 1.15.3)
set(SQLITE_VERSION 3500300)
set(SQLITE2_VERSION 3.50.3) set(SQLITE2_VERSION 3.50.3)
set(SQLITE_VERSION 3500300)
set(STDUUID_VERSION 1.2.3) set(STDUUID_VERSION 1.2.3)
set(WINFSP_VERSION 2.1.25156)
set(WINFSP2_VERSION 2.1) set(WINFSP2_VERSION 2.1)
set(WINFSP_VERSION 2.1.25156)
set(ZLIB_VERSION 1.3.1) set(ZLIB_VERSION 1.3.1)

View File

@@ -75,9 +75,9 @@ public:
std::uint64_t accessed_date, std::uint32_t attributes, std::uint64_t accessed_date, std::uint32_t attributes,
std::uint64_t changed_date, std::uint64_t creation_date, bool directory, std::uint64_t changed_date, std::uint64_t creation_date, bool directory,
std::uint32_t gid, const std::string &key, std::uint32_t mode, std::uint32_t gid, const std::string &key, std::uint32_t mode,
std::uint64_t modified_date, std::uint32_t osx_backup, std::uint64_t modified_date, std::uint32_t osx_flags, std::uint64_t size,
std::uint32_t osx_flags, std::uint64_t size, const std::string &source_path, const std::string &source_path, std::uint32_t uid,
std::uint32_t uid, std::uint64_t written_date) -> api_meta_map; std::uint64_t written_date) -> api_meta_map;
[[nodiscard]] auto provider_meta_creator(bool directory, const api_file &file) [[nodiscard]] auto provider_meta_creator(bool directory, const api_file &file)
-> api_meta_map; -> api_meta_map;

View File

@@ -62,9 +62,9 @@ public:
std::uint64_t accessed_date, std::uint32_t attributes, std::uint64_t accessed_date, std::uint32_t attributes,
std::uint64_t changed_date, std::uint64_t creation_date, bool directory, std::uint64_t changed_date, std::uint64_t creation_date, bool directory,
std::uint32_t gid, const std::string &key, std::uint32_t mode, std::uint32_t gid, const std::string &key, std::uint32_t mode,
std::uint64_t modified_date, std::uint32_t osx_backup, std::uint64_t modified_date, std::uint32_t osx_flags, std::uint64_t size,
std::uint32_t osx_flags, std::uint64_t size, const std::string &source_path, const std::string &source_path, std::uint32_t uid,
std::uint32_t uid, std::uint64_t written_date) -> api_meta_map; std::uint64_t written_date) -> api_meta_map;
[[nodiscard]] auto provider_meta_creator(bool directory, const api_file &file) [[nodiscard]] auto provider_meta_creator(bool directory, const api_file &file)
-> api_meta_map; -> api_meta_map;

View File

@@ -262,6 +262,7 @@ struct api_file final {
std::string key; std::string key;
std::uint64_t modified_date{}; std::uint64_t modified_date{};
std::string source_path; std::string source_path;
std::uint64_t written_date{};
}; };
struct directory_item final { struct directory_item final {

View File

@@ -220,7 +220,7 @@ auto fuse_drive::create_impl(std::string api_path, mode_t mode,
auto meta = create_meta_attributes( auto meta = create_meta_attributes(
now, FILE_ATTRIBUTE_ARCHIVE, now, now, is_directory_op, now, FILE_ATTRIBUTE_ARCHIVE, now, now, is_directory_op,
get_effective_gid(), "", mode, now, 0U, osx_flags, 0U, get_effective_gid(), "", mode, now, osx_flags, 0U,
utils::path::combine(config_.get_cache_directory(), utils::path::combine(config_.get_cache_directory(),
{utils::create_uuid_string()}), {utils::create_uuid_string()}),
get_effective_uid(), now); get_effective_uid(), now);
@@ -705,7 +705,7 @@ auto fuse_drive::mkdir_impl(std::string api_path, mode_t mode) -> api_error {
auto now = utils::time::get_time_now(); auto now = utils::time::get_time_now();
auto meta = create_meta_attributes(now, FILE_ATTRIBUTE_DIRECTORY, now, now, auto meta = create_meta_attributes(now, FILE_ATTRIBUTE_DIRECTORY, now, now,
true, get_effective_gid(), "", mode, now, true, get_effective_gid(), "", mode, now,
0U, 0U, 0U, "", get_effective_uid(), now); 0U, 0U, "", get_effective_uid(), now);
res = provider_.create_directory(api_path, meta); res = provider_.create_directory(api_path, meta);
if (res != api_error::success) { if (res != api_error::success) {
return res; return res;

View File

@@ -342,15 +342,15 @@ void fuse_drive_base::populate_stat(const std::string &api_path,
u_stat->st_blksize = 0; u_stat->st_blksize = 0;
u_stat->st_flags = get_flags_from_meta(meta); u_stat->st_flags = get_flags_from_meta(meta);
set_timespec_from_meta(meta, META_MODIFIED, u_stat->st_mtimespec);
set_timespec_from_meta(meta, META_CREATION, u_stat->st_birthtimespec);
set_timespec_from_meta(meta, META_CHANGED, u_stat->st_ctimespec);
set_timespec_from_meta(meta, META_ACCESSED, u_stat->st_atimespec); set_timespec_from_meta(meta, META_ACCESSED, u_stat->st_atimespec);
set_timespec_from_meta(meta, META_CHANGED, u_stat->st_ctimespec);
set_timespec_from_meta(meta, META_CREATION, u_stat->st_birthtimespec);
set_timespec_from_meta(meta, META_MODIFIED, u_stat->st_mtimespec);
#else // !defined(__APPLE__) #else // !defined(__APPLE__)
u_stat->st_blksize = 4096; u_stat->st_blksize = 4096;
set_timespec_from_meta(meta, META_MODIFIED, u_stat->st_mtim); set_timespec_from_meta(meta, META_MODIFIED, u_stat->st_mtim);
set_timespec_from_meta(meta, META_CREATION, u_stat->st_ctim); set_timespec_from_meta(meta, META_CHANGED, u_stat->st_ctim);
set_timespec_from_meta(meta, META_ACCESSED, u_stat->st_atim); set_timespec_from_meta(meta, META_ACCESSED, u_stat->st_atim);
#endif // defined(__APPLE__) #endif // defined(__APPLE__)
} }

View File

@@ -207,17 +207,18 @@ auto lock_data::wait_for_lock(int handle, std::uint8_t retry_count) -> int {
return lock_status; return lock_status;
} }
auto create_meta_attributes( auto create_meta_attributes(std::uint64_t accessed_date,
std::uint64_t accessed_date, std::uint32_t attributes, std::uint32_t attributes,
std::uint64_t changed_date, std::uint64_t creation_date, bool directory, std::uint64_t changed_date,
std::uint32_t gid, const std::string &key, std::uint32_t mode, std::uint64_t creation_date, bool directory,
std::uint64_t modified_date, std::uint32_t osx_backup, std::uint32_t gid, const std::string &key,
std::uint32_t osx_flags, std::uint64_t size, const std::string &source_path, std::uint32_t mode, std::uint64_t modified_date,
std::uint32_t uid, std::uint64_t written_date) -> api_meta_map { std::uint32_t osx_flags, std::uint64_t size,
const std::string &source_path, std::uint32_t uid,
std::uint64_t written_date) -> api_meta_map {
return { return {
{META_ACCESSED, std::to_string(accessed_date)}, {META_ACCESSED, std::to_string(accessed_date)},
{META_ATTRIBUTES, std::to_string(attributes)}, {META_ATTRIBUTES, std::to_string(attributes)},
{META_BACKUP, std::to_string(osx_backup)},
{META_CHANGED, std::to_string(changed_date)}, {META_CHANGED, std::to_string(changed_date)},
{META_CREATION, std::to_string(creation_date)}, {META_CREATION, std::to_string(creation_date)},
{META_DIRECTORY, utils::string::from_bool(directory)}, {META_DIRECTORY, utils::string::from_bool(directory)},
@@ -243,8 +244,8 @@ auto provider_meta_creator(bool directory, const api_file &file)
file.changed_date, file.creation_date, directory, getgid(), file.key, file.changed_date, file.creation_date, directory, getgid(), file.key,
directory ? S_IFDIR | S_IRUSR | S_IWUSR | S_IXUSR directory ? S_IFDIR | S_IRUSR | S_IWUSR | S_IXUSR
: S_IFREG | S_IRUSR | S_IWUSR, : S_IFREG | S_IRUSR | S_IWUSR,
file.modified_date, 0U, 0U, file.file_size, file.source_path, getuid(), file.modified_date, 0U, file.file_size, file.source_path, getuid(),
file.modified_date); file.written_date);
} }
auto provider_meta_handler(i_provider &provider, bool directory, auto provider_meta_handler(i_provider &provider, bool directory,

View File

@@ -189,17 +189,18 @@ auto lock_data::set_mount_state(bool active, std::string_view mount_location,
return ret; return ret;
} }
auto create_meta_attributes( auto create_meta_attributes(std::uint64_t accessed_date,
std::uint64_t accessed_date, std::uint32_t attributes, std::uint32_t attributes,
std::uint64_t changed_date, std::uint64_t creation_date, bool directory, std::uint64_t changed_date,
std::uint32_t gid, const std::string &key, std::uint32_t mode, std::uint64_t creation_date, bool directory,
std::uint64_t modified_date, std::uint32_t osx_backup, std::uint32_t gid, const std::string &key,
std::uint32_t osx_flags, std::uint64_t size, const std::string &source_path, std::uint32_t mode, std::uint64_t modified_date,
std::uint32_t uid, std::uint64_t written_date) -> api_meta_map { std::uint32_t osx_flags, std::uint64_t size,
const std::string &source_path, std::uint32_t uid,
std::uint64_t written_date) -> api_meta_map {
return { return {
{META_ACCESSED, std::to_string(accessed_date)}, {META_ACCESSED, std::to_string(accessed_date)},
{META_ATTRIBUTES, std::to_string(attributes)}, {META_ATTRIBUTES, std::to_string(attributes)},
{META_BACKUP, std::to_string(osx_backup)},
{META_CHANGED, std::to_string(changed_date)}, {META_CHANGED, std::to_string(changed_date)},
{META_CREATION, std::to_string(creation_date)}, {META_CREATION, std::to_string(creation_date)},
{META_DIRECTORY, utils::string::from_bool(directory)}, {META_DIRECTORY, utils::string::from_bool(directory)},
@@ -223,8 +224,8 @@ auto provider_meta_creator(bool directory, const api_file &file)
file.accessed_date, file.accessed_date,
directory ? FILE_ATTRIBUTE_DIRECTORY : FILE_ATTRIBUTE_ARCHIVE, directory ? FILE_ATTRIBUTE_DIRECTORY : FILE_ATTRIBUTE_ARCHIVE,
file.changed_date, file.creation_date, directory, 0u, file.key, file.changed_date, file.creation_date, directory, 0u, file.key,
directory ? S_IFDIR : S_IFREG, file.modified_date, 0u, 0u, file.file_size, directory ? S_IFDIR : S_IFREG, file.modified_date, 0u, file.file_size,
file.source_path, 0u, file.modified_date); file.source_path, 0u, file.written_date);
} }
auto provider_meta_handler(i_provider &provider, bool directory, auto provider_meta_handler(i_provider &provider, bool directory,

View File

@@ -72,15 +72,19 @@ void base_provider::add_all_items(stop_type &stop_requested) {
auto base_provider::create_api_file(std::string path, std::string key, auto base_provider::create_api_file(std::string path, std::string key,
std::uint64_t size, std::uint64_t file_time) std::uint64_t size, std::uint64_t file_time)
-> api_file { -> api_file {
api_file file{}; auto api_path = utils::path::create_api_path(path);
file.api_path = utils::path::create_api_path(path); api_file file{
file.api_parent = utils::path::get_parent_api_path(file.api_path); .api_path = api_path,
file.accessed_date = file_time; .api_parent = utils::path::get_parent_api_path(api_path),
file.changed_date = file_time; .accessed_date = file_time,
file.creation_date = file_time; .changed_date = file_time,
file.modified_date = file_time; .creation_date = file_time,
file.key = key; .file_size = size,
file.file_size = size; .key = key,
.modified_date = file_time,
.source_path = "",
.written_date = file_time,
};
return file; return file;
} }
@@ -99,6 +103,7 @@ auto base_provider::create_api_file(std::string path, std::uint64_t size,
file.creation_date = utils::string::to_uint64(meta[META_CREATION]); file.creation_date = utils::string::to_uint64(meta[META_CREATION]);
file.file_size = current_size; file.file_size = current_size;
file.modified_date = utils::string::to_uint64(meta[META_MODIFIED]); file.modified_date = utils::string::to_uint64(meta[META_MODIFIED]);
file.written_date = utils::string::to_uint64(meta[META_WRITTEN]);
return file; return file;
} }

View File

@@ -57,19 +57,22 @@ auto encrypt_provider::create_api_file(const std::string &api_path,
throw std::runtime_error("failed to get file times"); throw std::runtime_error("failed to get file times");
} }
api_file file{}; api_file file{
file.accessed_date = times->get(utils::file::time_type::accessed); .api_path = api_path,
file.api_path = api_path; .api_parent = utils::path::get_parent_api_path(api_path),
file.api_parent = utils::path::get_parent_api_path(api_path); .accessed_date = times->get(utils::file::time_type::accessed),
file.changed_date = times->get(utils::file::time_type::modified); .changed_date = times->get(utils::file::time_type::changed),
file.creation_date = times->get(utils::file::time_type::created); .creation_date = times->get(utils::file::time_type::created),
file.file_size = .file_size =
directory directory
? 0U ? 0U
: utils::encryption::encrypting_reader::calculate_encrypted_size( : utils::encryption::encrypting_reader::calculate_encrypted_size(
source_path, true); source_path, true),
file.modified_date = times->get(utils::file::time_type::written); .key = "",
file.source_path = source_path; .modified_date = times->get(utils::file::time_type::modified),
.source_path = source_path,
.written_date = times->get(utils::file::time_type::written),
};
return file; return file;
} }
@@ -97,7 +100,7 @@ void encrypt_provider::create_item_meta(api_meta_map &meta, bool directory,
meta[META_UID] = std::to_string(buf.st_uid); meta[META_UID] = std::to_string(buf.st_uid);
#if defined(__APPLE__) #if defined(__APPLE__)
meta[META_BACKUP] = std::to_string(buf.st_bkuptime); meta[META_BACKUP];
meta[META_OSXFLAGS] = std::to_string(buf.st_flags); meta[META_OSXFLAGS] = std::to_string(buf.st_flags);
#endif // defined(__APPLE__) #endif // defined(__APPLE__)
} }

View File

@@ -404,7 +404,7 @@ auto s3_provider::get_directory_items_impl(const std::string &api_path,
file.api_path = dir_item.api_path; file.api_path = dir_item.api_path;
file.api_parent = dir_item.api_parent; file.api_parent = dir_item.api_parent;
file.accessed_date = file.changed_date = file.creation_date = file.accessed_date = file.changed_date = file.creation_date =
file.modified_date = last_modified; file.modified_date = file.written_date = last_modified;
file.file_size = dir_item.size; file.file_size = dir_item.size;
if (is_encrypted) { if (is_encrypted) {
file.key = child_object_name; file.key = child_object_name;
@@ -540,7 +540,7 @@ auto s3_provider::get_file(const std::string &api_path, api_file &file) const
file.api_path = api_path; file.api_path = api_path;
file.api_parent = utils::path::get_parent_api_path(api_path); file.api_parent = utils::path::get_parent_api_path(api_path);
file.accessed_date = file.changed_date = file.creation_date = file.accessed_date = file.changed_date = file.creation_date =
file.modified_date = result.last_modified; file.modified_date = file.written_date = result.last_modified;
file.key = is_encrypted ? utils::path::create_api_path(object_name) : ""; file.key = is_encrypted ? utils::path::create_api_path(object_name) : "";
file.file_size = file.file_size =
is_encrypted is_encrypted
@@ -616,21 +616,24 @@ auto s3_provider::get_file_list(api_file_list &list, std::string &marker) const
auto size{node.node().select_node("Size").node().text().as_ullong()}; auto size{node.node().select_node("Size").node().text().as_ullong()};
api_file file{}; api_path = utils::path::create_api_path(api_path);
file.api_path = utils::path::create_api_path(api_path); auto date = convert_api_date(
file.api_parent = utils::path::get_parent_api_path(file.api_path); node.node().select_node("LastModified").node().text().as_string());
file.accessed_date = file.changed_date = file.creation_date = api_file file{
file.modified_date = convert_api_date(node.node() .api_path = api_path,
.select_node("LastModified") .api_parent = utils::path::get_parent_api_path(api_path),
.node() .accessed_date = date,
.text() .changed_date = date,
.as_string()); .creation_date = date,
file.file_size = .file_size = is_encrypted ? utils::encryption::encrypting_reader::
is_encrypted calculate_decrypted_size(
? utils::encryption::encrypting_reader::calculate_decrypted_size( size, not legacy_bucket_)
size, not legacy_bucket_) : size,
: size; .key = is_encrypted ? utils::path::create_api_path(object_name) : "",
file.key = is_encrypted ? utils::path::create_api_path(object_name) : ""; .modified_date = date,
.source_path = "",
.written_date = date,
};
auto res{add_if_not_found(file, file.key)}; auto res{add_if_not_found(file, file.key)};
if (res != api_error::success) { if (res != api_error::success) {
return res; return res;

View File

@@ -95,12 +95,12 @@ auto get_accessed_time_from_meta(const api_meta_map &meta) -> std::uint64_t {
auto get_changed_time_from_meta(const api_meta_map &meta) -> std::uint64_t { auto get_changed_time_from_meta(const api_meta_map &meta) -> std::uint64_t {
return utils::time::unix_time_to_windows_time( return utils::time::unix_time_to_windows_time(
utils::string::to_uint64(meta.at(META_MODIFIED))); utils::string::to_uint64(meta.at(META_CHANGED)));
} }
auto get_creation_time_from_meta(const api_meta_map &meta) -> std::uint64_t { auto get_modified_time_from_meta(const api_meta_map &meta) -> std::uint64_t {
return utils::time::unix_time_to_windows_time( return utils::time::unix_time_to_windows_time(
utils::string::to_uint64(meta.at(META_CREATION))); utils::string::to_uint64(meta.at(META_MODIFIED)));
} }
auto get_written_time_from_meta(const api_meta_map &meta) -> std::uint64_t { auto get_written_time_from_meta(const api_meta_map &meta) -> std::uint64_t {
@@ -119,7 +119,7 @@ auto unix_access_mask_to_windows(std::int32_t mask) -> int {
return mask & 6; return mask & 6;
} }
auto unix_open_flags_to_flags_and_perms(remote::file_mode /*mode*/, auto unix_open_flags_to_flags_and_perms(remote::file_mode /*mode*/,
const remote::open_flags &flags, const remote::open_flags &flags,
std::int32_t &perms) -> int { std::int32_t &perms) -> int {
auto ret = _O_BINARY | _O_RANDOM; auto ret = _O_BINARY | _O_RANDOM;

View File

@@ -220,9 +220,9 @@ protected:
static void create_directory(const std::string &api_path) { static void create_directory(const std::string &api_path) {
auto date = utils::time::get_time_now(); auto date = utils::time::get_time_now();
auto meta = create_meta_attributes( auto meta = create_meta_attributes(date, 1U, date + 1U, date + 2U, true,
date, 1U, date + 1U, date + 2U, true, getgid(), "", 0700, date + 3U, 2U, getgid(), "", 0700, date + 3U, 2U, 3U,
3U, 0U, api_path + "_src", getuid(), date + 4U); api_path + "_src", getuid(), date + 4U);
EXPECT_EQ(api_error::success, provider->create_directory(api_path, meta)); EXPECT_EQ(api_error::success, provider->create_directory(api_path, meta));
bool exists{}; bool exists{};
@@ -256,7 +256,7 @@ protected:
auto date = utils::time::get_time_now(); auto date = utils::time::get_time_now();
auto meta = create_meta_attributes(date, 1U, date + 1U, date + 2U, false, auto meta = create_meta_attributes(date, 1U, date + 1U, date + 2U, false,
getgid(), "", 0700, date + 3U, 2U, 3U, getgid(), "", 0700, date + 3U, 2U, 3U,
0U, source_path, getuid(), date + 4U); source_path, getuid(), date + 4U);
EXPECT_EQ(api_error::success, provider->create_file(api_path, meta)); EXPECT_EQ(api_error::success, provider->create_file(api_path, meta));
bool exists{}; bool exists{};

View File

@@ -158,7 +158,8 @@ public:
for (const auto &[key, value] : meta) { for (const auto &[key, value] : meta) {
meta_[api_path][key] = value; meta_[api_path][key] = value;
} }
}; }
};
} // namespace repertory } // namespace repertory
#endif // !defined(_WIN32) #endif // !defined(_WIN32)

View File

@@ -60,7 +60,7 @@ public:
{META_MODIFIED, std::to_string(utils::time::get_time_now())}, {META_MODIFIED, std::to_string(utils::time::get_time_now())},
{META_WRITTEN, std::to_string(utils::time::get_time_now())}, {META_WRITTEN, std::to_string(utils::time::get_time_now())},
{META_ACCESSED, std::to_string(utils::time::get_time_now())}, {META_ACCESSED, std::to_string(utils::time::get_time_now())},
{META_CREATION, std::to_string(utils::time::get_time_now())}}; {META_CHANGED, std::to_string(utils::time::get_time_now())}};
list.emplace_back(di); list.emplace_back(di);
di.api_path = ".."; di.api_path = "..";

View File

@@ -156,7 +156,7 @@ TEST_F(file_manager_test, can_create_and_close_file) {
auto now = utils::time::get_time_now(); auto now = utils::time::get_time_now();
auto meta = create_meta_attributes(now, FILE_ATTRIBUTE_ARCHIVE, now + 1U, auto meta = create_meta_attributes(now, FILE_ATTRIBUTE_ARCHIVE, now + 1U,
now + 2U, false, 1, "key", 2, now + 3U, now + 2U, false, 1, "key", 2, now + 3U,
3U, 4U, 0U, source_path, 10U, now + 4U); 3U, 4U, source_path, 10U, now + 4U);
EXPECT_CALL(mp, create_file("/test_create.txt", meta)) EXPECT_CALL(mp, create_file("/test_create.txt", meta))
.WillOnce(Return(api_error::success)); .WillOnce(Return(api_error::success));
@@ -261,7 +261,7 @@ TEST_F(file_manager_test, can_open_and_close_file) {
auto now = utils::time::get_time_now(); auto now = utils::time::get_time_now();
auto meta = create_meta_attributes(now, FILE_ATTRIBUTE_ARCHIVE, now + 1U, auto meta = create_meta_attributes(now, FILE_ATTRIBUTE_ARCHIVE, now + 1U,
now + 2U, false, 1U, "key", 2U, now + 3U, now + 2U, false, 1U, "key", 2U, now + 3U,
3U, 4U, 0U, source_path, 10U, now + 4U); 3U, 4U, source_path, 10U, now + 4U);
EXPECT_CALL(mp, create_file).Times(0U); EXPECT_CALL(mp, create_file).Times(0U);
@@ -356,7 +356,7 @@ TEST_F(file_manager_test, can_open_and_close_multiple_handles_for_same_file) {
auto now = utils::time::get_time_now(); auto now = utils::time::get_time_now();
auto meta = create_meta_attributes(now, FILE_ATTRIBUTE_ARCHIVE, now + 1U, auto meta = create_meta_attributes(now, FILE_ATTRIBUTE_ARCHIVE, now + 1U,
now + 2U, false, 1U, "key", 2U, now + 3U, now + 2U, false, 1U, "key", 2U, now + 3U,
3U, 4U, 0U, source_path, 10U, now + 4U); 3U, 4U, source_path, 10U, now + 4U);
EXPECT_CALL(mp, create_file).Times(0U); EXPECT_CALL(mp, create_file).Times(0U);
@@ -432,7 +432,7 @@ TEST_F(file_manager_test,
auto now = utils::time::get_time_now(); auto now = utils::time::get_time_now();
auto meta = create_meta_attributes( auto meta = create_meta_attributes(
now, FILE_ATTRIBUTE_ARCHIVE, now + 1U, now + 2U, false, 1U, "key", 2U, now, FILE_ATTRIBUTE_ARCHIVE, now + 1U, now + 2U, false, 1U, "key", 2U,
now + 3U, 3U, 4U, now + 3U, 3U,
utils::encryption::encrypting_reader::get_data_chunk_size() * 4U, utils::encryption::encrypting_reader::get_data_chunk_size() * 4U,
source_path, 10U, now + 4U); source_path, 10U, now + 4U);
auto &file = auto &file =
@@ -586,8 +586,8 @@ TEST_F(file_manager_test, upload_occurs_after_write_if_fully_downloaded) {
auto now = utils::time::get_time_now(); auto now = utils::time::get_time_now();
auto meta = create_meta_attributes( auto meta = create_meta_attributes(
now, FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u, false, 1, "key", 2, now, FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2U, false, 1, "key", 2,
now + 3u, 3u, 4u, now + 3u, 3u,
utils::encryption::encrypting_reader::get_data_chunk_size() * 4u, utils::encryption::encrypting_reader::get_data_chunk_size() * 4u,
source_path, 10, now + 4u); source_path, 10, now + 4u);
auto &file = auto &file =
@@ -697,8 +697,8 @@ TEST_F(file_manager_test, can_evict_file) {
auto now = utils::time::get_time_now(); auto now = utils::time::get_time_now();
auto meta = create_meta_attributes(now, FILE_ATTRIBUTE_ARCHIVE, now + 1u, auto meta = create_meta_attributes(now, FILE_ATTRIBUTE_ARCHIVE, now + 1u,
now + 2u, false, 1, "key", 2, now + 3u, 3u, now + 2U, false, 1, "key", 2, now + 3u, 3u,
4u, 0u, source_path, 10, now + 4u); 4u, source_path, 10, now + 4u);
std::uint64_t handle{}; std::uint64_t handle{};
{ {
std::shared_ptr<i_open_file> open_file; std::shared_ptr<i_open_file> open_file;
@@ -890,8 +890,8 @@ TEST_F(file_manager_test, evict_file_fails_if_file_is_uploading) {
auto now = utils::time::get_time_now(); auto now = utils::time::get_time_now();
auto meta = create_meta_attributes(now, FILE_ATTRIBUTE_ARCHIVE, now + 1u, auto meta = create_meta_attributes(now, FILE_ATTRIBUTE_ARCHIVE, now + 1u,
now + 2u, false, 1, "", 2, now + 3u, 3u, now + 2U, false, 1, "", 2, now + 3u, 3u,
4u, 0u, source_path, 10, now + 4u); 4u, source_path, 10, now + 4u);
std::uint64_t handle{}; std::uint64_t handle{};
{ {
std::shared_ptr<i_open_file> open_file; std::shared_ptr<i_open_file> open_file;
@@ -1086,8 +1086,8 @@ TEST_F(file_manager_test, file_is_not_opened_if_provider_create_file_fails) {
auto now = utils::time::get_time_now(); auto now = utils::time::get_time_now();
auto meta = create_meta_attributes(now, FILE_ATTRIBUTE_ARCHIVE, now + 1u, auto meta = create_meta_attributes(now, FILE_ATTRIBUTE_ARCHIVE, now + 1u,
now + 2u, false, 1, "", 2, now + 3u, 3u, now + 2U, false, 1, "", 2, now + 3u, 3u,
4u, 0u, "/test_create.src", 10, now + 4u); 4u, "/test_create.src", 10, now + 4u);
file_manager mgr(*cfg, mp); file_manager mgr(*cfg, mp);
EXPECT_CALL(mp, create_file("/test_create.txt", meta)) EXPECT_CALL(mp, create_file("/test_create.txt", meta))
@@ -1421,6 +1421,7 @@ TEST_F(file_manager_test, can_remove_file) {
.key = "", .key = "",
.modified_date = 0, .modified_date = 0,
.source_path = "", .source_path = "",
.written_date = 0,
}; };
EXPECT_CALL(mp, get_item_meta(_, _)) EXPECT_CALL(mp, get_item_meta(_, _))
@@ -1499,8 +1500,8 @@ TEST_F(file_manager_test, file_is_closed_after_download_timeout) {
auto now = utils::time::get_time_now(); auto now = utils::time::get_time_now();
auto meta = create_meta_attributes( auto meta = create_meta_attributes(
now, FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u, false, 1, "key", 2, now, FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2U, false, 1, "key", 2,
now + 3u, 3u, 4u, now + 3u, 3u,
utils::encryption::encrypting_reader::get_data_chunk_size() * 4u, utils::encryption::encrypting_reader::get_data_chunk_size() * 4u,
source_path, 10, now + 4u); source_path, 10, now + 4u);
@@ -1657,7 +1658,7 @@ TEST_F(file_manager_test,
auto now = utils::time::get_time_now(); auto now = utils::time::get_time_now();
auto meta = create_meta_attributes(now, FILE_ATTRIBUTE_ARCHIVE, now + 1U, auto meta = create_meta_attributes(now, FILE_ATTRIBUTE_ARCHIVE, now + 1U,
now + 2U, false, 1U, "key", 2, now + 3U, now + 2U, false, 1U, "key", 2, now + 3U,
3U, 4U, 0U, source_path, 10U, now + 4U); 3U, 4U, source_path, 10U, now + 4U);
EXPECT_CALL(mp, create_file("/test_create.txt", meta)) EXPECT_CALL(mp, create_file("/test_create.txt", meta))
.WillOnce(Return(api_error::success)); .WillOnce(Return(api_error::success));

View File

@@ -613,8 +613,6 @@ TYPED_TEST(providers_test, get_file) {
file.accessed_date); file.accessed_date);
EXPECT_LT(utils::time::get_time_now() - (utils::time::NANOS_PER_SECOND * 5U), EXPECT_LT(utils::time::get_time_now() - (utils::time::NANOS_PER_SECOND * 5U),
file.changed_date); file.changed_date);
EXPECT_LT(utils::time::get_time_now() - (utils::time::NANOS_PER_SECOND * 5U),
file.creation_date);
EXPECT_LT(utils::time::get_time_now() - (utils::time::NANOS_PER_SECOND * 5U), EXPECT_LT(utils::time::get_time_now() - (utils::time::NANOS_PER_SECOND * 5U),
file.modified_date); file.modified_date);

View File

@@ -30,6 +30,7 @@
namespace repertory::utils::file { namespace repertory::utils::file {
enum class time_type { enum class time_type {
accessed, accessed,
changed,
created, created,
modified, modified,
written, written,
@@ -37,6 +38,7 @@ enum class time_type {
struct file_times final { struct file_times final {
std::uint64_t accessed{}; std::uint64_t accessed{};
std::uint64_t changed{};
std::uint64_t created{}; std::uint64_t created{};
std::uint64_t modified{}; std::uint64_t modified{};
std::uint64_t written{}; std::uint64_t written{};
@@ -47,6 +49,8 @@ struct file_times final {
switch (type) { switch (type) {
case time_type::accessed: case time_type::accessed:
return accessed; return accessed;
case time_type::changed:
return changed;
case time_type::created: case time_type::created:
return created; return created;
case time_type::modified: case time_type::modified:
@@ -70,8 +74,8 @@ struct i_fs_item {
[[nodiscard]] virtual auto copy_to(std::string_view to_path, [[nodiscard]] virtual auto copy_to(std::string_view to_path,
bool overwrite) const -> bool = 0; bool overwrite) const -> bool = 0;
[[nodiscard]] virtual auto copy_to(std::wstring_view new_path, [[nodiscard]] virtual auto copy_to(std::wstring_view new_path, bool overwrite)
bool overwrite) -> bool { -> bool {
return copy_to(utils::string::to_utf8(new_path), overwrite); return copy_to(utils::string::to_utf8(new_path), overwrite);
} }
@@ -79,8 +83,8 @@ struct i_fs_item {
[[nodiscard]] virtual auto get_path() const -> std::string = 0; [[nodiscard]] virtual auto get_path() const -> std::string = 0;
[[nodiscard]] virtual auto [[nodiscard]] virtual auto get_time(time_type type) const
get_time(time_type type) const -> std::optional<std::uint64_t>; -> std::optional<std::uint64_t>;
[[nodiscard]] virtual auto is_directory_item() const -> bool = 0; [[nodiscard]] virtual auto is_directory_item() const -> bool = 0;

View File

@@ -209,7 +209,9 @@ auto get_times(std::string_view path) -> std::optional<file_times> {
if (res) { if (res) {
ret.accessed = ret.accessed =
utils::time::windows_file_time_to_unix_time(times.at(1U)); utils::time::windows_file_time_to_unix_time(times.at(1U));
ret.created = utils::time::windows_file_time_to_unix_time(times.at(0U)); ret.changed = utils::time::windows_file_time_to_unix_time(times.at(2U));
ret.created = =
utils::time::windows_file_time_to_unix_time(times.at(0U));
ret.modified = ret.modified =
utils::time::windows_file_time_to_unix_time(times.at(2U)); utils::time::windows_file_time_to_unix_time(times.at(2U));
ret.written = utils::time::windows_file_time_to_unix_time(times.at(2U)); ret.written = utils::time::windows_file_time_to_unix_time(times.at(2U));
@@ -228,6 +230,7 @@ auto get_times(std::string_view path) -> std::optional<file_times> {
} }
ret.accessed = utils::time::windows_time_t_to_unix_time(u_stat.st_atime); ret.accessed = utils::time::windows_time_t_to_unix_time(u_stat.st_atime);
ret.changed = utils::time::windows_time_t_to_unix_time(u_stat.st_ctime);
ret.created = utils::time::windows_time_t_to_unix_time(u_stat.st_ctime); ret.created = utils::time::windows_time_t_to_unix_time(u_stat.st_ctime);
ret.modified = utils::time::windows_time_t_to_unix_time(u_stat.st_mtime); ret.modified = utils::time::windows_time_t_to_unix_time(u_stat.st_mtime);
ret.written = utils::time::windows_time_t_to_unix_time(u_stat.st_mtime); ret.written = utils::time::windows_time_t_to_unix_time(u_stat.st_mtime);
@@ -246,7 +249,10 @@ auto get_times(std::string_view path) -> std::optional<file_times> {
ret.accessed = static_cast<std::uint64_t>(u_stat.st_atimespec.tv_nsec) + ret.accessed = static_cast<std::uint64_t>(u_stat.st_atimespec.tv_nsec) +
static_cast<std::uint64_t>(u_stat.st_atimespec.tv_sec) * static_cast<std::uint64_t>(u_stat.st_atimespec.tv_sec) *
utils::time::NANOS_PER_SECOND; utils::time::NANOS_PER_SECOND;
ret.created = static_cast<std::uint64_t>(u_stat.st_ctimespec.tv_nsec) + ret.created = static_cast<std::uint64_t>(u_stat.st_birthtimespec.tv_nsec) +
static_cast<std::uint64_t>(u_stat.st_birthtimespec.tv_sec) *
utils::time::NANOS_PER_SECOND;
ret.changed = static_cast<std::uint64_t>(u_stat.st_ctimespec.tv_nsec) +
static_cast<std::uint64_t>(u_stat.st_ctimespec.tv_sec) * static_cast<std::uint64_t>(u_stat.st_ctimespec.tv_sec) *
utils::time::NANOS_PER_SECOND; utils::time::NANOS_PER_SECOND;
ret.modified = static_cast<std::uint64_t>(u_stat.st_mtimespec.tv_nsec) + ret.modified = static_cast<std::uint64_t>(u_stat.st_mtimespec.tv_nsec) +
@@ -259,6 +265,9 @@ auto get_times(std::string_view path) -> std::optional<file_times> {
ret.accessed = static_cast<std::uint64_t>(u_stat.st_atim.tv_nsec) + ret.accessed = static_cast<std::uint64_t>(u_stat.st_atim.tv_nsec) +
static_cast<std::uint64_t>(u_stat.st_atim.tv_sec) * static_cast<std::uint64_t>(u_stat.st_atim.tv_sec) *
utils::time::NANOS_PER_SECOND; utils::time::NANOS_PER_SECOND;
ret.changed = static_cast<std::uint64_t>(u_stat.st_ctim.tv_nsec) +
static_cast<std::uint64_t>(u_stat.st_ctim.tv_sec) *
utils::time::NANOS_PER_SECOND;
ret.created = static_cast<std::uint64_t>(u_stat.st_ctim.tv_nsec) + ret.created = static_cast<std::uint64_t>(u_stat.st_ctim.tv_nsec) +
static_cast<std::uint64_t>(u_stat.st_ctim.tv_sec) * static_cast<std::uint64_t>(u_stat.st_ctim.tv_sec) *
utils::time::NANOS_PER_SECOND; utils::time::NANOS_PER_SECOND;

View File

@@ -336,8 +336,6 @@ TEST_P(utils_encryption_read_encrypted_range_fixture, single_byte_read) {
TEST_P(utils_encryption_read_encrypted_range_fixture, TEST_P(utils_encryption_read_encrypted_range_fixture,
begin_at_exact_chunk_boundary) { begin_at_exact_chunk_boundary) {
ASSERT_NE(chunk, 0U);
auto begin = static_cast<std::uint64_t>(chunk); auto begin = static_cast<std::uint64_t>(chunk);
std::uint64_t end = begin + 1024U - 1U; std::uint64_t end = begin + 1024U - 1U;
if (end >= plain_sz) if (end >= plain_sz)

View File

@@ -510,6 +510,7 @@ TEST(utils_file, get_times) {
utils::file::get_times(test::create_random_file(1U).get_path()); utils::file::get_times(test::create_random_file(1U).get_path());
EXPECT_TRUE(times.has_value()); EXPECT_TRUE(times.has_value());
EXPECT_LT(0U, times->get(utils::file::time_type::accessed)); EXPECT_LT(0U, times->get(utils::file::time_type::accessed));
EXPECT_LT(0U, times->get(utils::file::time_type::changed));
EXPECT_LT(0U, times->get(utils::file::time_type::created)); EXPECT_LT(0U, times->get(utils::file::time_type::created));
EXPECT_LT(0U, times->get(utils::file::time_type::modified)); EXPECT_LT(0U, times->get(utils::file::time_type::modified));
EXPECT_LT(0U, times->get(utils::file::time_type::written)); EXPECT_LT(0U, times->get(utils::file::time_type::written));
@@ -520,6 +521,7 @@ TEST(utils_file, get_times) {
utils::string::from_utf8(test::create_random_file(1U).get_path())); utils::string::from_utf8(test::create_random_file(1U).get_path()));
EXPECT_TRUE(times.has_value()); EXPECT_TRUE(times.has_value());
EXPECT_LT(0U, times->get(utils::file::time_type::accessed)); EXPECT_LT(0U, times->get(utils::file::time_type::accessed));
EXPECT_LT(0U, times->get(utils::file::time_type::changed));
EXPECT_LT(0U, times->get(utils::file::time_type::created)); EXPECT_LT(0U, times->get(utils::file::time_type::created));
EXPECT_LT(0U, times->get(utils::file::time_type::modified)); EXPECT_LT(0U, times->get(utils::file::time_type::modified));
EXPECT_LT(0U, times->get(utils::file::time_type::written)); EXPECT_LT(0U, times->get(utils::file::time_type::written));
@@ -540,6 +542,11 @@ TEST(utils_file, get_time) {
EXPECT_TRUE(file_time.has_value()); EXPECT_TRUE(file_time.has_value());
EXPECT_LT(0U, file_time.value()); EXPECT_LT(0U, file_time.value());
file_time =
utils::file::get_time(file_path, utils::file::time_type::changed);
EXPECT_TRUE(file_time.has_value());
EXPECT_LT(0U, file_time.value());
file_time = file_time =
utils::file::get_time(file_path, utils::file::time_type::created); utils::file::get_time(file_path, utils::file::time_type::created);
EXPECT_TRUE(file_time.has_value()); EXPECT_TRUE(file_time.has_value());
@@ -565,6 +572,11 @@ TEST(utils_file, get_time) {
EXPECT_TRUE(file_time.has_value()); EXPECT_TRUE(file_time.has_value());
EXPECT_LT(0U, file_time.value()); EXPECT_LT(0U, file_time.value());
file_time =
utils::file::get_time(file_path, utils::file::time_type::changed);
EXPECT_TRUE(file_time.has_value());
EXPECT_LT(0U, file_time.value());
file_time = file_time =
utils::file::get_time(file_path, utils::file::time_type::created); utils::file::get_time(file_path, utils::file::time_type::created);
EXPECT_TRUE(file_time.has_value()); EXPECT_TRUE(file_time.has_value());