From 776862d47407da1db2239b2d7835d3fcf175f43e Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Fri, 23 Aug 2024 14:12:02 -0500 Subject: [PATCH] updated build system --- repertory/librepertory/include/common.hpp | 2 - .../librepertory/include/types/remote.hpp | 127 +++++++++--------- repertory/librepertory/include/types/s3.hpp | 4 +- .../librepertory/include/utils/file_utils.hpp | 8 +- .../librepertory/src/comm/packet/packet.cpp | 10 +- .../librepertory/src/drives/eviction.cpp | 33 ++--- .../fuse/remotefuse/remote_fuse_drive.cpp | 108 ++++++++------- .../drives/fuse/remotefuse/remote_server.cpp | 61 +++++---- .../winfsp/remotewinfsp/remote_server.cpp | 4 +- .../providers/encrypt/encrypt_provider.cpp | 27 ++-- .../librepertory/src/utils/file_utils.cpp | 78 ++--------- .../repertory_test/src/remote_fuse_test.cpp | 18 +-- 12 files changed, 220 insertions(+), 260 deletions(-) diff --git a/repertory/librepertory/include/common.hpp b/repertory/librepertory/include/common.hpp index da1530db..5ac2c3e8 100644 --- a/repertory/librepertory/include/common.hpp +++ b/repertory/librepertory/include/common.hpp @@ -63,8 +63,6 @@ inline constexpr const std::string_view REPERTORY_MIN_REMOTE_VERSION = "2.0.0"; #define REPERTORY_INVALID_HANDLE INVALID_HANDLE_VALUE -inline constexpr const auto NANOS_PER_SECOND = 1000000000L; - #define WINFSP_ALLOCATION_UNIT UINT64(4096U) #if defined(_WIN32) diff --git a/repertory/librepertory/include/types/remote.hpp b/repertory/librepertory/include/types/remote.hpp index 627252f0..8f37a87f 100644 --- a/repertory/librepertory/include/types/remote.hpp +++ b/repertory/librepertory/include/types/remote.hpp @@ -22,14 +22,14 @@ #ifndef INCLUDE_TYPES_REMOTE_HPP_ #define INCLUDE_TYPES_REMOTE_HPP_ -#define PACKET_SERVICE_FUSE 1U -#define PACKET_SERVICE_WINFSP 2U +inline constexpr const auto PACKET_SERVICE_FUSE{1U}; +inline constexpr const auto PACKET_SERVICE_WINFSP{2U}; #if defined(_WIN32) -#define PACKET_SERVICE_FLAGS PACKET_SERVICE_WINFSP -#else -#define PACKET_SERVICE_FLAGS PACKET_SERVICE_FUSE -#endif +inline constexpr const auto PACKET_SERVICE_FLAGS{PACKET_SERVICE_WINFSP}; +#else // !defined(_WIN32) +inline constexpr const auto PACKET_SERVICE_FLAGS{PACKET_SERVICE_FUSE}; +#endif // defined(_WIN32) namespace repertory::remote { using block_count = std::uint64_t; @@ -65,16 +65,19 @@ enum class open_flags : std::uint32_t { dsync = 131072U, }; -inline auto operator|(const open_flags &flag_1, - const open_flags &flag_2) -> open_flags { - using t = std::underlying_type_t; - return static_cast(static_cast(flag_1) | - static_cast(flag_2)); +#if defined(__GNUG__) +__attribute__((unused)) +#endif // defined(__GNUG__) +[[nodiscard]] inline auto +operator|(const open_flags &flag_1, const open_flags &flag_2) -> open_flags { + using flag_t = std::underlying_type_t; + return static_cast(static_cast(flag_1) | + static_cast(flag_2)); } #if defined(__GNUG__) __attribute__((unused)) -#endif +#endif // defined(__GNUG__) inline auto operator|=(open_flags &flag_1, const open_flags &flag_2) -> open_flags & { flag_1 = flag_1 | flag_2; @@ -83,69 +86,69 @@ operator|=(open_flags &flag_1, const open_flags &flag_2) -> open_flags & { #if defined(__GNUG__) __attribute__((unused)) -#endif -inline auto +#endif // defined(__GNUG__) +[[nodiscard]] inline auto operator&(const open_flags &flag_1, const open_flags &flag_2) -> open_flags { - using t = std::underlying_type_t; - return static_cast(static_cast(flag_1) & - static_cast(flag_2)); + using flag_t = std::underlying_type_t; + return static_cast(static_cast(flag_1) & + static_cast(flag_2)); } #pragma pack(1) -struct file_info { - UINT32 FileAttributes; - UINT32 ReparseTag; - UINT64 AllocationSize; - UINT64 FileSize; - UINT64 CreationTime; - UINT64 LastAccessTime; - UINT64 LastWriteTime; - UINT64 ChangeTime; - UINT64 IndexNumber; - UINT32 HardLinks; - UINT32 EaSize; +struct file_info final { + UINT32 FileAttributes{}; + UINT32 ReparseTag{}; + UINT64 AllocationSize{}; + UINT64 FileSize{}; + UINT64 CreationTime{}; + UINT64 LastAccessTime{}; + UINT64 LastWriteTime{}; + UINT64 ChangeTime{}; + UINT64 IndexNumber{}; + UINT32 HardLinks{}; + UINT32 EaSize{}; }; -struct setattr_x { - std::int32_t valid; - file_mode mode; - user_id uid; - group_id gid; - file_size size; - file_time acctime; - file_time modtime; - file_time crtime; - file_time chgtime; - file_time bkuptime; - std::uint32_t flags; +struct setattr_x final { + std::int32_t valid{}; + file_mode mode{}; + user_id uid{}; + group_id gid{}; + file_size size{}; + file_time acctime{}; + file_time modtime{}; + file_time crtime{}; + file_time chgtime{}; + file_time bkuptime{}; + std::uint32_t flags{}; }; -struct stat { - file_mode st_mode; - file_nlink st_nlink; - user_id st_uid; - group_id st_gid; - file_time st_atimespec; - file_time st_mtimespec; - file_time st_ctimespec; - file_time st_birthtimespec; - file_size st_size; - block_count st_blocks; - block_size st_blksize; - std::uint32_t st_flags; +struct stat final { + file_mode st_mode{}; + file_nlink st_nlink{}; + user_id st_uid{}; + group_id st_gid{}; + file_time st_atimespec{}; + file_time st_mtimespec{}; + file_time st_ctimespec{}; + file_time st_birthtimespec{}; + file_size st_size{}; + block_count st_blocks{}; + block_size st_blksize{}; + std::uint32_t st_flags{}; }; struct statfs { - std::uint64_t f_bavail; - std::uint64_t f_bfree; - std::uint64_t f_blocks; - std::uint64_t f_favail; - std::uint64_t f_ffree; - std::uint64_t f_files; + std::uint64_t f_bavail{}; + std::uint64_t f_bfree{}; + std::uint64_t f_blocks{}; + std::uint64_t f_favail{}; + std::uint64_t f_ffree{}; + std::uint64_t f_files{}; }; struct statfs_x : public statfs { - char f_mntfromname[1024]; + std::array f_mntfromname{}; }; #pragma pack() @@ -154,7 +157,7 @@ struct statfs_x : public statfs { [[nodiscard]] auto create_os_open_flags(const open_flags &flags) -> std::uint32_t; -#endif +#endif // !defined(_WIN32) } // namespace repertory::remote #endif // INCLUDE_TYPES_REMOTE_HPP_ diff --git a/repertory/librepertory/include/types/s3.hpp b/repertory/librepertory/include/types/s3.hpp index 20bf1928..6ac87c98 100644 --- a/repertory/librepertory/include/types/s3.hpp +++ b/repertory/librepertory/include/types/s3.hpp @@ -79,8 +79,8 @@ struct head_object_result { #else strptime(date.c_str(), "%a, %d %b %Y %H:%M:%S %Z", &tm1); #endif - last_modified = - static_cast(mktime(&tm1)) * NANOS_PER_SECOND; + last_modified = static_cast(mktime(&tm1)) * + utils::time::NANOS_PER_SECOND; } return *this; } diff --git a/repertory/librepertory/include/utils/file_utils.hpp b/repertory/librepertory/include/utils/file_utils.hpp index a642ac9a..a2e183b2 100644 --- a/repertory/librepertory/include/utils/file_utils.hpp +++ b/repertory/librepertory/include/utils/file_utils.hpp @@ -34,9 +34,6 @@ void change_to_process_directory(); [[nodiscard]] auto copy_file(std::string from_path, std::string to_path) -> bool; -[[nodiscard]] auto get_accessed_time(const std::string &path, - std::uint64_t &accessed) -> bool; - [[nodiscard]] auto get_directory_files(std::string path, bool oldest_first, bool recursive = false) -> std::deque; @@ -47,11 +44,8 @@ get_free_drive_space(const std::string &path) -> std::uint64_t; [[nodiscard]] auto get_total_drive_space(const std::string &path) -> std::uint64_t; -[[nodiscard]] auto get_modified_time(const std::string &path, - std::uint64_t &modified) -> bool; - [[nodiscard]] auto -is_modified_date_older_than(const std::string &path, +is_modified_date_older_than(std::string_view path, const std::chrono::hours &hours) -> bool; [[nodiscard]] auto move_file(std::string from, std::string to) -> bool; diff --git a/repertory/librepertory/src/comm/packet/packet.cpp b/repertory/librepertory/src/comm/packet/packet.cpp index ecab6c9b..a08cfa14 100644 --- a/repertory/librepertory/src/comm/packet/packet.cpp +++ b/repertory/librepertory/src/comm/packet/packet.cpp @@ -194,7 +194,7 @@ auto packet::decode(remote::statfs &val) -> packet::error_type { auto packet::decode(remote::statfs_x &val) -> packet::error_type { auto ret = decode(*dynamic_cast(&val)); if (ret == 0) { - ret = decode(&val.f_mntfromname[0U], sizeof(val.f_mntfromname)); + ret = decode(val.f_mntfromname.data(), val.f_mntfromname.size()); } return ret; } @@ -372,9 +372,9 @@ void packet::encode(remote::statfs val, bool should_reserve) { void packet::encode(remote::statfs_x val) { buffer_.reserve(buffer_.size() + sizeof(remote::statfs) + - sizeof(val.f_mntfromname)); + val.f_mntfromname.size()); encode(*dynamic_cast(&val), false); - encode(&val.f_mntfromname[0], sizeof(val.f_mntfromname), false); + encode(val.f_mntfromname.data(), val.f_mntfromname.size(), false); } void packet::encode(remote::file_info val) { @@ -501,8 +501,8 @@ void packet::encode_top(remote::statfs val, bool should_reserve) { void packet::encode_top(remote::statfs_x val) { buffer_.reserve(buffer_.size() + sizeof(remote::statfs) + - sizeof(val.f_mntfromname)); - encode_top(&val.f_mntfromname[0], sizeof(val.f_mntfromname), false); + val.f_mntfromname.size()); + encode_top(val.f_mntfromname.data(), val.f_mntfromname.size(), false); encode_top(*dynamic_cast(&val), false); } diff --git a/repertory/librepertory/src/drives/eviction.cpp b/repertory/librepertory/src/drives/eviction.cpp index 05f79240..e8ea97b0 100644 --- a/repertory/librepertory/src/drives/eviction.cpp +++ b/repertory/librepertory/src/drives/eviction.cpp @@ -46,30 +46,19 @@ auto eviction::check_minimum_requirements(const std::string &file_path) } auto file_size{opt_size.value()}; - auto ret{false}; - if (file_size != 0U) { - std::uint64_t reference_time{}; - ret = config_.get_eviction_uses_accessed_time() - ? utils::file::get_accessed_time(file_path, reference_time) - : utils::file::get_modified_time(file_path, reference_time); - if (ret) { -#if defined(_WIN32) - const auto now = std::chrono::system_clock::now(); - const auto delay = - std::chrono::minutes(config_.get_eviction_delay_mins()); - ret = ((std::chrono::system_clock::from_time_t( - static_cast(reference_time)) + - delay) <= now); -#else - const auto now = utils::time::get_time_now(); - const auto delay = - (config_.get_eviction_delay_mins() * 60L) * NANOS_PER_SECOND; - ret = ((reference_time + static_cast(delay)) <= now); -#endif - } + if (file_size == 0U) { + return false; } - return ret; + auto reference_time = utils::file::file{file_path}.get_time( + config_.get_eviction_uses_accessed_time() + ? utils::file::file::time_types::access + : utils::file::file::time_types::modified); + + auto delay = (config_.get_eviction_delay_mins() * 60UL) * + utils::time::NANOS_PER_SECOND; + return ((reference_time + static_cast(delay)) <= + utils::time::get_time_now()); } auto eviction::get_filtered_cached_files() -> std::deque { diff --git a/repertory/librepertory/src/drives/fuse/remotefuse/remote_fuse_drive.cpp b/repertory/librepertory/src/drives/fuse/remotefuse/remote_fuse_drive.cpp index e54ee2d5..9d7b393e 100644 --- a/repertory/librepertory/src/drives/fuse/remotefuse/remote_fuse_drive.cpp +++ b/repertory/librepertory/src/drives/fuse/remotefuse/remote_fuse_drive.cpp @@ -36,6 +36,7 @@ #include "utils/error_utils.hpp" #include "utils/file_utils.hpp" #include "utils/path.hpp" +#include "utils/time.hpp" #include "utils/utils.hpp" namespace repertory::remote_fuse { @@ -142,16 +143,17 @@ api_error remote_fuse_drive::fsetattr_x_impl(std::string api_path, attributes.uid = attr->uid; attributes.gid = attr->gid; attributes.size = attr->size; - attributes.acctime = - ((attr->acctime.tv_sec * NANOS_PER_SECOND) + attr->acctime.tv_nsec); - attributes.modtime = - ((attr->modtime.tv_sec * NANOS_PER_SECOND) + attr->modtime.tv_nsec); - attributes.crtime = - ((attr->crtime.tv_sec * NANOS_PER_SECOND) + attr->crtime.tv_nsec); - attributes.chgtime = - ((attr->chgtime.tv_sec * NANOS_PER_SECOND) + attr->chgtime.tv_nsec); + attributes.acctime = ((attr->acctime.tv_sec * utils::time::NANOS_PER_SECOND) + + attr->acctime.tv_nsec); + attributes.modtime = ((attr->modtime.tv_sec * utils::time::NANOS_PER_SECOND) + + attr->modtime.tv_nsec); + attributes.crtime = ((attr->crtime.tv_sec * utils::time::NANOS_PER_SECOND) + + attr->crtime.tv_nsec); + attributes.chgtime = ((attr->chgtime.tv_sec * utils::time::NANOS_PER_SECOND) + + attr->chgtime.tv_nsec); attributes.bkuptime = - ((attr->bkuptime.tv_sec * NANOS_PER_SECOND) + attr->bkuptime.tv_nsec); + ((attr->bkuptime.tv_sec * utils::time::NANOS_PER_SECOND) + + attr->bkuptime.tv_nsec); attributes.flags = attr->flags; return utils::to_api_error(remote_instance_->fuse_fsetattr_x( api_path.c_str(), attributes, f_info->fh)); @@ -208,10 +210,11 @@ api_error remote_fuse_drive::getxtimes_impl(std::string api_path, api_path.c_str(), repertory_bkuptime, repertory_crtime); if (res == 0) { bkuptime->tv_nsec = - static_cast(repertory_bkuptime % NANOS_PER_SECOND); - bkuptime->tv_sec = repertory_bkuptime / NANOS_PER_SECOND; - crtime->tv_nsec = static_cast(repertory_crtime % NANOS_PER_SECOND); - crtime->tv_sec = repertory_crtime / NANOS_PER_SECOND; + static_cast(repertory_bkuptime % utils::time::NANOS_PER_SECOND); + bkuptime->tv_sec = repertory_bkuptime / utils::time::NANOS_PER_SECOND; + crtime->tv_nsec = + static_cast(repertory_crtime % utils::time::NANOS_PER_SECOND); + crtime->tv_sec = repertory_crtime / utils::time::NANOS_PER_SECOND; } return utils::to_api_error(res); @@ -301,36 +304,44 @@ void remote_fuse_drive::populate_stat(const remote::stat &r_stat, #if defined(__APPLE__) unix_st.st_blksize = 0; - unix_st.st_atimespec.tv_nsec = r_stat.st_atimespec % NANOS_PER_SECOND; - unix_st.st_atimespec.tv_sec = r_stat.st_atimespec / NANOS_PER_SECOND; + unix_st.st_atimespec.tv_nsec = + r_stat.st_atimespec % utils::time::NANOS_PER_SECOND; + unix_st.st_atimespec.tv_sec = + r_stat.st_atimespec / utils::time::NANOS_PER_SECOND; - unix_st.st_birthtimespec.tv_nsec = r_stat.st_birthtimespec % NANOS_PER_SECOND; - unix_st.st_birthtimespec.tv_sec = r_stat.st_birthtimespec / NANOS_PER_SECOND; + unix_st.st_birthtimespec.tv_nsec = + r_stat.st_birthtimespec % utils::time::NANOS_PER_SECOND; + unix_st.st_birthtimespec.tv_sec = + r_stat.st_birthtimespec / utils::time::NANOS_PER_SECOND; - unix_st.st_ctimespec.tv_nsec = r_stat.st_ctimespec % NANOS_PER_SECOND; - unix_st.st_ctimespec.tv_sec = r_stat.st_ctimespec / NANOS_PER_SECOND; + unix_st.st_ctimespec.tv_nsec = + r_stat.st_ctimespec % utils::time::NANOS_PER_SECOND; + unix_st.st_ctimespec.tv_sec = + r_stat.st_ctimespec / utils::time::NANOS_PER_SECOND; - unix_st.st_mtimespec.tv_nsec = r_stat.st_mtimespec % NANOS_PER_SECOND; - unix_st.st_mtimespec.tv_sec = r_stat.st_mtimespec / NANOS_PER_SECOND; + unix_st.st_mtimespec.tv_nsec = + r_stat.st_mtimespec % utils::time::NANOS_PER_SECOND; + unix_st.st_mtimespec.tv_sec = + r_stat.st_mtimespec / utils::time::NANOS_PER_SECOND; unix_st.st_flags = r_stat.st_flags; #else // !defined(__APPLE__) unix_st.st_blksize = 4096; - unix_st.st_atim.tv_nsec = - static_cast(r_stat.st_atimespec % NANOS_PER_SECOND); - unix_st.st_atim.tv_sec = - static_cast(r_stat.st_atimespec / NANOS_PER_SECOND); + unix_st.st_atim.tv_nsec = static_cast( + r_stat.st_atimespec % utils::time::NANOS_PER_SECOND); + unix_st.st_atim.tv_sec = static_cast( + r_stat.st_atimespec / utils::time::NANOS_PER_SECOND); - unix_st.st_ctim.tv_nsec = - static_cast(r_stat.st_ctimespec % NANOS_PER_SECOND); - unix_st.st_ctim.tv_sec = - static_cast(r_stat.st_ctimespec / NANOS_PER_SECOND); + unix_st.st_ctim.tv_nsec = static_cast( + r_stat.st_ctimespec % utils::time::NANOS_PER_SECOND); + unix_st.st_ctim.tv_sec = static_cast( + r_stat.st_ctimespec / utils::time::NANOS_PER_SECOND); - unix_st.st_mtim.tv_nsec = - static_cast(r_stat.st_mtimespec % NANOS_PER_SECOND); - unix_st.st_mtim.tv_sec = - static_cast(r_stat.st_mtimespec / NANOS_PER_SECOND); + unix_st.st_mtim.tv_nsec = static_cast( + r_stat.st_mtimespec % utils::time::NANOS_PER_SECOND); + unix_st.st_mtim.tv_sec = static_cast( + r_stat.st_mtimespec / utils::time::NANOS_PER_SECOND); #endif // defined(__APPLE__) if (not directory) { @@ -441,16 +452,17 @@ api_error remote_fuse_drive::setattr_x_impl(std::string api_path, attributes.uid = attr->uid; attributes.gid = attr->gid; attributes.size = attr->size; - attributes.acctime = - ((attr->acctime.tv_sec * NANOS_PER_SECOND) + attr->acctime.tv_nsec); - attributes.modtime = - ((attr->modtime.tv_sec * NANOS_PER_SECOND) + attr->modtime.tv_nsec); - attributes.crtime = - ((attr->crtime.tv_sec * NANOS_PER_SECOND) + attr->crtime.tv_nsec); - attributes.chgtime = - ((attr->chgtime.tv_sec * NANOS_PER_SECOND) + attr->chgtime.tv_nsec); + attributes.acctime = ((attr->acctime.tv_sec * utils::time::NANOS_PER_SECOND) + + attr->acctime.tv_nsec); + attributes.modtime = ((attr->modtime.tv_sec * utils::time::NANOS_PER_SECOND) + + attr->modtime.tv_nsec); + attributes.crtime = ((attr->crtime.tv_sec * utils::time::NANOS_PER_SECOND) + + attr->crtime.tv_nsec); + attributes.chgtime = ((attr->chgtime.tv_sec * utils::time::NANOS_PER_SECOND) + + attr->chgtime.tv_nsec); attributes.bkuptime = - ((attr->bkuptime.tv_sec * NANOS_PER_SECOND) + attr->bkuptime.tv_nsec); + ((attr->bkuptime.tv_sec * utils::time::NANOS_PER_SECOND) + + attr->bkuptime.tv_nsec); attributes.flags = attr->flags; return utils::to_api_error( remote_instance_->fuse_setattr_x(api_path.c_str(), attributes)); @@ -459,7 +471,7 @@ api_error remote_fuse_drive::setattr_x_impl(std::string api_path, api_error remote_fuse_drive::setbkuptime_impl(std::string api_path, const struct timespec *bkuptime) { remote::file_time repertory_bkuptime = - ((bkuptime->tv_sec * NANOS_PER_SECOND) + bkuptime->tv_nsec); + ((bkuptime->tv_sec * utils::time::NANOS_PER_SECOND) + bkuptime->tv_nsec); return utils::to_api_error( remote_instance_->fuse_setbkuptime(api_path.c_str(), repertory_bkuptime)); } @@ -467,7 +479,7 @@ api_error remote_fuse_drive::setbkuptime_impl(std::string api_path, api_error remote_fuse_drive::setchgtime_impl(std::string api_path, const struct timespec *chgtime) { remote::file_time repertory_chgtime = - ((chgtime->tv_sec * NANOS_PER_SECOND) + chgtime->tv_nsec); + ((chgtime->tv_sec * utils::time::NANOS_PER_SECOND) + chgtime->tv_nsec); return utils::to_api_error( remote_instance_->fuse_setchgtime(api_path.c_str(), repertory_chgtime)); } @@ -475,7 +487,7 @@ api_error remote_fuse_drive::setchgtime_impl(std::string api_path, api_error remote_fuse_drive::setcrtime_impl(std::string api_path, const struct timespec *crtime) { remote::file_time repertory_crtime = - ((crtime->tv_sec * NANOS_PER_SECOND) + crtime->tv_nsec); + ((crtime->tv_sec * utils::time::NANOS_PER_SECOND) + crtime->tv_nsec); return utils::to_api_error( remote_instance_->fuse_setcrtime(api_path.c_str(), repertory_crtime)); } @@ -498,7 +510,7 @@ api_error remote_fuse_drive::statfs_x_impl(std::string api_path, stbuf->f_files = r.f_files; stbuf->f_owner = getuid(); strncpy(&stbuf->f_mntonname[0U], get_mount_location().c_str(), MNAMELEN); - strncpy(&stbuf->f_mntfromname[0U], &r.f_mntfromname[0U], MNAMELEN); + strncpy(stbuf->f_mntfromname.data(), &r.f_mntonname[0U], MNAMELEN); } } else { res = -errno; @@ -557,9 +569,9 @@ auto remote_fuse_drive::utimens_impl(std::string api_path, remote::file_time rtv[2U] = {0}; if (tv != nullptr) { rtv[0U] = static_cast( - tv[0U].tv_nsec + (tv[0U].tv_sec * NANOS_PER_SECOND)); + tv[0U].tv_nsec + (tv[0U].tv_sec * utils::time::NANOS_PER_SECOND)); rtv[1U] = static_cast( - tv[1U].tv_nsec + (tv[1U].tv_sec * NANOS_PER_SECOND)); + tv[1U].tv_nsec + (tv[1U].tv_sec * utils::time::NANOS_PER_SECOND)); } return utils::to_api_error(remote_instance_->fuse_utimens( diff --git a/repertory/librepertory/src/drives/fuse/remotefuse/remote_server.cpp b/repertory/librepertory/src/drives/fuse/remotefuse/remote_server.cpp index 0ccaf592..96bd3393 100644 --- a/repertory/librepertory/src/drives/fuse/remotefuse/remote_server.cpp +++ b/repertory/librepertory/src/drives/fuse/remotefuse/remote_server.cpp @@ -152,26 +152,33 @@ void remote_server::populate_stat(const struct stat64 &unix_st, #if defined(__APPLE__) r_stat.st_flags = unix_st.st_flags; - r_stat.st_atimespec = unix_st.st_atimespec.tv_nsec + - (unix_st.st_atimespec.tv_sec * NANOS_PER_SECOND); + r_stat.st_atimespec = + unix_st.st_atimespec.tv_nsec + + (unix_st.st_atimespec.tv_sec * utils::time::NANOS_PER_SECOND); r_stat.st_birthtimespec = unix_st.st_birthtimespec.tv_nsec + - (unix_st.st_birthtimespec.tv_sec * NANOS_PER_SECOND); - r_stat.st_ctimespec = unix_st.st_ctimespec.tv_nsec + - (unix_st.st_ctimespec.tv_sec * NANOS_PER_SECOND); - r_stat.st_mtimespec = unix_st.st_mtimespec.tv_nsec + - (unix_st.st_mtimespec.tv_sec * NANOS_PER_SECOND); + (unix_st.st_birthtimespec.tv_sec * utils::time::NANOS_PER_SECOND); + r_stat.st_ctimespec = + unix_st.st_ctimespec.tv_nsec + + (unix_st.st_ctimespec.tv_sec * utils::time::NANOS_PER_SECOND); + r_stat.st_mtimespec = + unix_st.st_mtimespec.tv_nsec + + (unix_st.st_mtimespec.tv_sec * utils::time::NANOS_PER_SECOND); #else // !defined(__APPLE__) r_stat.st_flags = 0; r_stat.st_atimespec = static_cast( - unix_st.st_atim.tv_nsec + (unix_st.st_atim.tv_sec * NANOS_PER_SECOND)); + unix_st.st_atim.tv_nsec + + (unix_st.st_atim.tv_sec * utils::time::NANOS_PER_SECOND)); r_stat.st_birthtimespec = static_cast( - unix_st.st_ctim.tv_nsec + (unix_st.st_ctim.tv_sec * NANOS_PER_SECOND)); + unix_st.st_ctim.tv_nsec + + (unix_st.st_ctim.tv_sec * utils::time::NANOS_PER_SECOND)); r_stat.st_ctimespec = static_cast( - unix_st.st_ctim.tv_nsec + (unix_st.st_ctim.tv_sec * NANOS_PER_SECOND)); + unix_st.st_ctim.tv_nsec + + (unix_st.st_ctim.tv_sec * utils::time::NANOS_PER_SECOND)); r_stat.st_mtimespec = static_cast( - unix_st.st_mtim.tv_nsec + (unix_st.st_mtim.tv_sec * NANOS_PER_SECOND)); + unix_st.st_mtim.tv_nsec + + (unix_st.st_mtim.tv_sec * utils::time::NANOS_PER_SECOND)); #endif // defined(__APPLE__) r_stat.st_blksize = static_cast(unix_st.st_blksize); r_stat.st_blocks = static_cast(unix_st.st_blocks); @@ -406,16 +413,18 @@ auto remote_server::fuse_fsetattr_x( if (SETATTR_WANTS_MODTIME(&attr)) { struct timeval val[2]; if (SETATTR_WANTS_ACCTIME(&attr)) { - val[0U].tv_sec = static_cast(attr.acctime / NANOS_PER_SECOND); - val[0U].tv_usec = - static_cast((attr.acctime % NANOS_PER_SECOND) / 1000); + val[0U].tv_sec = + static_cast(attr.acctime / utils::time::NANOS_PER_SECOND); + val[0U].tv_usec = static_cast( + (attr.acctime % utils::time::NANOS_PER_SECOND) / 1000); } else { gettimeofday(&val[0U], nullptr); } - val[1U].tv_sec = static_cast(attr.modtime / NANOS_PER_SECOND); - val[1U].tv_usec = - static_cast((attr.modtime % NANOS_PER_SECOND) / 1000); + val[1U].tv_sec = + static_cast(attr.modtime / utils::time::NANOS_PER_SECOND); + val[1U].tv_usec = static_cast( + (attr.modtime % utils::time::NANOS_PER_SECOND) / 1000); res = utimes(file_path.c_str(), &val[0U]); } @@ -950,10 +959,10 @@ auto remote_server::fuse_statfs_x(const char *path, std::uint64_t bsize, r_stat.f_blocks ? (r_stat.f_blocks - used_blocks) : 0; r_stat.f_ffree = r_stat.f_favail = r_stat.f_files - drive_.get_total_item_count(); - std::memset(&r_stat.f_mntfromname[0U], 0, sizeof(r_stat.f_mntfromname)); - strncpy(&r_stat.f_mntfromname[0U], + std::memset(r_stat.f_mntfromname.data(), 0, r_stat.f_mntfromname.data()); + strncpy(r_stat.f_mntfromname.data(), (utils::create_volume_label(config_.get_provider_type())).c_str(), - sizeof(r_stat.f_mntfromname) - 1U); + r_stat.f_mntfromname.size() - 1U); RAISE_REMOTE_FUSE_SERVER_EVENT(function_name, file_path, 0); return 0; @@ -998,16 +1007,20 @@ auto remote_server::fuse_utimens(const char *path, const remote::file_time *tv, tv2[0U].tv_nsec = static_cast(op0); tv2[0U].tv_sec = 0; } else { - tv2[0U].tv_nsec = static_cast(tv[0U] % NANOS_PER_SECOND); - tv2[0U].tv_sec = static_cast(tv[0U] / NANOS_PER_SECOND); + tv2[0U].tv_nsec = + static_cast(tv[0U] % utils::time::NANOS_PER_SECOND); + tv2[0U].tv_sec = + static_cast(tv[0U] / utils::time::NANOS_PER_SECOND); } if ((op1 == UTIME_NOW) || (op1 == UTIME_OMIT)) { tv2[1U].tv_nsec = static_cast(op1); tv2[1U].tv_sec = 0; } else { - tv2[1U].tv_nsec = static_cast(tv[1U] % NANOS_PER_SECOND); - tv2[1U].tv_sec = static_cast(tv[1U] / NANOS_PER_SECOND); + tv2[1U].tv_nsec = + static_cast(tv[1U] % utils::time::NANOS_PER_SECOND); + tv2[1U].tv_sec = + static_cast(tv[1U] / utils::time::NANOS_PER_SECOND); } const auto res = diff --git a/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_server.cpp b/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_server.cpp index 54c3ae78..3a35ce11 100644 --- a/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_server.cpp +++ b/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_server.cpp @@ -745,9 +745,9 @@ auto remote_server::fuse_statfs_x(const char *path, std::uint64_t bsize, r_stat.f_files = 4294967295; r_stat.f_ffree = r_stat.f_favail = r_stat.f_files - drive_.get_total_item_count(); - strncpy(&r_stat.f_mntfromname[0U], + strncpy(r_stat.f_mntfromname.data(), (utils::create_volume_label(config_.get_provider_type())).c_str(), - sizeof(r_stat.f_mntfromname) - 1U); + r_stat.f_mntfromname.size() - 1U); RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, 0); return 0; diff --git a/repertory/librepertory/src/providers/encrypt/encrypt_provider.cpp b/repertory/librepertory/src/providers/encrypt/encrypt_provider.cpp index 0c473c12..4f911855 100644 --- a/repertory/librepertory/src/providers/encrypt/encrypt_provider.cpp +++ b/repertory/librepertory/src/providers/encrypt/encrypt_provider.cpp @@ -90,14 +90,17 @@ auto encrypt_provider::create_api_file( source_path); file.source_path = source_path; #if defined(__APPLE__) - file.changed_date = - buf.st_ctimespec.tv_nsec + (buf.st_ctimespec.tv_sec * NANOS_PER_SECOND); + file.changed_date = buf.st_ctimespec.tv_nsec + + (buf.st_ctimespec.tv_sec * utils::time::NANOS_PER_SECOND); file.accessed_date = - buf.st_atimespec.tv_nsec + (buf.st_atimespec.tv_sec * NANOS_PER_SECOND); - file.creation_date = buf.st_birthtimespec.tv_nsec + - (buf.st_birthtimespec.tv_sec * NANOS_PER_SECOND); + buf.st_atimespec.tv_nsec + + (buf.st_atimespec.tv_sec * utils::time::NANOS_PER_SECOND); + file.creation_date = + buf.st_birthtimespec.tv_nsec + + (buf.st_birthtimespec.tv_sec * utils::time::NANOS_PER_SECOND); file.modified_date = - buf.st_mtimespec.tv_nsec + (buf.st_mtimespec.tv_sec * NANOS_PER_SECOND); + buf.st_mtimespec.tv_nsec + + (buf.st_mtimespec.tv_sec * utils::time::NANOS_PER_SECOND); #elif defined(_WIN32) file.accessed_date = utils::time::windows_time_to_unix_time( static_cast(buf.st_atime)); @@ -109,13 +112,17 @@ auto encrypt_provider::create_api_file( static_cast(buf.st_mtime)); #else // !defined(_WIN32) file.changed_date = static_cast( - buf.st_mtim.tv_nsec + (buf.st_mtim.tv_sec * NANOS_PER_SECOND)); + buf.st_mtim.tv_nsec + + (buf.st_mtim.tv_sec * utils::time::NANOS_PER_SECOND)); file.accessed_date = static_cast( - buf.st_atim.tv_nsec + (buf.st_atim.tv_sec * NANOS_PER_SECOND)); + buf.st_atim.tv_nsec + + (buf.st_atim.tv_sec * utils::time::NANOS_PER_SECOND)); file.creation_date = static_cast( - buf.st_ctim.tv_nsec + (buf.st_ctim.tv_sec * NANOS_PER_SECOND)); + buf.st_ctim.tv_nsec + + (buf.st_ctim.tv_sec * utils::time::NANOS_PER_SECOND)); file.modified_date = static_cast( - buf.st_mtim.tv_nsec + (buf.st_mtim.tv_sec * NANOS_PER_SECOND)); + buf.st_mtim.tv_nsec + + (buf.st_mtim.tv_sec * utils::time::NANOS_PER_SECOND)); #endif // defined(__APPLE__) return file; diff --git a/repertory/librepertory/src/utils/file_utils.cpp b/repertory/librepertory/src/utils/file_utils.cpp index 64c7746f..0ade36a4 100644 --- a/repertory/librepertory/src/utils/file_utils.cpp +++ b/repertory/librepertory/src/utils/file_utils.cpp @@ -218,12 +218,13 @@ auto get_directory_files(std::string path, bool oldest_first, stat(lookup_path.c_str(), &st); #if defined(__APPLE__) lookup[lookup_path] = static_cast( - (st.st_mtimespec.tv_sec * NANOS_PER_SECOND) + + (st.st_mtimespec.tv_sec * utils::time::NANOS_PER_SECOND) + st.st_mtimespec.tv_nsec); -#else +#else // !defined(__APPLE__) lookup[lookup_path] = static_cast( - (st.st_mtim.tv_sec * NANOS_PER_SECOND) + st.st_mtim.tv_nsec); -#endif + (st.st_mtim.tv_sec * utils::time::NANOS_PER_SECOND) + + st.st_mtim.tv_nsec); +#endif // defined(__APPLE__) } }; @@ -238,70 +239,13 @@ auto get_directory_files(std::string path, bool oldest_first, return ret; } -auto get_accessed_time(const std::string &path, - std::uint64_t &accessed) -> bool { - auto ret = false; - accessed = 0; -#if defined(_WIN32) - struct _stat64 st {}; - if (_stat64(path.c_str(), &st) != -1) { - accessed = time::windows_time_to_unix_time( - static_cast(st.st_atime)); -#else - struct stat st {}; - if (stat(path.c_str(), &st) != -1) { -#if defined(__APPLE__) - accessed = static_cast( - st.st_atimespec.tv_nsec + (st.st_atimespec.tv_sec * NANOS_PER_SECOND)); -#else - accessed = static_cast(st.st_atim.tv_nsec + - (st.st_atim.tv_sec * NANOS_PER_SECOND)); -#endif -#endif - ret = true; - } - - return ret; -} - -auto get_modified_time(const std::string &path, - std::uint64_t &modified) -> bool { - auto ret = false; - modified = 0U; -#if defined(_WIN32) - struct _stat64 st {}; - if (_stat64(path.c_str(), &st) != -1) { - modified = time::windows_time_to_unix_time( - static_cast(st.st_mtime)); -#else - struct stat st {}; - if (stat(path.c_str(), &st) != -1) { -#if defined(__APPLE__) - modified = static_cast( - st.st_mtimespec.tv_nsec + (st.st_mtimespec.tv_sec * NANOS_PER_SECOND)); -#else - modified = static_cast(st.st_mtim.tv_nsec + - (st.st_mtim.tv_sec * NANOS_PER_SECOND)); -#endif -#endif - ret = true; - } - - return ret; -} - -auto is_modified_date_older_than(const std::string &path, +auto is_modified_date_older_than(std::string_view path, const std::chrono::hours &hours) -> bool { - auto ret = false; - std::uint64_t modified{}; - if (get_modified_time(path, modified)) { - auto seconds = std::chrono::duration_cast(hours); - return (modified + - static_cast(seconds.count() * NANOS_PER_SECOND)) < - utils::time::get_time_now(); - } - - return ret; + auto modified = file{path}.get_time(file::time_types::modified); + auto seconds = std::chrono::duration_cast(hours); + return (modified + static_cast( + seconds.count() * utils::time::NANOS_PER_SECOND)) < + utils::time::get_time_now(); } auto move_file(std::string from, std::string to) -> bool { diff --git a/repertory/repertory_test/src/remote_fuse_test.cpp b/repertory/repertory_test/src/remote_fuse_test.cpp index 84c3513c..c66c3909 100644 --- a/repertory/repertory_test/src/remote_fuse_test.cpp +++ b/repertory/repertory_test/src/remote_fuse_test.cpp @@ -219,13 +219,13 @@ static void fgetattr_test(repertory::remote_fuse::remote_client &client) { EXPECT_EQ(st1.st_nlink, st.st_nlink); EXPECT_EQ(st1.st_mode, st.st_mode); EXPECT_LE(static_cast(st1.st_atime), - st.st_atimespec / NANOS_PER_SECOND); + st.st_atimespec / utils::time::NANOS_PER_SECOND); EXPECT_EQ(static_cast(st1.st_mtime), - st.st_mtimespec / NANOS_PER_SECOND); + st.st_mtimespec / utils::time::NANOS_PER_SECOND); EXPECT_EQ(static_cast(st1.st_ctime), - st.st_ctimespec / NANOS_PER_SECOND); + st.st_ctimespec / utils::time::NANOS_PER_SECOND); EXPECT_EQ(static_cast(st1.st_ctime), - st.st_birthtimespec / NANOS_PER_SECOND); + st.st_birthtimespec / utils::time::NANOS_PER_SECOND); } EXPECT_TRUE(utils::file::file(test_file).remove()); @@ -330,13 +330,13 @@ static void getattr_test(repertory::remote_fuse::remote_client &client) { EXPECT_EQ(st1.st_nlink, st.st_nlink); EXPECT_EQ(st1.st_mode, st.st_mode); EXPECT_LE(static_cast(st1.st_atime), - st.st_atimespec / NANOS_PER_SECOND); + st.st_atimespec / utils::time::NANOS_PER_SECOND); EXPECT_EQ(static_cast(st1.st_mtime), - st.st_mtimespec / NANOS_PER_SECOND); + st.st_mtimespec / utils::time::NANOS_PER_SECOND); EXPECT_EQ(static_cast(st1.st_ctime), - st.st_ctimespec / NANOS_PER_SECOND); + st.st_ctimespec / utils::time::NANOS_PER_SECOND); EXPECT_EQ(static_cast(st1.st_ctime), - st.st_birthtimespec / NANOS_PER_SECOND); + st.st_birthtimespec / utils::time::NANOS_PER_SECOND); } EXPECT_TRUE(utils::file::file(test_file).remove()); @@ -832,7 +832,7 @@ static void statfs_x_test(repertory::remote_fuse::remote_client &client, remote::statfs_x st{}; EXPECT_EQ(0, client.fuse_statfs_x(api_path.c_str(), 4096, st)); - EXPECT_STREQ(&st.f_mntfromname[0], + EXPECT_STREQ(st.f_mntfromname.data(), utils::create_volume_label(provider_type::remote).c_str()); const auto total_bytes = drive.get_total_drive_space();