updated build system

This commit is contained in:
Scott E. Graves 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)

View File

@ -77,7 +77,7 @@ auto main(int argc, char **argv) -> int {
res = utils::cli::parse_string_option(
args, utils::cli::options::remote_mount_option, data);
if (res == exit_code::success) {
const auto parts = utils::string::split(data, ':');
const auto parts = utils::string::split(data, ':', false);
if (parts.size() != 2) {
std::cerr << "Invalid syntax for host/port '-rm "
"host:port,--remote_mount host:port'"

View File

@ -30,6 +30,7 @@
#include "types/repertory.hpp"
#include "utils/file_utils.hpp"
#include "utils/path.hpp"
#include "utils/time.hpp"
#include "utils/utils.hpp"
namespace repertory {
@ -67,10 +68,10 @@ public:
dir_item.size = 0;
dir_item.meta = {
{META_ATTRIBUTES, "16"},
{META_MODIFIED, std::to_string(utils::get_file_time_now())},
{META_WRITTEN, std::to_string(utils::get_file_time_now())},
{META_ACCESSED, std::to_string(utils::get_file_time_now())},
{META_CREATION, std::to_string(utils::get_file_time_now())}};
{META_MODIFIED, std::to_string(utils::time::get_file_time_now())},
{META_WRITTEN, std::to_string(utils::time::get_file_time_now())},
{META_ACCESSED, std::to_string(utils::time::get_file_time_now())},
{META_CREATION, std::to_string(utils::time::get_file_time_now())}};
list.emplace_back(dir_item);
dir_item.api_path = "..";

View File

@ -28,6 +28,7 @@
#include "drives/winfsp/i_winfsp_drive.hpp"
#include "utils/file_utils.hpp"
#include "utils/path.hpp"
#include "utils/time.hpp"
#include "utils/utils.hpp"
namespace repertory {
@ -53,11 +54,12 @@ public:
di.api_path = ".";
di.directory = true;
di.size = 0u;
di.meta = {{META_ATTRIBUTES, "16"},
{META_MODIFIED, std::to_string(utils::get_file_time_now())},
{META_WRITTEN, std::to_string(utils::get_file_time_now())},
{META_ACCESSED, std::to_string(utils::get_file_time_now())},
{META_CREATION, std::to_string(utils::get_file_time_now())}};
di.meta = {
{META_ATTRIBUTES, "16"},
{META_MODIFIED, std::to_string(utils::time::get_file_time_now())},
{META_WRITTEN, std::to_string(utils::time::get_file_time_now())},
{META_ACCESSED, std::to_string(utils::time::get_file_time_now())},
{META_CREATION, std::to_string(utils::time::get_file_time_now())}};
list.emplace_back(di);
di.api_path = "..";

View File

@ -22,8 +22,10 @@
#include "test_common.hpp"
#include "types/repertory.hpp"
#include "utils/collection.hpp"
#include "utils/encrypt.hpp"
#include "utils/file_utils.hpp"
#include "utils/string.hpp"
namespace repertory {
static const std::string buffer = "cow moose dog chicken";
@ -41,7 +43,7 @@ static void test_encrypted_result(const data_buffer &result) {
TEST(encryption, generate_key) {
const auto key = utils::encryption::generate_key(token);
const auto str = utils::to_hex_string(key);
const auto str = utils::collection::to_hex_string(key);
EXPECT_STREQ(
"182072537ada59e4d6b18034a80302ebae935f66adbdf0f271d3d36309c2d481",
str.c_str());

View File

@ -36,6 +36,7 @@
#include "utils/path.hpp"
#include "utils/polling.hpp"
#include "utils/string.hpp"
#include "utils/time.hpp"
#include "utils/utils.hpp"
namespace repertory {
@ -115,7 +116,7 @@ TEST(file_manager, can_create_and_close_file) {
{
std::shared_ptr<i_open_file> f;
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_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u,
now + 2u, false, 1, "key", 2, now + 3u, 3u, 4u, 0u, source_path, 10,
@ -230,7 +231,7 @@ TEST(file_manager, can_open_and_close_file) {
std::uint64_t handle{};
{
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_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u,
now + 2u, false, 1, "key", 2, now + 3u, 3u, 4u, 0u, source_path, 10,
@ -337,7 +338,7 @@ TEST(file_manager, can_open_and_close_multiple_handles_for_same_file) {
const auto source_path = utils::path::combine(
cfg.get_cache_directory(), {utils::create_uuid_string()});
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_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u,
now + 2u, false, 1, "key", 2, now + 3u, 3u, 4u, 0u, source_path, 10,
@ -417,7 +418,7 @@ TEST(file_manager, download_is_stored_after_write_if_partially_downloaded) {
event_capture ec({"download_stored"},
{"file_upload_completed", "file_upload_queued"});
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_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u,
false, 1, "key", 2, now + 3u, 3u, 4u,
@ -580,7 +581,7 @@ TEST(file_manager, upload_occurs_after_write_if_fully_downloaded) {
});
event_capture ec({"download_end"});
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_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u,
false, 1, "key", 2, now + 3u, 3u, 4u,
@ -691,7 +692,7 @@ TEST(file_manager, can_evict_file) {
const auto source_path = utils::path::combine(
cfg.get_cache_directory(), {utils::create_uuid_string()});
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_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u,
@ -957,7 +958,7 @@ TEST(file_manager, evict_file_fails_if_file_is_uploading) {
const auto source_path = utils::path::combine(
cfg.get_cache_directory(), {utils::create_uuid_string()});
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_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u,
@ -1189,7 +1190,7 @@ TEST(file_manager, file_is_not_opened_if_provider_create_file_fails) {
EXPECT_CALL(mp, is_direct_only()).WillRepeatedly(Return(false));
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_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u,
false, 1, "", 2, now + 3u, 3u, 4u, 0u, "/test_create.src", 10,
@ -1741,7 +1742,7 @@ TEST(file_manager, file_is_closed_after_download_timeout) {
ee.get_api_path().get<std::string>().c_str());
});
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_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u,
false, 1, "key", 2, now + 3u, 3u, 4u,

View File

@ -33,8 +33,8 @@
#include "utils/file_utils.hpp"
#include "utils/path.hpp"
#include "utils/string.hpp"
#include "utils/time.hpp"
#include "utils/utils.hpp"
#include "gtest/gtest.h"
namespace {
#if defined(_WIN32)
@ -57,7 +57,7 @@ const auto check_forced_dirs = [](const repertory::directory_item_list &list) {
const auto create_directory = [](repertory::i_provider &provider,
const std::string &api_path) {
auto date = repertory::utils::get_file_time_now();
auto date = repertory::utils::time::get_file_time_now();
auto meta = repertory::create_meta_attributes(
date, 1U, date + 1U, date + 2U, true, getgid(), "", 0700, date + 3U, 2U,
3U, 0U, api_path + "_src", getuid(), date + 4U);
@ -110,7 +110,7 @@ const auto create_file = [](repertory::i_provider &provider,
auto source_path = repertory::generate_test_file_name(
repertory::get_test_dir(), "providers_test");
auto date = repertory::utils::get_file_time_now();
auto date = repertory::utils::time::get_file_time_now();
auto meta = repertory::create_meta_attributes(
date, 1U, date + 1U, date + 2U, false, getgid(), "", 0700, date + 3U, 2U,
3U, 0U, source_path, getuid(), date + 4U);

View File

@ -34,6 +34,7 @@
#endif
#include "drives/fuse/remotefuse/remote_client.hpp"
#include "types/repertory.hpp"
#include "utils/time.hpp"
#include "utils/utils.hpp"
using namespace repertory;
@ -685,7 +686,7 @@ static void setbkuptime_test(repertory::remote_fuse::remote_client &client) {
if (ret == 0) {
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
remote::file_time ts = utils::get_file_time_now();
remote::file_time ts = utils::time::get_file_time_now();
#if defined(_WIN32)
EXPECT_EQ(NOT_IMPLEMENTED, client.fuse_setbkuptime(api_path.c_str(), ts));
#else
@ -710,7 +711,7 @@ static void setchgtime_test(repertory::remote_fuse::remote_client &client) {
if (ret == 0) {
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
remote::file_time ts = utils::get_file_time_now();
remote::file_time ts = utils::time::get_file_time_now();
#if defined(_WIN32)
EXPECT_EQ(NOT_IMPLEMENTED, client.fuse_setchgtime(api_path.c_str(), ts));
#else
@ -735,7 +736,7 @@ static void setcrtime_test(repertory::remote_fuse::remote_client &client) {
if (ret == 0) {
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
remote::file_time ts = utils::get_file_time_now();
remote::file_time ts = utils::time::get_file_time_now();
#if defined(_WIN32)
EXPECT_EQ(NOT_IMPLEMENTED, client.fuse_setcrtime(api_path.c_str(), ts));
#else

View File

@ -56,7 +56,7 @@ decrypt_data(const key_type &key, const unsigned char *buffer,
res.resize(buffer_size - encryption_header_size);
return crypto_aead_xchacha20poly1305_ietf_decrypt_detached(
reinterpret_cast<unsigned char *>(res.data()), nullptr,
&buffer[header_size], res.size(),
&buffer[encryption_header_size], res.size(),
&buffer[crypto_aead_xchacha20poly1305_IETF_NPUBBYTES],
reinterpret_cast<const unsigned char *>(&size), sizeof(size),
buffer, key.data()) == 0;

View File

@ -86,12 +86,6 @@ inline auto replace(string_t &src,
std::basic_string_view<typename string_t::value_type> with,
std::size_t start_pos = 0U) -> string_t &;
template <typename t>
[[nodiscard]] auto from_hex_string(const std::string &str, t &val) -> bool;
template <typename collection_t>
[[nodiscard]] auto to_hex_string(const collection_t &collection) -> std::string;
template <typename string_t>
[[nodiscard]] inline auto replace_copy(string_t src,
typename string_t::value_type character,
@ -460,37 +454,6 @@ inline auto split(std::wstring_view str, std::wstring_view delim,
bool should_trim) -> std::vector<std::wstring> {
return split_t<std::wstring>(str, delim, should_trim);
}
template <typename t>
auto from_hex_string(const std::string &str, t &val) -> bool {
static constexpr const auto base16 = 16;
val.clear();
if (not(str.length() % 2U)) {
for (std::size_t i = 0U; i < str.length(); i += 2U) {
val.emplace_back(static_cast<typename t::value_type>(
strtol(str.substr(i, 2U).c_str(), nullptr, base16)));
}
return true;
}
return false;
}
template <typename collection_t>
auto to_hex_string(const collection_t &collection) -> std::string {
static_assert(sizeof(typename collection_t::value_type) == 1U,
"value_type must be 1 byte in size");
static constexpr const auto mask = 0xFF;
std::stringstream stream;
for (auto &&val : collection) {
stream << std::setfill('0') << std::setw(2) << std::hex
<< (static_cast<std::uint32_t>(val) & mask);
}
return stream.str();
}
} // namespace repertory::utils::string
#endif // REPERTORY_INCLUDE_UTILS_STRING_HPP_