From 07ad8a55d34c28f46a2f84753298d30900018364 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Thu, 29 Aug 2024 09:33:24 -0500 Subject: [PATCH] updates --- cmake/libraries/libsodium.cmake | 2 +- cmake/libraries/stduuid.cmake | 2 +- .../providers/encrypt/encrypt_provider.cpp | 24 +++----- support/include/utils/file.hpp | 18 +----- support/include/utils/time.hpp | 7 --- support/src/utils/file_directory.cpp | 5 +- support/src/utils/file_file.cpp | 56 +------------------ support/src/utils/time.cpp | 22 +------- 8 files changed, 19 insertions(+), 117 deletions(-) diff --git a/cmake/libraries/libsodium.cmake b/cmake/libraries/libsodium.cmake index 9dbee628..b547b592 100644 --- a/cmake/libraries/libsodium.cmake +++ b/cmake/libraries/libsodium.cmake @@ -1,6 +1,6 @@ if(PROJECT_ENABLE_LIBSODIUM) if(PROJECT_BUILD) - pkg_check_modules(SODIUM libsodium=${LIBSODIUM_VERSION} REQUIRED) + pkg_check_modules(SODIUM libsodium>=${LIBSODIUM_VERSION} REQUIRED) add_definitions(-DPROJECT_ENABLE_LIBSODIUM) diff --git a/cmake/libraries/stduuid.cmake b/cmake/libraries/stduuid.cmake index 87ffc05a..fe6e758b 100644 --- a/cmake/libraries/stduuid.cmake +++ b/cmake/libraries/stduuid.cmake @@ -2,7 +2,7 @@ if(PROJECT_ENABLE_STDUUID) if(PROJECT_BUILD) add_definitions(-DPROJECT_ENABLE_STDUUID) - find_package(stduuid REQUIRED) + find_package(stduuid ${STDUUID_VERSION} REQUIRED) include_directories(BEFORE SYSTEM ${stduuid_INCLUDE_DIRS}) diff --git a/repertory/librepertory/src/providers/encrypt/encrypt_provider.cpp b/repertory/librepertory/src/providers/encrypt/encrypt_provider.cpp index 627c764c..ff07b4ae 100644 --- a/repertory/librepertory/src/providers/encrypt/encrypt_provider.cpp +++ b/repertory/librepertory/src/providers/encrypt/encrypt_provider.cpp @@ -133,29 +133,21 @@ void encrypt_provider::create_item_meta(api_meta_map &meta, bool directory, #if defined(_WIN32) struct _stat64 buf {}; _stat64(file.source_path.c_str(), &buf); -#else +#else // !defined(_WIN32) struct stat buf {}; stat(file.source_path.c_str(), &buf); -#endif +#endif // defined(_WIN32) meta[META_ACCESSED] = std::to_string(file.accessed_date); #if defined(_WIN32) - meta[META_ATTRIBUTES] = std::to_string( - ::GetFileAttributesA(file.source_path.c_str()) & - ~static_cast( - FILE_ATTRIBUTE_DEVICE | FILE_ATTRIBUTE_TEMPORARY | - FILE_ATTRIBUTE_SPARSE_FILE | FILE_ATTRIBUTE_REPARSE_POINT | - FILE_ATTRIBUTE_COMPRESSED | FILE_ATTRIBUTE_OFFLINE | - FILE_ATTRIBUTE_NOT_CONTENT_INDEXED | FILE_ATTRIBUTE_ENCRYPTED | - FILE_ATTRIBUTE_INTEGRITY_STREAM | FILE_ATTRIBUTE_VIRTUAL | - FILE_ATTRIBUTE_NO_SCRUB_DATA | FILE_ATTRIBUTE_PINNED | - FILE_ATTRIBUTE_UNPINNED | FILE_ATTRIBUTE_RECALL_ON_OPEN | - FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS)); + meta[META_ATTRIBUTES] = + std::to_string(::GetFileAttributesA(file.source_path.c_str()) & + ~static_cast(FILE_ATTRIBUTE_REPARSE_POINT)); -#endif +#endif // defined(_WIN32) #if defined(__APPLE__) meta[META_BACKUP]; -#endif +#endif // defined(__APPLE__) meta[META_CHANGED] = std::to_string(file.changed_date); meta[META_CREATION] = std::to_string(file.creation_date); meta[META_DIRECTORY] = utils::string::from_bool(directory); @@ -164,7 +156,7 @@ void encrypt_provider::create_item_meta(api_meta_map &meta, bool directory, meta[META_MODIFIED] = std::to_string(file.modified_date); #if defined(__APPLE__) meta[META_OSXFLAGS]; -#endif +#endif // defined(__APPLE__) meta[META_SIZE] = std::to_string(file.file_size); meta[META_SOURCE] = file.source_path; meta[META_UID] = std::to_string(buf.st_uid); diff --git a/support/include/utils/file.hpp b/support/include/utils/file.hpp index 28ba1440..916ac3be 100644 --- a/support/include/utils/file.hpp +++ b/support/include/utils/file.hpp @@ -237,13 +237,7 @@ public: file(file &&move_file) noexcept : file_(std::move(move_file.file_)), path_(std::move(move_file.path_)), - read_only_(move_file.read_only_) -#if defined(_WIN32) - , - mtx_(std::move(move_file.mtx_)) -#endif // defined(_WIN32) - { - } + read_only_(move_file.read_only_) {} ~file() override { close(); } @@ -251,11 +245,6 @@ private: file_t file_; std::string path_; bool read_only_{false}; -#if defined(_WIN32) - mutable std::unique_ptr mtx_{ - new std::recursive_mutex(), - }; -#endif // defined(_WIN32) private: std::atomic_uint32_t read_buffer_size{65536U}; @@ -281,8 +270,6 @@ public: return read_buffer_size; } - [[nodiscard]] auto get_time(time_types type) const -> std::uint64_t override; - [[nodiscard]] auto is_read_only() const -> bool override { return read_only_; } @@ -322,9 +309,6 @@ public: file_ = std::move(move_file.file_); path_ = std::move(move_file.path_); read_only_ = move_file.read_only_; -#if defined(_WIN32) - mtx_ = std::move(move_file.mtx_); -#endif // defined(_WIN32) } return *this; diff --git a/support/include/utils/time.hpp b/support/include/utils/time.hpp index 7a7bd688..05536c2e 100644 --- a/support/include/utils/time.hpp +++ b/support/include/utils/time.hpp @@ -36,11 +36,6 @@ inline constexpr const auto WIN32_TIME_NANOS_PER_TICK{100ULL}; } #endif // defined(PROJECT_ENABLE_SPDLOG) || defined(PROJECT_ENABLE_FMT) -#if defined(_WIN32) -[[nodiscard]] auto -filetime_to_unix_time(const FILETIME &file_time) -> std::uint64_t; -#endif // defined(_WIN32) - #if defined(PROJECT_ENABLE_SPDLOG) || defined(PROJECT_ENABLE_FMT) [[nodiscard]] inline auto get_current_time_utc() -> std::time_t { auto calendar_time = fmt::gmtime(std::time(nullptr)); @@ -55,8 +50,6 @@ void get_local_time_now(struct tm &local_time); #if defined(_WIN32) auto strptime(const char *s, const char *f, struct tm *tm) -> const char *; -[[nodiscard]] auto time64_to_unix_time(const __time64_t &time) -> std::uint64_t; - [[nodiscard]] auto unix_time_to_filetime(std::uint64_t unix_time) -> FILETIME; #endif // defined(_WIN32) diff --git a/support/src/utils/file_directory.cpp b/support/src/utils/file_directory.cpp index 2647025a..254c7f0a 100644 --- a/support/src/utils/file_directory.cpp +++ b/support/src/utils/file_directory.cpp @@ -65,10 +65,11 @@ auto traverse_directory( std::to_string(repertory::utils::get_last_error_code())); } - struct dirent *de{}; + struct dirent *de{nullptr}; while (res && (de = readdir(root))) { if (de->d_type == DT_DIR) { - if ((strcmp(de->d_name, ".") != 0) && (strcmp(de->d_name, "..") != 0)) { + if ((std::string_view(de->d_name) != ".") && + (std::string_view(de->d_name) != "..")) { res = directory_action(repertory::utils::file::directory( repertory::utils::path::combine(path, {de->d_name}))); } diff --git a/support/src/utils/file_file.cpp b/support/src/utils/file_file.cpp index 75d747ef..1fe168ca 100644 --- a/support/src/utils/file_file.cpp +++ b/support/src/utils/file_file.cpp @@ -179,13 +179,7 @@ auto file::open_or_create_file(std::string_view path, return open_file(abs_path, read_only); } -void file::close() { -#if defined(_WIN32) - recur_mutex_lock lock{*mtx_}; -#endif // defined(_WIN32) - - file_.reset(); -} +void file::close() { file_.reset(); } auto file::copy_to(std::string_view new_path, bool overwrite) const -> bool { static constexpr const std::string_view function_name{ @@ -216,29 +210,15 @@ auto file::copy_to(std::string_view new_path, bool overwrite) const -> bool { return false; } -auto file::exists() const -> bool { -#if defined(_WIN32) - recur_mutex_lock lock{*mtx_}; -#endif // defined(_WIN32) - - return is_file(path_); -} +auto file::exists() const -> bool { return is_file(path_); } void file::flush() const { -#if defined(_WIN32) - recur_mutex_lock lock{*mtx_}; -#endif // defined(_WIN32) - if (file_) { fflush(file_.get()); } } auto file::get_handle() const -> native_handle { -#if defined(_WIN32) - recur_mutex_lock lock{*mtx_}; -#endif // defined(_WIN32) - if (file_) { #if defined(_WIN32) return reinterpret_cast( @@ -251,14 +231,6 @@ auto file::get_handle() const -> native_handle { return INVALID_HANDLE_VALUE; } -auto file::get_time(time_types type) const -> std::uint64_t { -#if defined(_WIN32) - recur_mutex_lock lock{*mtx_}; -#endif // defined(_WIN32) - - return i_fs_item::get_time(type); -} - auto file::is_symlink() const -> bool { static constexpr const std::string_view function_name{ static_cast(__FUNCTION__), @@ -280,10 +252,6 @@ auto file::move_to(std::string_view path) -> bool { static_cast(__FUNCTION__), }; -#if defined(_WIN32) - recur_mutex_lock lock{*mtx_}; -#endif // defined(_WIN32) - auto abs_path = utils::path::absolute(path); auto reopen{false}; @@ -326,10 +294,6 @@ auto file::read(unsigned char *data, std::size_t to_read, std::uint64_t offset, static_cast(__FUNCTION__), }; -#if defined(_WIN32) - recur_mutex_lock lock{*mtx_}; -#endif // defined(_WIN32) - if (total_read != nullptr) { (*total_read) = 0U; } @@ -441,10 +405,6 @@ auto file::sha256() -> std::optional { #endif // defined(PROJECT_ENABLE_LIBSODIUM) auto file::remove() -> bool { -#if defined(_WIN32) - recur_mutex_lock lock{*mtx_}; -#endif // defined(_WIN32) - if (not exists()) { return true; } @@ -466,10 +426,6 @@ auto file::truncate(std::size_t size) -> bool { static_cast(__FUNCTION__), }; -#if defined(_WIN32) - recur_mutex_lock lock{*mtx_}; -#endif // defined(_WIN32) - auto reopen{false}; if (file_) { reopen = true; @@ -502,10 +458,6 @@ auto file::write(const unsigned char *data, std::size_t to_write, static_cast(__FUNCTION__), }; -#if defined(_WIN32) - recur_mutex_lock lock{*mtx_}; -#endif // defined(_WIN32) - if (total_written != nullptr) { (*total_written) = 0U; } @@ -556,10 +508,6 @@ auto file::size() const -> std::optional { static_cast(__FUNCTION__), }; -#if defined(_WIN32) - recur_mutex_lock lock{*mtx_}; -#endif // defined(_WIN32) - try { if (file_) { if (fseeko(file_.get(), 0, SEEK_END) == -1) { diff --git a/support/src/utils/time.cpp b/support/src/utils/time.cpp index cc11ca04..ecce2a77 100644 --- a/support/src/utils/time.cpp +++ b/support/src/utils/time.cpp @@ -22,18 +22,6 @@ #include "utils/time.hpp" namespace repertory::utils::time { -#if defined(_WIN32) -// https://www.frenk.com/2009/12/convert-filetime-to-unix-timestamp/ -auto filetime_to_unix_time(const FILETIME &file_time) -> std::uint64_t { - LARGE_INTEGER date{}; - date.HighPart = static_cast(file_time.dwHighDateTime); - date.LowPart = file_time.dwLowDateTime; - date.QuadPart -= WIN32_TIME_CONVERSION; - - return static_cast(date.QuadPart) * WIN32_TIME_NANOS_PER_TICK; -} -#endif // defined(_WIN32) - void get_local_time_now(struct tm &local_time) { std::memset(&local_time, 0, sizeof(local_time)); @@ -66,14 +54,10 @@ auto strptime(const char *s, const char *f, struct tm *tm) -> const char * { return reinterpret_cast(s + input.tellg()); } -auto time64_to_unix_time(const __time64_t &time) -> std::uint64_t { - return static_cast(time * NANOS_PER_SECOND); -} - // https://www.frenk.com/2009/12/convert-filetime-to-unix-timestamp/ auto unix_time_to_filetime(std::uint64_t unix_time) -> FILETIME { - auto win_time = - (unix_time / WIN32_TIME_NANOS_PER_TICK) + WIN32_TIME_CONVERSION; + auto win_time = unix_time_to_windows_time(unix_time); + FILETIME file_time{}; file_time.dwHighDateTime = static_cast(win_time >> 32U); file_time.dwLowDateTime = win_time & 0xFFFFFFFF; @@ -86,6 +70,6 @@ auto unix_time_to_windows_time(std::uint64_t unix_time) -> std::uint64_t { } auto windows_time_to_unix_time(std::uint64_t win_time) -> std::uint64_t { - return (win_time - WIN32_TIME_CONVERSION) * WIN32_TIME_NANOS_PER_TICK; + return (win_time * WIN32_TIME_NANOS_PER_TICK) - WIN32_TIME_CONVERSION; } } // namespace repertory::utils::time