updated build system

This commit is contained in:
2024-08-02 11:14:28 -05:00
parent 1cebaf83e1
commit a383fb405e
27 changed files with 113 additions and 132 deletions

View File

@ -42,7 +42,7 @@ const curl_comm::write_callback curl_comm::write_headers =
void *outstream) -> size_t {
auto &headers = *reinterpret_cast<http_headers *>(outstream);
const auto header = std::string(buffer, size * nitems);
const auto parts = utils::string::split(header, ':');
const auto parts = utils::string::split(header, ':', false);
if (parts.size() > 1U) {
auto data = header.substr(parts[0U].size() + 1U);
utils::string::left_trim(data);
@ -101,7 +101,7 @@ auto curl_comm::create_host_config(const s3_config &cfg,
auto pos = cfg.url.find(':');
host_cfg.host_name_or_ip = cfg.url.substr(pos + 3U);
if (cfg.use_region_in_url && not cfg.region.empty()) {
auto parts = utils::string::split(host_cfg.host_name_or_ip, '.', false);
auto parts = utils::string::split(host_cfg.host_name_or_ip, '.', true);
if (parts.size() > 1U) {
parts.insert(parts.begin() + 1U, cfg.region);
host_cfg.host_name_or_ip = utils::string::join(parts, '.');

View File

@ -27,6 +27,7 @@
#include "types/repertory.hpp"
#include "utils/error_utils.hpp"
#include "utils/file_utils.hpp"
#include "utils/time.hpp"
#include "utils/unix/unix_utils.hpp"
#include "utils/utils.hpp"
@ -57,7 +58,7 @@ auto eviction::check_minimum_requirements(const std::string &file_path)
static_cast<time_t>(reference_time)) +
delay) <= now);
#else
const auto now = utils::get_time_now();
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<std::uint64_t>(delay)) <= now);

View File

@ -631,10 +631,10 @@ auto fuse_base::parse_args(std::vector<std::string> &args) -> int {
options = args[i].substr(2);
}
const auto option_parts = utils::string::split(options, ',');
const auto option_parts = utils::string::split(options, ',', true);
for (const auto &option : option_parts) {
if (option.find("gid") == 0) {
const auto parts = utils::string::split(option, '=');
const auto parts = utils::string::split(option, '=', true);
if (parts.size() == 2u) {
auto gid = getgrnam(parts[1].c_str());
if (not gid) {
@ -650,7 +650,7 @@ auto fuse_base::parse_args(std::vector<std::string> &args) -> int {
} else if (option.find("noatime") == 0) {
atime_enabled_ = false;
} else if (option.find("uid") == 0) {
const auto parts = utils::string::split(option, '=');
const auto parts = utils::string::split(option, '=', true);
if (parts.size() == 2u) {
auto *uid = getpwnam(parts[1u].c_str());
if (not uid) {
@ -664,7 +664,7 @@ auto fuse_base::parse_args(std::vector<std::string> &args) -> int {
}
}
} else if (option.find("umask") == 0) {
const auto parts = utils::string::split(option, '=');
const auto parts = utils::string::split(option, '=', true);
if (parts.size() == 2u) {
static const auto match_number_regex = std::regex("[0-9]+");
try {

View File

@ -43,6 +43,7 @@
#include "utils/error_utils.hpp"
#include "utils/file_utils.hpp"
#include "utils/polling.hpp"
#include "utils/time.hpp"
#include "utils/utils.hpp"
namespace repertory {
@ -163,7 +164,7 @@ auto fuse_drive::create_impl(std::string api_path, mode_t mode,
{
std::shared_ptr<i_open_file> open_file;
if (is_create_op) {
const auto now = utils::get_file_time_now();
const auto now = utils::time::get_file_time_now();
#if defined(__APPLE__)
const auto osx_flags = static_cast<std::uint32_t>(file_info->flags);
#else
@ -604,7 +605,7 @@ auto fuse_drive::mkdir_impl(std::string api_path, mode_t mode) -> api_error {
return res;
}
const auto now = utils::get_file_time_now();
const auto now = utils::time::get_file_time_now();
auto meta = create_meta_attributes(now, FILE_ATTRIBUTE_DIRECTORY, now, now,
true, get_effective_gid(), "", mode, now,
0U, 0U, 0U, "", get_effective_uid(), now);
@ -1299,14 +1300,14 @@ auto fuse_drive::utimens_impl(std::string api_path,
meta.clear();
if ((tv == nullptr) || (tv[0U].tv_nsec == UTIME_NOW)) {
meta[META_ACCESSED] = std::to_string(utils::get_file_time_now());
meta[META_ACCESSED] = std::to_string(utils::time::get_file_time_now());
} else if (tv[0U].tv_nsec != UTIME_OMIT) {
const auto val = tv[0U].tv_nsec + (tv[0U].tv_sec * NANOS_PER_SECOND);
meta[META_ACCESSED] = std::to_string(val);
}
if ((tv == nullptr) || (tv[1U].tv_nsec == UTIME_NOW)) {
meta[META_MODIFIED] = std::to_string(utils::get_file_time_now());
meta[META_MODIFIED] = std::to_string(utils::time::get_file_time_now());
} else if (tv[1U].tv_nsec != UTIME_OMIT) {
const auto val = tv[1U].tv_nsec + (tv[1U].tv_sec * NANOS_PER_SECOND);
meta[META_MODIFIED] = std::to_string(val);
@ -1355,7 +1356,8 @@ void fuse_drive::update_accessed_time(const std::string &api_path) {
if (atime_enabled_) {
auto res = provider_.set_item_meta(
api_path, META_ACCESSED, std::to_string(utils::get_file_time_now()));
api_path, META_ACCESSED,
std::to_string(utils::time::get_file_time_now()));
if (res != api_error::success) {
utils::error::raise_api_path_error(function_name, api_path, res,
"failed to set accessed time");

View File

@ -782,7 +782,7 @@ auto remote_server::fuse_utimens(const char *path, const remote::file_time *tv,
FILETIME *write_time_ptr = nullptr;
if ((tv[0U] == 0U) || (op0 == UTIME_NOW)) {
const auto now = utils::get_file_time_now();
const auto now = utils::time::get_file_time_now();
access_time.dwHighDateTime =
static_cast<DWORD>((now >> 32U) & 0xFFFFFFFF);
access_time.dwLowDateTime = now & 0xFFFFFFFF;
@ -793,7 +793,7 @@ auto remote_server::fuse_utimens(const char *path, const remote::file_time *tv,
}
if ((tv[1U] == 0U) || (op1 == UTIME_NOW)) {
const auto now = utils::get_file_time_now();
const auto now = utils::time::get_file_time_now();
write_time.dwHighDateTime = static_cast<DWORD>((now >> 32U) & 0xFFFFFFFF);
write_time.dwLowDateTime = now & 0xFFFFFFFF;
write_time_ptr = &write_time;

View File

@ -33,6 +33,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_winfsp {
@ -224,7 +225,7 @@ auto remote_winfsp_drive::Init(PVOID host) -> NTSTATUS {
file_system_host->SetPersistentAcls(FALSE);
file_system_host->SetPostCleanupWhenModifiedOnly(TRUE);
file_system_host->SetPassQueryDirectoryPattern(FALSE);
file_system_host->SetVolumeCreationTime(utils::get_file_time_now());
file_system_host->SetVolumeCreationTime(utils::time::get_file_time_now());
file_system_host->SetVolumeSerialNumber(0);
return STATUS_SUCCESS;
}

View File

@ -37,6 +37,7 @@
#include "utils/file_utils.hpp"
#include "utils/polling.hpp"
#include "utils/string.hpp"
#include "utils/time.hpp"
#include "utils/utils.hpp"
namespace repertory {
@ -205,7 +206,7 @@ VOID winfsp_drive::Cleanup(PVOID file_node, PVOID file_desc,
if ((flags & (FspCleanupSetLastAccessTime | FspCleanupSetLastWriteTime |
FspCleanupSetChangeTime)) != 0U) {
const auto now = utils::get_file_time_now();
const auto now = utils::time::get_file_time_now();
if ((flags & FspCleanupSetLastAccessTime) != 0U) {
auto res = provider_.set_item_meta(api_path, META_ACCESSED,
std::to_string(now));
@ -296,7 +297,7 @@ auto winfsp_drive::Create(PWSTR file_name, UINT32 create_options,
attributes = FILE_ATTRIBUTE_NORMAL;
}
const auto now = utils::get_file_time_now();
const auto now = utils::time::get_file_time_now();
auto meta = create_meta_attributes(
now, attributes, now, now, (attributes & FILE_ATTRIBUTE_DIRECTORY) != 0U,
0U, "", 0U, now, 0U, 0U, 0U,
@ -553,7 +554,7 @@ auto winfsp_drive::Init(PVOID host) -> NTSTATUS {
file_system_host->SetPersistentAcls(FALSE);
file_system_host->SetPostCleanupWhenModifiedOnly(TRUE);
file_system_host->SetPassQueryDirectoryPattern(FALSE);
file_system_host->SetVolumeCreationTime(utils::get_file_time_now());
file_system_host->SetVolumeCreationTime(utils::time::get_file_time_now());
file_system_host->SetVolumeSerialNumber(0);
return STATUS_SUCCESS;
}
@ -834,7 +835,7 @@ auto winfsp_drive::Read(PVOID /*file_node*/, PVOID file_desc, PVOID buffer,
data.clear();
auto res = provider_.set_item_meta(
api_path, META_ACCESSED,
std::to_string(utils::get_file_time_now()));
std::to_string(utils::time::get_file_time_now()));
if (res != api_error::success) {
utils::error::raise_api_path_error(
function_name, api_path, res,

View File

@ -506,7 +506,7 @@ void file_manager::queue_upload(const std::string &api_path,
.or_replace()
.column_value("api_path", api_path)
.column_value("date_time",
static_cast<std::int64_t>(utils::get_file_time_now()))
static_cast<std::int64_t>(utils::time::get_file_time_now()))
.column_value("source_path", source_path)
.go();
if (result.ok()) {

View File

@ -28,6 +28,7 @@
#include "utils/error_utils.hpp"
#include "utils/file_utils.hpp"
#include "utils/path.hpp"
#include "utils/time.hpp"
#include "utils/unix/unix_utils.hpp"
#include "utils/utils.hpp"
@ -327,7 +328,7 @@ auto file_manager::open_file::native_operation(
set_modified();
fsi_.size = new_file_size;
const auto now = std::to_string(utils::get_file_time_now());
const auto now = std::to_string(utils::time::get_file_time_now());
res = provider_.set_item_meta(
fsi_.api_path, {
{META_CHANGED, now},
@ -346,8 +347,8 @@ auto file_manager::open_file::native_operation(
}
auto file_manager::open_file::read(std::size_t read_size,
std::uint64_t read_offset, data_buffer &data)
-> api_error {
std::uint64_t read_offset,
data_buffer &data) -> api_error {
if (fsi_.directory) {
return api_error::invalid_operation;
}
@ -591,7 +592,7 @@ auto file_manager::open_file::write(std::uint64_t write_offset,
return set_api_error(res);
}
const auto now = std::to_string(utils::get_file_time_now());
const auto now = std::to_string(utils::time::get_file_time_now());
res = provider_.set_item_meta(fsi_.api_path, {
{META_CHANGED, now},
{META_MODIFIED, now},

View File

@ -31,6 +31,7 @@
#include "utils/file_utils.hpp"
#include "utils/path.hpp"
#include "utils/polling.hpp"
#include "utils/time.hpp"
namespace repertory {
auto base_provider::create_api_file(std::string path, std::string key,
@ -38,10 +39,10 @@ auto base_provider::create_api_file(std::string path, std::string key,
api_file file{};
file.api_path = utils::path::create_api_path(path);
file.api_parent = utils::path::get_parent_api_path(file.api_path);
file.accessed_date = utils::get_file_time_now();
file.changed_date = utils::get_file_time_now();
file.creation_date = utils::get_file_time_now();
file.modified_date = utils::get_file_time_now();
file.accessed_date = utils::time::get_file_time_now();
file.changed_date = utils::time::get_file_time_now();
file.creation_date = utils::time::get_file_time_now();
file.modified_date = utils::time::get_file_time_now();
file.key = key;
file.file_size = size;
return file;
@ -66,8 +67,8 @@ auto base_provider::create_api_file(std::string path, std::uint64_t size,
}
auto base_provider::create_directory_clone_source_meta(
const std::string &source_api_path, const std::string &api_path)
-> api_error {
const std::string &source_api_path,
const std::string &api_path) -> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
bool exists{};
@ -164,8 +165,8 @@ auto base_provider::create_directory(const std::string &api_path,
return set_item_meta(api_path, meta);
}
auto base_provider::create_file(const std::string &api_path, api_meta_map &meta)
-> api_error {
auto base_provider::create_file(const std::string &api_path,
api_meta_map &meta) -> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
bool exists{};
@ -222,9 +223,8 @@ auto base_provider::create_file(const std::string &api_path, api_meta_map &meta)
return api_error::error;
}
auto base_provider::get_api_path_from_source(const std::string &source_path,
std::string &api_path) const
-> api_error {
auto base_provider::get_api_path_from_source(
const std::string &source_path, std::string &api_path) const -> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
if (source_path.empty()) {
@ -237,9 +237,8 @@ auto base_provider::get_api_path_from_source(const std::string &source_path,
return db3_->get_api_path(source_path, api_path);
}
auto base_provider::get_directory_items(const std::string &api_path,
directory_item_list &list) const
-> api_error {
auto base_provider::get_directory_items(
const std::string &api_path, directory_item_list &list) const -> api_error {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
bool exists{};
@ -303,10 +302,9 @@ auto base_provider::get_file_size(const std::string &api_path,
return api_error::success;
}
auto base_provider::get_filesystem_item(const std::string &api_path,
bool directory,
filesystem_item &fsi) const
-> api_error {
auto base_provider::get_filesystem_item(
const std::string &api_path, bool directory,
filesystem_item &fsi) const -> api_error {
bool exists{};
auto res = is_directory(api_path, exists);
if (res != api_error::success) {
@ -339,10 +337,9 @@ auto base_provider::get_filesystem_item(const std::string &api_path,
return api_error::success;
}
auto base_provider::get_filesystem_item_and_file(const std::string &api_path,
api_file &file,
filesystem_item &fsi) const
-> api_error {
auto base_provider::get_filesystem_item_and_file(
const std::string &api_path, api_file &file,
filesystem_item &fsi) const -> api_error {
auto res = get_file(api_path, file);
if (res != api_error::success) {
return res;

View File

@ -27,8 +27,9 @@
#include "events/event_system.hpp"
#include "events/events.hpp"
#include "types/repertory.hpp"
#include "utils/encrypting_reader.hpp"
#include "utils/collection.hpp"
#include "utils/encrypt.hpp"
#include "utils/encrypting_reader.hpp"
#include "utils/path.hpp"
#include "utils/polling.hpp"
@ -186,8 +187,8 @@ auto encrypt_provider::do_fs_operation(
source_path = utils::path::combine(cfg.path, {source_path});
if (source_path != cfg.path &&
not source_path.starts_with(cfg.path +
utils::path::directory_seperator)) {
not source_path.starts_with(
cfg.path + std::string{utils::path::directory_seperator})) {
return directory ? api_error::directory_not_found
: api_error::item_not_found;
}
@ -697,7 +698,8 @@ auto encrypt_provider::process_directory_entry(
strnlen(encrypted_parts.at(part_idx).c_str(),
encrypted_parts.at(part_idx).size()),
encrypted_data);
encrypted_parts[part_idx] = utils::to_hex_string(encrypted_data);
encrypted_parts[part_idx] =
utils::collection::to_hex_string(encrypted_data);
}
std::size_t current_idx{1U};

View File

@ -28,6 +28,7 @@
#include "types/repertory.hpp"
#include "types/s3.hpp"
#include "types/startup_exception.hpp"
#include "utils/collection.hpp"
#include "utils/encrypt.hpp"
#include "utils/encrypting_reader.hpp"
#include "utils/error_utils.hpp"
@ -35,6 +36,7 @@
#include "utils/path.hpp"
#include "utils/polling.hpp"
#include "utils/string.hpp"
#include "utils/time.hpp"
namespace repertory {
s3_provider::s3_provider(app_config &config, i_http_comm &comm)
@ -83,7 +85,7 @@ auto s3_provider::create_directory_impl(const std::string &api_path,
meta[META_KEY] = utils::path::create_api_path(
utils::path::combine(utils::path::create_api_path(encrypted_file_path),
{utils::to_hex_string(result)}));
{utils::collection::to_hex_string(result)}));
}
const auto object_name =
@ -132,7 +134,7 @@ auto s3_provider::create_file_extra(const std::string &api_path,
meta[META_KEY] = utils::path::create_api_path(
utils::path::combine(utils::path::create_api_path(encrypted_file_path),
{utils::to_hex_string(result)}));
{utils::collection::to_hex_string(result)}));
}
return api_error::success;
@ -384,7 +386,7 @@ auto s3_provider::get_file(const std::string &api_path,
return res;
}
file.accessed_date = utils::get_file_time_now();
file.accessed_date = utils::time::get_file_time_now();
file.api_path = api_path;
file.api_parent = utils::path::get_parent_api_path(file.api_path);
file.changed_date = utils::aws::format_time(result.last_modified);
@ -439,7 +441,7 @@ auto s3_provider::get_file_list(api_file_list &list) const -> api_error {
api_file file{};
file.api_path = utils::path::create_api_path(api_path);
file.api_parent = utils::path::get_parent_api_path(file.api_path);
file.accessed_date = utils::get_file_time_now();
file.accessed_date = utils::time::get_file_time_now();
file.changed_date = utils::convert_api_date(
node.node().select_node("LastModified").node().text().as_string());
file.creation_date = file.changed_date;

View File

@ -42,7 +42,7 @@ auto server::check_authorization(const httplib::Request &req) -> bool {
return false;
}
const auto auth_parts = utils::string::split(authorization, ' ');
const auto auth_parts = utils::string::split(authorization, ' ', true);
if (auth_parts.empty()) {
return false;
}
@ -54,7 +54,7 @@ auto server::check_authorization(const httplib::Request &req) -> bool {
const auto data = macaron::Base64::Decode(authorization.substr(6U));
const auto auth =
utils::string::split(std::string(data.begin(), data.end()), ':');
utils::string::split(std::string(data.begin(), data.end()), ':', true);
if (auth.size() != 2U) {
return false;
}

View File

@ -158,7 +158,7 @@ auto parse_drive_options(
options = drive_args.at(i).substr(2);
}
const auto fuse_option_list = utils::string::split(options, ',');
const auto fuse_option_list = utils::string::split(options, ',', true);
for (const auto &fuse_option : fuse_option_list) {
if (fuse_option.find("s3") == 0) {
prov = provider_type::s3;
@ -166,7 +166,7 @@ auto parse_drive_options(
}
if ((fuse_option.find("dd") == 0) ||
(fuse_option.find("data_directory") == 0)) {
const auto data = utils::string::split(fuse_option, '=');
const auto data = utils::string::split(fuse_option, '=', true);
if (data.size() == 2U) {
data_directory = data.at(1U);
} else {

View File

@ -24,6 +24,7 @@
#include "events/event_system.hpp"
#include "events/events.hpp"
#include "types/repertory.hpp"
#include "utils/collection.hpp"
#include "utils/encrypting_reader.hpp"
#include "utils/utils.hpp"
@ -52,7 +53,7 @@ auto decrypt_file_path(std::string_view encryption_token,
auto decrypt_file_name(std::string_view encryption_token,
std::string &file_name) -> api_error {
data_buffer buffer;
if (not utils::from_hex_string(file_name, buffer)) {
if (not utils::collection::from_hex_string(file_name, buffer)) {
return api_error::error;
}

View File

@ -24,6 +24,7 @@
#include "events/event_system.hpp"
#include "events/events.hpp"
#include "types/repertory.hpp"
#include "utils/collection.hpp"
#include "utils/encrypt.hpp"
#include "utils/error_utils.hpp"
#include "utils/utils.hpp"
@ -181,14 +182,14 @@ encrypting_reader::encrypting_reader(
utils::encryption::encrypt_data(
key_, reinterpret_cast<const unsigned char *>(file_name.data()),
file_name.size(), result);
encrypted_file_name_ = utils::to_hex_string(result);
encrypted_file_name_ = utils::collection::to_hex_string(result);
if (relative_parent_path.has_value()) {
for (auto &&part : std::filesystem::path(relative_parent_path.value())) {
utils::encryption::encrypt_data(
key_, reinterpret_cast<const unsigned char *>(part.string().c_str()),
strnlen(part.string().c_str(), part.string().size()), result);
encrypted_file_path_ += '/' + utils::to_hex_string(result);
encrypted_file_path_ += '/' + utils::collection::to_hex_string(result);
}
encrypted_file_path_ += '/' + encrypted_file_name_;
}

View File

@ -22,9 +22,11 @@
#include "utils/file_utils.hpp"
#include "types/repertory.hpp"
#include "utils/collection.hpp"
#include "utils/error_utils.hpp"
#include "utils/path.hpp"
#include "utils/string.hpp"
#include "utils/time.hpp"
#include "utils/utils.hpp"
namespace repertory::utils::file {
@ -173,8 +175,8 @@ auto create_full_directory_path(std::string path) -> bool {
(::SHCreateDirectory(nullptr, unicode_path.c_str()) == ERROR_SUCCESS);
#else
auto ret = true;
const auto paths = utils::string::split(utils::path::absolute(path),
utils::path::directory_seperator[0U]);
const auto paths = utils::string::split(
utils::path::absolute(path), utils::path::directory_seperator[0U], false);
std::string current_path;
for (std::size_t i = 0U; ret && (i < paths.size()); i++) {
if (paths[i].empty()) { // Skip root
@ -310,7 +312,7 @@ auto generate_sha256(const std::string &file_path) -> std::string {
std::to_string(res));
}
return utils::to_hex_string(out);
return utils::collection::to_hex_string(out);
}
auto get_free_drive_space(const std::string &path) -> std::uint64_t {
@ -497,7 +499,7 @@ auto is_modified_date_older_than(const std::string &path,
#else
return (modified +
static_cast<std::uint64_t>(seconds.count() * NANOS_PER_SECOND)) <
utils::get_time_now();
utils::time::get_time_now();
#endif
}
return ret;

View File

@ -54,10 +54,10 @@ void calculate_allocation_size(bool directory, std::uint64_t file_size,
auto convert_api_date(const std::string &date) -> std::uint64_t {
// 2009-10-12T17:50:30.000Z
const auto date_parts = utils::string::split(date, '.');
const auto date_parts = utils::string::split(date, '.', true);
const auto date_time = date_parts[0U];
const auto nanos =
utils::string::to_uint64(utils::string::split(date_parts[1U], 'Z')[0U]);
const auto nanos = utils::string::to_uint64(
utils::string::split(date_parts[1U], 'Z', true)[0U]);
struct tm tm1 {};
#if defined(_WIN32)