updates
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
if(PROJECT_ENABLE_LIBSODIUM)
|
if(PROJECT_ENABLE_LIBSODIUM)
|
||||||
if(PROJECT_BUILD)
|
if(PROJECT_BUILD)
|
||||||
pkg_check_modules(SODIUM libsodium=${LIBSODIUM_VERSION} REQUIRED)
|
pkg_check_modules(SODIUM libsodium>=${LIBSODIUM_VERSION} REQUIRED)
|
||||||
|
|
||||||
add_definitions(-DPROJECT_ENABLE_LIBSODIUM)
|
add_definitions(-DPROJECT_ENABLE_LIBSODIUM)
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ if(PROJECT_ENABLE_STDUUID)
|
|||||||
if(PROJECT_BUILD)
|
if(PROJECT_BUILD)
|
||||||
add_definitions(-DPROJECT_ENABLE_STDUUID)
|
add_definitions(-DPROJECT_ENABLE_STDUUID)
|
||||||
|
|
||||||
find_package(stduuid REQUIRED)
|
find_package(stduuid ${STDUUID_VERSION} REQUIRED)
|
||||||
|
|
||||||
include_directories(BEFORE SYSTEM ${stduuid_INCLUDE_DIRS})
|
include_directories(BEFORE SYSTEM ${stduuid_INCLUDE_DIRS})
|
||||||
|
|
||||||
|
@ -133,29 +133,21 @@ void encrypt_provider::create_item_meta(api_meta_map &meta, bool directory,
|
|||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
struct _stat64 buf {};
|
struct _stat64 buf {};
|
||||||
_stat64(file.source_path.c_str(), &buf);
|
_stat64(file.source_path.c_str(), &buf);
|
||||||
#else
|
#else // !defined(_WIN32)
|
||||||
struct stat buf {};
|
struct stat buf {};
|
||||||
stat(file.source_path.c_str(), &buf);
|
stat(file.source_path.c_str(), &buf);
|
||||||
#endif
|
#endif // defined(_WIN32)
|
||||||
|
|
||||||
meta[META_ACCESSED] = std::to_string(file.accessed_date);
|
meta[META_ACCESSED] = std::to_string(file.accessed_date);
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
meta[META_ATTRIBUTES] = std::to_string(
|
meta[META_ATTRIBUTES] =
|
||||||
::GetFileAttributesA(file.source_path.c_str()) &
|
std::to_string(::GetFileAttributesA(file.source_path.c_str()) &
|
||||||
~static_cast<DWORD>(
|
~static_cast<DWORD>(FILE_ATTRIBUTE_REPARSE_POINT));
|
||||||
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));
|
|
||||||
|
|
||||||
#endif
|
#endif // defined(_WIN32)
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
meta[META_BACKUP];
|
meta[META_BACKUP];
|
||||||
#endif
|
#endif // defined(__APPLE__)
|
||||||
meta[META_CHANGED] = std::to_string(file.changed_date);
|
meta[META_CHANGED] = std::to_string(file.changed_date);
|
||||||
meta[META_CREATION] = std::to_string(file.creation_date);
|
meta[META_CREATION] = std::to_string(file.creation_date);
|
||||||
meta[META_DIRECTORY] = utils::string::from_bool(directory);
|
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);
|
meta[META_MODIFIED] = std::to_string(file.modified_date);
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
meta[META_OSXFLAGS];
|
meta[META_OSXFLAGS];
|
||||||
#endif
|
#endif // defined(__APPLE__)
|
||||||
meta[META_SIZE] = std::to_string(file.file_size);
|
meta[META_SIZE] = std::to_string(file.file_size);
|
||||||
meta[META_SOURCE] = file.source_path;
|
meta[META_SOURCE] = file.source_path;
|
||||||
meta[META_UID] = std::to_string(buf.st_uid);
|
meta[META_UID] = std::to_string(buf.st_uid);
|
||||||
|
@ -237,13 +237,7 @@ public:
|
|||||||
file(file &&move_file) noexcept
|
file(file &&move_file) noexcept
|
||||||
: file_(std::move(move_file.file_)),
|
: file_(std::move(move_file.file_)),
|
||||||
path_(std::move(move_file.path_)),
|
path_(std::move(move_file.path_)),
|
||||||
read_only_(move_file.read_only_)
|
read_only_(move_file.read_only_) {}
|
||||||
#if defined(_WIN32)
|
|
||||||
,
|
|
||||||
mtx_(std::move(move_file.mtx_))
|
|
||||||
#endif // defined(_WIN32)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
~file() override { close(); }
|
~file() override { close(); }
|
||||||
|
|
||||||
@ -251,11 +245,6 @@ private:
|
|||||||
file_t file_;
|
file_t file_;
|
||||||
std::string path_;
|
std::string path_;
|
||||||
bool read_only_{false};
|
bool read_only_{false};
|
||||||
#if defined(_WIN32)
|
|
||||||
mutable std::unique_ptr<std::recursive_mutex> mtx_{
|
|
||||||
new std::recursive_mutex(),
|
|
||||||
};
|
|
||||||
#endif // defined(_WIN32)
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::atomic_uint32_t read_buffer_size{65536U};
|
std::atomic_uint32_t read_buffer_size{65536U};
|
||||||
@ -281,8 +270,6 @@ public:
|
|||||||
return read_buffer_size;
|
return read_buffer_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] auto get_time(time_types type) const -> std::uint64_t override;
|
|
||||||
|
|
||||||
[[nodiscard]] auto is_read_only() const -> bool override {
|
[[nodiscard]] auto is_read_only() const -> bool override {
|
||||||
return read_only_;
|
return read_only_;
|
||||||
}
|
}
|
||||||
@ -322,9 +309,6 @@ public:
|
|||||||
file_ = std::move(move_file.file_);
|
file_ = std::move(move_file.file_);
|
||||||
path_ = std::move(move_file.path_);
|
path_ = std::move(move_file.path_);
|
||||||
read_only_ = move_file.read_only_;
|
read_only_ = move_file.read_only_;
|
||||||
#if defined(_WIN32)
|
|
||||||
mtx_ = std::move(move_file.mtx_);
|
|
||||||
#endif // defined(_WIN32)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -36,11 +36,6 @@ inline constexpr const auto WIN32_TIME_NANOS_PER_TICK{100ULL};
|
|||||||
}
|
}
|
||||||
#endif // defined(PROJECT_ENABLE_SPDLOG) || defined(PROJECT_ENABLE_FMT)
|
#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)
|
#if defined(PROJECT_ENABLE_SPDLOG) || defined(PROJECT_ENABLE_FMT)
|
||||||
[[nodiscard]] inline auto get_current_time_utc() -> std::time_t {
|
[[nodiscard]] inline auto get_current_time_utc() -> std::time_t {
|
||||||
auto calendar_time = fmt::gmtime(std::time(nullptr));
|
auto calendar_time = fmt::gmtime(std::time(nullptr));
|
||||||
@ -55,8 +50,6 @@ void get_local_time_now(struct tm &local_time);
|
|||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
auto strptime(const char *s, const char *f, struct tm *tm) -> const char *;
|
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;
|
[[nodiscard]] auto unix_time_to_filetime(std::uint64_t unix_time) -> FILETIME;
|
||||||
#endif // defined(_WIN32)
|
#endif // defined(_WIN32)
|
||||||
|
|
||||||
|
@ -65,10 +65,11 @@ auto traverse_directory(
|
|||||||
std::to_string(repertory::utils::get_last_error_code()));
|
std::to_string(repertory::utils::get_last_error_code()));
|
||||||
}
|
}
|
||||||
|
|
||||||
struct dirent *de{};
|
struct dirent *de{nullptr};
|
||||||
while (res && (de = readdir(root))) {
|
while (res && (de = readdir(root))) {
|
||||||
if (de->d_type == DT_DIR) {
|
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(
|
res = directory_action(repertory::utils::file::directory(
|
||||||
repertory::utils::path::combine(path, {de->d_name})));
|
repertory::utils::path::combine(path, {de->d_name})));
|
||||||
}
|
}
|
||||||
|
@ -179,13 +179,7 @@ auto file::open_or_create_file(std::string_view path,
|
|||||||
return open_file(abs_path, read_only);
|
return open_file(abs_path, read_only);
|
||||||
}
|
}
|
||||||
|
|
||||||
void file::close() {
|
void file::close() { file_.reset(); }
|
||||||
#if defined(_WIN32)
|
|
||||||
recur_mutex_lock lock{*mtx_};
|
|
||||||
#endif // defined(_WIN32)
|
|
||||||
|
|
||||||
file_.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto file::copy_to(std::string_view new_path, bool overwrite) const -> bool {
|
auto file::copy_to(std::string_view new_path, bool overwrite) const -> bool {
|
||||||
static constexpr const std::string_view function_name{
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto file::exists() const -> bool {
|
auto file::exists() const -> bool { return is_file(path_); }
|
||||||
#if defined(_WIN32)
|
|
||||||
recur_mutex_lock lock{*mtx_};
|
|
||||||
#endif // defined(_WIN32)
|
|
||||||
|
|
||||||
return is_file(path_);
|
|
||||||
}
|
|
||||||
|
|
||||||
void file::flush() const {
|
void file::flush() const {
|
||||||
#if defined(_WIN32)
|
|
||||||
recur_mutex_lock lock{*mtx_};
|
|
||||||
#endif // defined(_WIN32)
|
|
||||||
|
|
||||||
if (file_) {
|
if (file_) {
|
||||||
fflush(file_.get());
|
fflush(file_.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto file::get_handle() const -> native_handle {
|
auto file::get_handle() const -> native_handle {
|
||||||
#if defined(_WIN32)
|
|
||||||
recur_mutex_lock lock{*mtx_};
|
|
||||||
#endif // defined(_WIN32)
|
|
||||||
|
|
||||||
if (file_) {
|
if (file_) {
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
return reinterpret_cast<native_handle>(
|
return reinterpret_cast<native_handle>(
|
||||||
@ -251,14 +231,6 @@ auto file::get_handle() const -> native_handle {
|
|||||||
return INVALID_HANDLE_VALUE;
|
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 {
|
auto file::is_symlink() const -> bool {
|
||||||
static constexpr const std::string_view function_name{
|
static constexpr const std::string_view function_name{
|
||||||
static_cast<const char *>(__FUNCTION__),
|
static_cast<const char *>(__FUNCTION__),
|
||||||
@ -280,10 +252,6 @@ auto file::move_to(std::string_view path) -> bool {
|
|||||||
static_cast<const char *>(__FUNCTION__),
|
static_cast<const char *>(__FUNCTION__),
|
||||||
};
|
};
|
||||||
|
|
||||||
#if defined(_WIN32)
|
|
||||||
recur_mutex_lock lock{*mtx_};
|
|
||||||
#endif // defined(_WIN32)
|
|
||||||
|
|
||||||
auto abs_path = utils::path::absolute(path);
|
auto abs_path = utils::path::absolute(path);
|
||||||
|
|
||||||
auto reopen{false};
|
auto reopen{false};
|
||||||
@ -326,10 +294,6 @@ auto file::read(unsigned char *data, std::size_t to_read, std::uint64_t offset,
|
|||||||
static_cast<const char *>(__FUNCTION__),
|
static_cast<const char *>(__FUNCTION__),
|
||||||
};
|
};
|
||||||
|
|
||||||
#if defined(_WIN32)
|
|
||||||
recur_mutex_lock lock{*mtx_};
|
|
||||||
#endif // defined(_WIN32)
|
|
||||||
|
|
||||||
if (total_read != nullptr) {
|
if (total_read != nullptr) {
|
||||||
(*total_read) = 0U;
|
(*total_read) = 0U;
|
||||||
}
|
}
|
||||||
@ -441,10 +405,6 @@ auto file::sha256() -> std::optional<std::string> {
|
|||||||
#endif // defined(PROJECT_ENABLE_LIBSODIUM)
|
#endif // defined(PROJECT_ENABLE_LIBSODIUM)
|
||||||
|
|
||||||
auto file::remove() -> bool {
|
auto file::remove() -> bool {
|
||||||
#if defined(_WIN32)
|
|
||||||
recur_mutex_lock lock{*mtx_};
|
|
||||||
#endif // defined(_WIN32)
|
|
||||||
|
|
||||||
if (not exists()) {
|
if (not exists()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -466,10 +426,6 @@ auto file::truncate(std::size_t size) -> bool {
|
|||||||
static_cast<const char *>(__FUNCTION__),
|
static_cast<const char *>(__FUNCTION__),
|
||||||
};
|
};
|
||||||
|
|
||||||
#if defined(_WIN32)
|
|
||||||
recur_mutex_lock lock{*mtx_};
|
|
||||||
#endif // defined(_WIN32)
|
|
||||||
|
|
||||||
auto reopen{false};
|
auto reopen{false};
|
||||||
if (file_) {
|
if (file_) {
|
||||||
reopen = true;
|
reopen = true;
|
||||||
@ -502,10 +458,6 @@ auto file::write(const unsigned char *data, std::size_t to_write,
|
|||||||
static_cast<const char *>(__FUNCTION__),
|
static_cast<const char *>(__FUNCTION__),
|
||||||
};
|
};
|
||||||
|
|
||||||
#if defined(_WIN32)
|
|
||||||
recur_mutex_lock lock{*mtx_};
|
|
||||||
#endif // defined(_WIN32)
|
|
||||||
|
|
||||||
if (total_written != nullptr) {
|
if (total_written != nullptr) {
|
||||||
(*total_written) = 0U;
|
(*total_written) = 0U;
|
||||||
}
|
}
|
||||||
@ -556,10 +508,6 @@ auto file::size() const -> std::optional<std::uint64_t> {
|
|||||||
static_cast<const char *>(__FUNCTION__),
|
static_cast<const char *>(__FUNCTION__),
|
||||||
};
|
};
|
||||||
|
|
||||||
#if defined(_WIN32)
|
|
||||||
recur_mutex_lock lock{*mtx_};
|
|
||||||
#endif // defined(_WIN32)
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (file_) {
|
if (file_) {
|
||||||
if (fseeko(file_.get(), 0, SEEK_END) == -1) {
|
if (fseeko(file_.get(), 0, SEEK_END) == -1) {
|
||||||
|
@ -22,18 +22,6 @@
|
|||||||
#include "utils/time.hpp"
|
#include "utils/time.hpp"
|
||||||
|
|
||||||
namespace repertory::utils::time {
|
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<LONG>(file_time.dwHighDateTime);
|
|
||||||
date.LowPart = file_time.dwLowDateTime;
|
|
||||||
date.QuadPart -= WIN32_TIME_CONVERSION;
|
|
||||||
|
|
||||||
return static_cast<std::uint64_t>(date.QuadPart) * WIN32_TIME_NANOS_PER_TICK;
|
|
||||||
}
|
|
||||||
#endif // defined(_WIN32)
|
|
||||||
|
|
||||||
void get_local_time_now(struct tm &local_time) {
|
void get_local_time_now(struct tm &local_time) {
|
||||||
std::memset(&local_time, 0, sizeof(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<const char *>(s + input.tellg());
|
return reinterpret_cast<const char *>(s + input.tellg());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto time64_to_unix_time(const __time64_t &time) -> std::uint64_t {
|
|
||||||
return static_cast<std::uint64_t>(time * NANOS_PER_SECOND);
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://www.frenk.com/2009/12/convert-filetime-to-unix-timestamp/
|
// https://www.frenk.com/2009/12/convert-filetime-to-unix-timestamp/
|
||||||
auto unix_time_to_filetime(std::uint64_t unix_time) -> FILETIME {
|
auto unix_time_to_filetime(std::uint64_t unix_time) -> FILETIME {
|
||||||
auto win_time =
|
auto win_time = unix_time_to_windows_time(unix_time);
|
||||||
(unix_time / WIN32_TIME_NANOS_PER_TICK) + WIN32_TIME_CONVERSION;
|
|
||||||
FILETIME file_time{};
|
FILETIME file_time{};
|
||||||
file_time.dwHighDateTime = static_cast<DWORD>(win_time >> 32U);
|
file_time.dwHighDateTime = static_cast<DWORD>(win_time >> 32U);
|
||||||
file_time.dwLowDateTime = win_time & 0xFFFFFFFF;
|
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 {
|
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
|
} // namespace repertory::utils::time
|
||||||
|
Reference in New Issue
Block a user