time fixes
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
namespace repertory::utils::file {
|
||||
enum class time_type {
|
||||
accessed,
|
||||
changed,
|
||||
created,
|
||||
modified,
|
||||
written,
|
||||
@@ -37,6 +38,7 @@ enum class time_type {
|
||||
|
||||
struct file_times final {
|
||||
std::uint64_t accessed{};
|
||||
std::uint64_t changed{};
|
||||
std::uint64_t created{};
|
||||
std::uint64_t modified{};
|
||||
std::uint64_t written{};
|
||||
@@ -47,6 +49,8 @@ struct file_times final {
|
||||
switch (type) {
|
||||
case time_type::accessed:
|
||||
return accessed;
|
||||
case time_type::changed:
|
||||
return changed;
|
||||
case time_type::created:
|
||||
return created;
|
||||
case time_type::modified:
|
||||
@@ -70,8 +74,8 @@ struct i_fs_item {
|
||||
[[nodiscard]] virtual auto copy_to(std::string_view to_path,
|
||||
bool overwrite) const -> bool = 0;
|
||||
|
||||
[[nodiscard]] virtual auto copy_to(std::wstring_view new_path,
|
||||
bool overwrite) -> bool {
|
||||
[[nodiscard]] virtual auto copy_to(std::wstring_view new_path, bool overwrite)
|
||||
-> bool {
|
||||
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_time(time_type type) const -> std::optional<std::uint64_t>;
|
||||
[[nodiscard]] virtual auto get_time(time_type type) const
|
||||
-> std::optional<std::uint64_t>;
|
||||
|
||||
[[nodiscard]] virtual auto is_directory_item() const -> bool = 0;
|
||||
|
||||
|
||||
@@ -209,7 +209,9 @@ auto get_times(std::string_view path) -> std::optional<file_times> {
|
||||
if (res) {
|
||||
ret.accessed =
|
||||
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 =
|
||||
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.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.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);
|
||||
@@ -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) +
|
||||
static_cast<std::uint64_t>(u_stat.st_atimespec.tv_sec) *
|
||||
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) *
|
||||
utils::time::NANOS_PER_SECOND;
|
||||
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) +
|
||||
static_cast<std::uint64_t>(u_stat.st_atim.tv_sec) *
|
||||
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) +
|
||||
static_cast<std::uint64_t>(u_stat.st_ctim.tv_sec) *
|
||||
utils::time::NANOS_PER_SECOND;
|
||||
|
||||
@@ -336,8 +336,6 @@ TEST_P(utils_encryption_read_encrypted_range_fixture, single_byte_read) {
|
||||
|
||||
TEST_P(utils_encryption_read_encrypted_range_fixture,
|
||||
begin_at_exact_chunk_boundary) {
|
||||
ASSERT_NE(chunk, 0U);
|
||||
|
||||
auto begin = static_cast<std::uint64_t>(chunk);
|
||||
std::uint64_t end = begin + 1024U - 1U;
|
||||
if (end >= plain_sz)
|
||||
|
||||
@@ -510,6 +510,7 @@ TEST(utils_file, get_times) {
|
||||
utils::file::get_times(test::create_random_file(1U).get_path());
|
||||
EXPECT_TRUE(times.has_value());
|
||||
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::modified));
|
||||
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()));
|
||||
EXPECT_TRUE(times.has_value());
|
||||
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::modified));
|
||||
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_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 =
|
||||
utils::file::get_time(file_path, utils::file::time_type::created);
|
||||
EXPECT_TRUE(file_time.has_value());
|
||||
@@ -565,6 +572,11 @@ TEST(utils_file, get_time) {
|
||||
EXPECT_TRUE(file_time.has_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 =
|
||||
utils::file::get_time(file_path, utils::file::time_type::created);
|
||||
EXPECT_TRUE(file_time.has_value());
|
||||
|
||||
Reference in New Issue
Block a user