updated build system

This commit is contained in:
2024-08-23 12:01:46 -05:00
parent 52f2b5b118
commit d4f0431cd5
8 changed files with 71 additions and 40 deletions

View File

@ -46,6 +46,10 @@ public:
auto operator=(const s3_provider &) -> s3_provider & = delete;
auto operator=(s3_provider &&) -> s3_provider & = delete;
public:
[[nodiscard]] static auto
convert_api_date(std::string_view date) -> std::uint64_t;
private:
[[nodiscard]] auto
add_if_not_found(api_file &file,

View File

@ -43,15 +43,9 @@ inline const std::array<std::string, 4U> attribute_namespaces = {
[[nodiscard]] auto unix_error_to_windows(int err) -> std::uint32_t;
[[nodiscard]] auto
unix_time_to_windows_time(const remote::file_time &file_time) -> UINT64;
void windows_create_to_unix(const UINT32 &create_options,
const UINT32 &granted_access, std::uint32_t &flags,
remote::file_mode &mode);
[[nodiscard]] auto
windows_time_to_unix_time(std::uint64_t win_time) -> remote::file_time;
} // namespace repertory::utils
#endif // !_WIN32

View File

@ -125,18 +125,18 @@ void remote_server::populate_file_info(const std::string &api_path,
file_info.AllocationSize =
utils::divide_with_ceiling(file_size, WINFSP_ALLOCATION_UNIT) *
WINFSP_ALLOCATION_UNIT;
file_info.ChangeTime = utils::unix_time_to_windows_time(
file_info.ChangeTime = utils::time::unix_time_to_windows_time(
utils::string::to_uint64(empty_as_zero(meta[META_MODIFIED])));
file_info.CreationTime = utils::unix_time_to_windows_time(
file_info.CreationTime = utils::time::unix_time_to_windows_time(
utils::string::to_uint64(empty_as_zero(meta[META_CREATION])));
file_info.EaSize = 0;
file_info.FileAttributes = attributes;
file_info.FileSize = file_size;
file_info.HardLinks = 0;
file_info.IndexNumber = 0;
file_info.LastAccessTime = utils::unix_time_to_windows_time(
file_info.LastAccessTime = utils::time::unix_time_to_windows_time(
utils::string::to_uint64(empty_as_zero(meta[META_ACCESSED])));
file_info.LastWriteTime = utils::unix_time_to_windows_time(
file_info.LastWriteTime = utils::time::unix_time_to_windows_time(
utils::string::to_uint64(empty_as_zero(meta[META_WRITTEN])));
if (meta[META_WRITTEN].empty() || (meta[META_WRITTEN] == "0") ||
(meta[META_WRITTEN] == "116444736000000000")) {
@ -1543,25 +1543,28 @@ auto remote_server::winfsp_set_basic_info(
if ((creation_time != 0U) && (creation_time != max_time)) {
drive_.set_item_meta(
api_path, META_CREATION,
std::to_string(utils::windows_time_to_unix_time(creation_time)));
std::to_string(
utils::time::windows_time_to_unix_time(creation_time)));
}
if ((last_access_time != 0U) && (last_access_time != max_time)) {
drive_.set_item_meta(
api_path, META_ACCESSED,
std::to_string(utils::windows_time_to_unix_time(last_access_time)));
std::to_string(
utils::time::windows_time_to_unix_time(last_access_time)));
}
if ((last_write_time != 0U) && (last_write_time != max_time)) {
drive_.set_item_meta(
api_path, META_WRITTEN,
std::to_string(utils::windows_time_to_unix_time(last_write_time)));
std::to_string(
utils::time::windows_time_to_unix_time(last_write_time)));
}
if ((change_time != 0U) && (change_time != max_time)) {
drive_.set_item_meta(
api_path, META_MODIFIED,
std::to_string(utils::windows_time_to_unix_time(change_time)));
std::to_string(utils::time::windows_time_to_unix_time(change_time)));
}
ret = populate_file_info(api_path, *file_info);
@ -1746,12 +1749,15 @@ auto remote_server::json_release_directory_snapshot(
auto remote_server::update_to_windows_format(json &item) -> json & {
const auto api_path = item["path"].get<std::string>();
item["meta"][META_MODIFIED] = std::to_string(utils::unix_time_to_windows_time(
utils::string::to_uint64(empty_as_zero(item["meta"][META_MODIFIED]))));
item["meta"][META_CREATION] = std::to_string(utils::unix_time_to_windows_time(
utils::string::to_uint64(empty_as_zero(item["meta"][META_CREATION]))));
item["meta"][META_ACCESSED] = std::to_string(utils::unix_time_to_windows_time(
utils::string::to_uint64(empty_as_zero(item["meta"][META_ACCESSED]))));
item["meta"][META_MODIFIED] = std::to_string(
utils::time::unix_time_to_windows_time(utils::string::to_uint64(
empty_as_zero(item["meta"][META_MODIFIED]))));
item["meta"][META_CREATION] = std::to_string(
utils::time::unix_time_to_windows_time(utils::string::to_uint64(
empty_as_zero(item["meta"][META_CREATION]))));
item["meta"][META_ACCESSED] = std::to_string(
utils::time::unix_time_to_windows_time(utils::string::to_uint64(
empty_as_zero(item["meta"][META_ACCESSED]))));
if (item["meta"][META_ATTRIBUTES].empty()) {
item["meta"][META_ATTRIBUTES] =
item["directory"].get<bool>() ? std::to_string(FILE_ATTRIBUTE_DIRECTORY)
@ -1766,11 +1772,11 @@ auto remote_server::update_to_windows_format(json &item) -> json & {
drive_.set_item_meta(api_path, META_WRITTEN,
item["meta"][META_MODIFIED].get<std::string>());
item["meta"][META_WRITTEN] = std::to_string(
utils::unix_time_to_windows_time(utils::string::to_uint64(
utils::time::unix_time_to_windows_time(utils::string::to_uint64(
empty_as_zero(item["meta"][META_MODIFIED]))));
} else {
item["meta"][META_WRITTEN] = std::to_string(
utils::unix_time_to_windows_time(utils::string::to_uint64(
utils::time::unix_time_to_windows_time(utils::string::to_uint64(
empty_as_zero(item["meta"][META_WRITTEN]))));
}
return item;

View File

@ -60,6 +60,24 @@ auto s3_provider::add_if_not_found(
return api_error::success;
}
auto s3_provider::convert_api_date(std::string_view date) -> std::uint64_t {
// 2009-10-12T17:50:30.000Z
auto date_parts = utils::string::split(date, '.', true);
auto date_time = date_parts.at(0U);
auto nanos = utils::string::to_uint64(
utils::string::split(date_parts.at(1U), 'Z', true).at(0U));
struct tm tm1 {};
#if defined(_WIN32)
utils::time::strptime(date_time.c_str(), "%Y-%m-%dT%T", &tm1);
#else
strptime(date_time.c_str(), "%Y-%m-%dT%T", &tm1);
#endif
return nanos + (static_cast<std::uint64_t>(mktime(&tm1)) *
utils::time::NANOS_PER_SECOND);
}
auto s3_provider::create_directory_impl(const std::string &api_path,
api_meta_map &meta) -> api_error {
static constexpr const std::string_view function_name{

View File

@ -201,10 +201,6 @@ auto unix_error_to_windows(int err) -> std::uint32_t {
}
}
auto unix_time_to_windows_time(const remote::file_time &file_time) -> UINT64 {
return (file_time / 100ULL) + 116444736000000000ULL;
}
void windows_create_to_unix(const UINT32 &create_options,
const UINT32 &granted_access, std::uint32_t &flags,
remote::file_mode &mode) {
@ -221,10 +217,6 @@ void windows_create_to_unix(const UINT32 &create_options,
mode |= (S_IXUSR);
}
}
auto windows_time_to_unix_time(std::uint64_t win_time) -> remote::file_time {
return (win_time - 116444736000000000ULL) * 100ULL;
}
} // namespace repertory::utils
#endif // !_WIN32

View File

@ -33,6 +33,7 @@
#include "platform/platform.hpp"
#include "types/repertory.hpp"
#include "utils/common.hpp"
#include "utils/time.hpp"
using namespace repertory;
using namespace repertory::remote_winfsp;
@ -429,7 +430,7 @@ static void set_basic_info_test(remote_client &client) {
const auto change_time = last_write_time;
#else
const auto creation_time =
utils::unix_time_to_windows_time(utils::time::get_time_now());
utils::time::unix_time_to_windows_time(utils::time::get_time_now());
const auto last_access_time = creation_time + 1;
const auto last_write_time = creation_time + 2;
const auto change_time = last_write_time;

View File

@ -25,7 +25,9 @@
#include "utils/config.hpp"
namespace repertory::utils::time {
inline constexpr const auto NANOS_PER_SECOND = 1000000000L;
inline constexpr const auto NANOS_PER_SECOND = 1000000000ULL;
inline constexpr const auto WIN32_TIME_CONVERSION{116444736000000000ULL};
inline constexpr const auto WIN32_TIME_NANOS_PER_TICK{100ULL};
#if defined(PROJECT_ENABLE_SPDLOG) || defined(PROJECT_ENABLE_FMT)
[[nodiscard]] inline auto convert_to_utc(time_t time) -> std::time_t {
@ -57,6 +59,12 @@ auto strptime(const char *s, const char *f, struct tm *tm) -> const char *;
[[nodiscard]] auto unix_time_to_filetime(std::uint64_t unix_time) -> FILETIME;
#endif // defined(_WIN32)
[[nodiscard]] auto
unix_time_to_windows_time(std::uint64_t unix_time) -> std::uint64_t;
[[nodiscard]] auto
windows_time_to_unix_time(std::uint64_t win_time) -> std::uint64_t;
} // namespace repertory::utils::time
#endif // REPERTORY_INCLUDE_UTILS_TIME_HPP_

View File

@ -28,9 +28,9 @@ 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 -= 116444736000000000LL;
date.QuadPart -= WIN32_TIME_CONVERSION;
return static_cast<std::uint64_t>(date.QuadPart) * 100ULL;
return static_cast<std::uint64_t>(date.QuadPart) * WIN32_TIME_NANOS_PER_TICK;
}
#endif // defined(_WIN32)
@ -47,11 +47,10 @@ void get_local_time_now(struct tm &local_time) {
}
auto get_time_now() -> std::uint64_t {
#if defined(_WIN32)
return static_cast<std::uint64_t>(_time64(nullptr));
#else // !defined(_WIN32)
return static_cast<std::uint64_t>(time(nullptr));
#endif // defined(_WIN32)
return static_cast<std::uint64_t>(
std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::system_clock::now().time_since_epoch())
.count());
}
#if defined(_WIN32)
@ -73,11 +72,20 @@ auto time64_to_unix_time(const __time64_t &time) -> std::uint64_t {
// 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 / 100ULL) + 116444736000000000ULL;
auto win_time =
(unix_time / WIN32_TIME_NANOS_PER_TICK) + WIN32_TIME_CONVERSION;
FILETIME file_time{};
file_time.dwHighDateTime = static_cast<DWORD>(win_time >> 32U);
file_time.dwLowDateTime = win_time & 0xFFFFFFFF;
return file_time;
}
#endif // defined(_WIN32)
auto unix_time_to_windows_time(std::uint64_t unix_time) -> std::uint64_t {
return (unix_time / WIN32_TIME_NANOS_PER_TICK) + WIN32_TIME_CONVERSION;
}
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;
}
} // namespace repertory::utils::time