updated build system

This commit is contained in:
2024-08-28 11:00:44 -05:00
parent f0b31aa7b2
commit 82b3efff0c
29 changed files with 358 additions and 188 deletions

View File

@ -1,18 +1,18 @@
set(BINUTILS_VERSION 2.41)
set(BOOST2_MAJOR_VERSION 1)
set(BOOST2_MINOR_VERSION 76)
set(BOOST2_PATCH_VERSION 0)
set(BOOST_MAJOR_VERSION 1)
set(BOOST_MINOR_VERSION 85)
set(BOOST_PATCH_VERSION 0)
set(BOOST2_MAJOR_VERSION 1)
set(BOOST2_MINOR_VERSION 76)
set(BOOST2_PATCH_VERSION 0)
set(CLI11_VERSION 2.4.2)
set(CPP_HTTPLIB_VERSION 0.16.3)
set(CURL2_VERSION 8_9_1)
set(CURL_VERSION 8.9.1)
set(CURL2_VERSION 8_9_1)
set(CXXOPTS_VERSION 3.2.1)
set(DTL_VERSION 2.01)
set(EXPAT2_VERSION 2_6_2)
set(EXPAT_VERSION 2.6.2)
set(EXPAT2_VERSION 2_6_2)
set(FLAC_VERSION 1.4.3)
set(FMT_VERSION 11.0.2)
set(FONTCONFIG_VERSION 2.15.0)
@ -44,8 +44,8 @@ set(SDL_VERSION 2.30.6)
set(SECP256K1_VERSION 0.1.0.20)
set(SFML_VERSION 2.6.1)
set(SPDLOG_VERSION 1.14.1)
set(SQLITE2_VERSION 3.46.1)
set(SQLITE_VERSION 3460100)
set(SQLITE2_VERSION 3.46.1)
set(STDUUID_VERSION 1.2.3)
set(VLC_VERSION 3.0)
set(VORBIS_VERSION 1.3.7)

View File

@ -73,10 +73,9 @@ private:
const std::string &source_path)>
callback) const -> api_error;
auto
process_directory_entry(const std::filesystem::directory_entry &dir_entry,
const encrypt_config &cfg,
std::string &api_path) const -> bool;
auto process_directory_entry(const utils::file::i_fs_item &dir_entry,
const encrypt_config &cfg,
std::string &api_path) const -> bool;
void remove_deleted_files();

View File

@ -150,28 +150,28 @@ enum class provider_type : std::size_t {
};
#if defined(_WIN32)
struct open_file_data {
struct open_file_data final {
void *directory_buffer{};
};
#else
using open_file_data = int;
#endif
struct api_file {
std::string api_path;
std::string api_parent;
struct api_file final {
std::string api_path{};
std::string api_parent{};
std::uint64_t accessed_date{};
std::uint64_t changed_date{};
std::uint64_t creation_date{};
std::uint64_t file_size{};
std::string key;
std::string key{};
std::uint64_t modified_date{};
std::string source_path;
};
struct directory_item {
std::string api_path;
std::string api_parent;
struct directory_item final {
std::string api_path{};
std::string api_parent{};
bool directory{false};
std::uint64_t size{};
api_meta_map meta{};
@ -188,26 +188,30 @@ struct directory_item {
}
[[nodiscard]] auto to_json() const -> json {
return {{"path", api_path},
{"parent", api_parent},
{"size", size},
{"directory", directory},
{"meta", meta}};
return {
{"path", api_path}, {"parent", api_parent}, {"size", size},
{"directory", directory}, {"meta", meta},
};
}
};
struct filesystem_item {
std::string api_path;
std::string api_parent;
bool directory{false};
std::uint64_t size{};
std::string source_path;
struct encrypt_config final {
std::string encryption_token{};
std::string path{};
};
struct host_config {
std::string agent_string;
std::string api_password;
std::string api_user;
struct filesystem_item final {
std::string api_path{};
std::string api_parent{};
bool directory{false};
std::uint64_t size{};
std::string source_path{};
};
struct host_config final {
std::string agent_string{};
std::string api_password{};
std::string api_user{};
std::uint16_t api_port{};
std::string host_name_or_ip{"localhost"};
std::string path{};
@ -263,15 +267,15 @@ from_json(const json &j, host_config &hc) {
j.at("TimeoutMs").get_to(hc.timeout_ms);
}
struct s3_config {
std::string access_key;
std::string bucket;
struct s3_config final {
std::string access_key{};
std::string bucket{};
std::uint16_t cache_timeout_secs{60U};
std::string encryption_token;
std::string encryption_token{};
std::string region{"any"};
std::string secret_key;
std::string secret_key{};
std::uint32_t timeout_ms{60000U};
std::string url;
std::string url{};
bool use_path_style{false};
bool use_region_in_url{false};
};

View File

@ -85,7 +85,7 @@ void directory_cache::service_function() {
auto lookup = directory_lookup_;
directory_lock.unlock();
for (const auto &kv : lookup) {
for (auto &&kv : lookup) {
if (std::chrono::duration_cast<std::chrono::seconds>(
std::chrono::system_clock::now() - kv.second.last_update) >= 120s) {
directory_lock.lock();

View File

@ -437,7 +437,7 @@ auto fuse_base::mount(std::vector<std::string> args) -> int {
auto ret = parse_args(args);
if (ret == 0) {
std::vector<const char *> fuse_argv(args.size());
for (std::size_t i = 0u; i < args.size(); i++) {
for (std::size_t i = 0u; i < args.size(); ++i) {
fuse_argv[i] = args[i].c_str();
}
@ -677,14 +677,14 @@ void fuse_base::notify_fuse_args_parsed(const std::vector<std::string> &args) {
auto fuse_base::parse_args(std::vector<std::string> &args) -> int {
auto force_no_console = false;
for (std::size_t i = 1u; !force_no_console && (i < args.size()); i++) {
for (std::size_t i = 1u; !force_no_console && (i < args.size()); ++i) {
if (args[i] == "-nc") {
force_no_console = true;
}
}
utils::collection::remove_element(args, "-nc");
for (std::size_t i = 1u; i < args.size(); i++) {
for (std::size_t i = 1u; i < args.size(); ++i) {
if (args[i] == "-f") {
console_enabled_ = not force_no_console;
} else if (args[i].find("-o") == 0) {
@ -698,7 +698,7 @@ auto fuse_base::parse_args(std::vector<std::string> &args) -> int {
}
const auto option_parts = utils::string::split(options, ',', true);
for (const auto &option : option_parts) {
for (auto &&option : option_parts) {
if (option.find("gid") == 0) {
const auto parts = utils::string::split(option, '=', true);
if (parts.size() == 2u) {

View File

@ -915,7 +915,7 @@ auto fuse_drive::listxattr_impl(std::string api_path, char *buffer, size_t size,
api_meta_map meta;
if ((res = provider_.get_item_meta(api_path, meta)) == api_error::success) {
for (const auto &meta_item : meta) {
for (auto &&meta_item : meta) {
if (utils::collection::excludes(META_USED_NAMES, meta_item.first)) {
auto attribute_name = meta_item.first;
#if defined(__APPLE__)

View File

@ -166,9 +166,9 @@ auto fuse_drive_base::check_parent_access(const std::string &api_path,
// Ignore root
if (api_path != "/") {
if ((mask & X_OK) == X_OK) {
for (auto parent = utils::path::get_parent_directory(api_path);
for (auto parent = utils::path::get_parent_path(api_path);
(ret == api_error::success) && not parent.empty();
parent = utils::path::get_parent_directory(parent)) {
parent = utils::path::get_parent_path(parent)) {
if (((ret = check_access(parent, X_OK)) == api_error::success) &&
(parent == "/")) {
break;
@ -179,7 +179,7 @@ auto fuse_drive_base::check_parent_access(const std::string &api_path,
if (ret == api_error::success) {
mask &= (~X_OK);
if (mask != 0) {
ret = check_access(utils::path::get_parent_directory(api_path), mask);
ret = check_access(utils::path::get_parent_path(api_path), mask);
}
}
}

View File

@ -39,14 +39,14 @@ void remote_open_file_table::add_directory(const std::string &client_id,
void remote_open_file_table::close_all(const std::string &client_id) {
std::vector<remote::file_handle> compat_handles;
unique_recur_mutex_lock compat_lock(compat_mutex_);
for (auto &kv : compat_lookup_) {
for (auto &&kv : compat_lookup_) {
if (kv.second.client_id == client_id) {
compat_handles.emplace_back(kv.first);
}
}
compat_lock.unlock();
for (auto &handle : compat_handles) {
for (auto &&handle : compat_handles) {
#if defined(_WIN32)
_close(static_cast<int>(handle));
#else
@ -57,14 +57,14 @@ void remote_open_file_table::close_all(const std::string &client_id) {
std::vector<native_handle> handles;
unique_recur_mutex_lock file_lock(file_mutex_);
for (auto &kv : file_lookup_) {
for (auto &&kv : file_lookup_) {
if (kv.second.client_id == client_id) {
handles.emplace_back(kv.first);
}
}
file_lock.unlock();
for (auto &handle : handles) {
for (auto &&handle : handles) {
#if defined(_WIN32)
::CloseHandle(handle);
#else
@ -75,7 +75,7 @@ void remote_open_file_table::close_all(const std::string &client_id) {
std::vector<std::uint64_t> dirs;
unique_recur_mutex_lock directory_lock(directory_mutex_);
for (auto &kv : directory_lookup_) {
for (auto &&kv : directory_lookup_) {
if (kv.first == client_id) {
dirs.insert(dirs.end(), kv.second.begin(), kv.second.end());
}
@ -183,11 +183,11 @@ void remote_open_file_table::remove_all(const std::string &file_path) {
});
file_lock.unlock();
for (auto &handle : open_list) {
for (auto &&handle : open_list) {
remove_open_info(handle);
}
for (auto &handle : compat_open_list) {
for (auto &&handle : compat_open_list) {
remove_compat_open_info(handle);
}
}

View File

@ -592,7 +592,7 @@ auto winfsp_drive::mount(const std::vector<std::string> &drive_args) -> int {
const auto force_no_console = utils::collection::includes(drive_args, "-nc");
auto enable_console = false;
for (const auto &arg : drive_args) {
for (auto &&arg : drive_args) {
if (arg == "-f") {
if (not force_no_console) {
enable_console = true;

View File

@ -116,7 +116,7 @@ file_manager::file_manager(app_config &config, i_provider &provider)
}
db_.reset(db3);
for (const auto &create_item : sql_create_tables) {
for (auto &&create_item : sql_create_tables) {
std::string err;
if (not db::execute_sql(*db_, create_item.second, err)) {
db_.reset();
@ -176,12 +176,12 @@ void file_manager::close_timed_out_files() {
}
return items;
});
for (const auto &closeable_file : closeable_list) {
for (auto &&closeable_file : closeable_list) {
open_file_lookup_.erase(closeable_file->get_api_path());
}
file_lock.unlock();
for (auto &closeable_file : closeable_list) {
for (auto &&closeable_file : closeable_list) {
closeable_file->close();
event_system::instance().raise<item_timeout>(
closeable_file->get_api_path());
@ -329,7 +329,7 @@ auto file_manager::get_open_files() const
std::unordered_map<std::string, std::size_t> ret;
recur_mutex_lock open_lock(open_file_mtx_);
for (const auto &item : open_file_lookup_) {
for (auto &&item : open_file_lookup_) {
ret[item.first] = item.second->get_open_file_count();
}
@ -843,7 +843,7 @@ void file_manager::start() {
}
}
for (const auto &active_item : active_items) {
for (auto &&active_item : active_items) {
queue_upload(active_item.api_path, active_item.source_path, false);
}
active_items.clear();
@ -937,7 +937,7 @@ void file_manager::stop() {
open_file_lookup_.clear();
upload_lock.lock();
for (auto &item : upload_lookup_) {
for (auto &&item : upload_lookup_) {
item.second->stop();
}
upload_notify_.notify_all();
@ -1125,7 +1125,7 @@ void file_manager::upload_handler() {
void file_manager::update_used_space(std::uint64_t &used_space) const {
recur_mutex_lock open_lock(open_file_mtx_);
for (const auto &item : open_file_lookup_) {
for (auto &&item : open_file_lookup_) {
std::uint64_t file_size{};
auto res = provider_.get_file_size(item.second->get_api_path(), file_size);
if ((res == api_error::success) &&

View File

@ -464,7 +464,7 @@ auto file_manager::open_file::close() -> bool {
utils::get_last_error_code(), "failed to delete file");
}
auto parent = utils::path::get_parent_directory(fsi_.source_path);
auto parent = utils::path::get_parent_path(fsi_.source_path);
fsi_.source_path =
utils::path::combine(parent, {utils::create_uuid_string()});
const auto res = provider_.set_item_meta(fsi_.api_path, META_SOURCE,

View File

@ -157,7 +157,7 @@ auto file_manager::open_file_base::get_handles() const
-> std::vector<std::uint64_t> {
recur_mutex_lock file_lock(file_mtx_);
std::vector<std::uint64_t> ret;
for (const auto &item : open_data_) {
for (auto &&item : open_data_) {
ret.emplace_back(item.first);
}

View File

@ -168,8 +168,8 @@ void file_manager::ring_buffer_open_file::forward(std::size_t count) {
last_chunk_ =
std::min(total_chunks_ - 1U, first_chunk_ + ring_state_.size() - 1U);
} else {
for (std::size_t i = 0U; i < added; i++) {
ring_state_[(first_chunk_ + i) % ring_state_.size()] = true;
for (std::size_t idx = 0U; idx < added; ++idx) {
ring_state_[(first_chunk_ + idx) % ring_state_.size()] = true;
}
first_chunk_ += added;
current_chunk_ += count;
@ -220,8 +220,8 @@ void file_manager::ring_buffer_open_file::reverse(std::size_t count) {
last_chunk_ =
std::min(total_chunks_ - 1U, first_chunk_ + ring_state_.size() - 1U);
} else {
for (std::size_t i = 0U; i < removed; i++) {
ring_state_[(last_chunk_ - i) % ring_state_.size()] = true;
for (std::size_t idx = 0U; idx < removed; ++idx) {
ring_state_[(last_chunk_ - idx) % ring_state_.size()] = true;
}
first_chunk_ -= removed;
current_chunk_ -= count;
@ -254,7 +254,7 @@ auto file_manager::ring_buffer_open_file::read(std::size_t read_size,
auto res = api_error::success;
for (std::size_t chunk = start_chunk_index;
(res == api_error::success) && (read_size > 0U); chunk++) {
(res == api_error::success) && (read_size > 0U); ++chunk) {
if (chunk > current_chunk_) {
forward(chunk - current_chunk_);
} else if (chunk < current_chunk_) {

View File

@ -455,7 +455,7 @@ void base_provider::remove_deleted_files() {
std::vector<removed_item> removed_list{};
for (const auto &api_path : db3_->get_api_path_list()) {
for (auto &&api_path : db3_->get_api_path_list()) {
api_meta_map meta{};
if (get_item_meta(api_path, meta) == api_error::success) {
if (utils::string::to_bool(meta[META_DIRECTORY])) {
@ -480,7 +480,7 @@ void base_provider::remove_deleted_files() {
}
}
for (const auto &item : removed_list) {
for (auto &&item : removed_list) {
if (not item.directory) {
if (utils::file::file(item.source_path).exists()) {
const auto orphaned_directory =
@ -520,7 +520,7 @@ void base_provider::remove_deleted_files() {
}
}
for (const auto &item : removed_list) {
for (auto &&item : removed_list) {
if (item.directory) {
db3_->remove_api_path(item.api_path);
event_system::instance().raise<directory_removed_externally>(
@ -641,9 +641,9 @@ auto base_provider::start(api_item_added_callback api_item_added,
repertory::event_consumer consumer(
"unmount_requested",
[&unmount_requested](const event &) { unmount_requested = true; });
for (std::uint16_t i = 0U; not online && not unmount_requested &&
(i < config_.get_online_check_retry_secs());
i++) {
for (std::uint16_t idx = 0U; not online && not unmount_requested &&
(idx < config_.get_online_check_retry_secs());
++idx) {
online = is_online();
if (not online) {
event_system::instance().raise<provider_offline>(

View File

@ -191,7 +191,11 @@ auto encrypt_provider::do_fs_operation(
: api_error::item_not_found;
}
auto exists = utils::file::file(source_path).exists();
auto exists =
utils::file::file{
source_path,
}
.exists();
if (exists && directory) {
return api_error::item_exists;
}
@ -199,7 +203,11 @@ auto encrypt_provider::do_fs_operation(
return api_error::item_not_found;
}
exists = utils::file::directory(source_path).exists();
exists =
utils::file::directory{
source_path,
}
.exists();
if (exists && not directory) {
return api_error::item_exists;
}
@ -265,10 +273,7 @@ auto encrypt_provider::get_directory_item_count(
[&api_path, &count](const encrypt_config & /* cfg */,
const std::string &source_path) -> api_error {
try {
for ([[maybe_unused]] const auto &dir_entry :
std::filesystem::directory_iterator(source_path)) {
count++;
}
count = utils::file::directory{source_path}.count();
} catch (const std::exception &ex) {
utils::error::raise_api_path_error(
function_name, api_path, source_path, ex,
@ -295,15 +300,15 @@ auto encrypt_provider::get_directory_items(
[this, &list](const encrypt_config &cfg,
const std::string &source_path) -> api_error {
try {
for (const auto &dir_entry :
std::filesystem::directory_iterator(source_path)) {
for (auto &&dir_entry :
utils::file::directory{source_path}.get_items()) {
try {
std::string current_api_path{};
if (dir_entry.is_directory()) {
if (dir_entry->is_directory_item()) {
auto result = db::db_select{*db_, directory_table}
.column("api_path")
.where("source_path")
.equals(dir_entry.path().string())
.equals(dir_entry->get_path())
.go();
std::optional<db::db_select::row> row;
if (result.get_row(row) && row.has_value()) {
@ -311,12 +316,13 @@ auto encrypt_provider::get_directory_items(
row->get_column("api_path").get_value<std::string>();
}
if (current_api_path.empty()) {
process_directory_entry(dir_entry, cfg, current_api_path);
process_directory_entry(*dir_entry.get(), cfg,
current_api_path);
result = db::db_select{*db_, directory_table}
.column("api_path")
.where("source_path")
.equals(dir_entry.path().string())
.equals(dir_entry->get_path())
.go();
row.reset();
if (not(result.get_row(row) && row.has_value())) {
@ -331,7 +337,7 @@ auto encrypt_provider::get_directory_items(
auto result = db::db_select{*db_, file_table}
.column("data")
.where("source_path")
.equals(dir_entry.path().string())
.equals(dir_entry->get_path())
.go();
std::optional<db::db_select::row> row;
if (result.get_row(row) && row.has_value()) {
@ -340,7 +346,7 @@ auto encrypt_provider::get_directory_items(
}
if (api_path_data.empty()) {
if (not process_directory_entry(dir_entry, cfg,
if (not process_directory_entry(*dir_entry.get(), cfg,
current_api_path)) {
continue;
}
@ -351,14 +357,14 @@ auto encrypt_provider::get_directory_items(
}
}
auto file =
create_api_file(current_api_path, dir_entry.is_directory(),
dir_entry.path().string());
auto file = create_api_file(current_api_path,
dir_entry->is_directory_item(),
dir_entry->get_path());
directory_item dir_item{};
dir_item.api_parent = file.api_parent;
dir_item.api_path = file.api_path;
dir_item.directory = dir_entry.is_directory();
dir_item.directory = dir_entry->is_directory_item();
dir_item.resolved = true;
dir_item.size = file.file_size;
create_item_meta(dir_item.meta, dir_item.directory, file);
@ -366,7 +372,7 @@ auto encrypt_provider::get_directory_items(
list.emplace_back(std::move(dir_item));
} catch (const std::exception &ex) {
utils::error::raise_error(function_name, ex,
dir_entry.path().string(),
dir_entry->get_path(),
"failed to process directory item");
}
}
@ -431,12 +437,11 @@ auto encrypt_provider::get_file_list(api_file_list &list) const -> api_error {
const auto cfg = config_.get_encrypt_config();
try {
for (const auto &dir_entry :
std::filesystem::recursive_directory_iterator(cfg.path)) {
for (auto &&dir_entry : utils::file::directory{cfg.path}.get_items()) {
std::string api_path{};
if (process_directory_entry(dir_entry, cfg, api_path)) {
list.emplace_back(create_api_file(api_path, dir_entry.is_directory(),
dir_entry.path().string()));
if (process_directory_entry(*dir_entry.get(), cfg, api_path)) {
list.emplace_back(create_api_file(
api_path, dir_entry->is_directory_item(), dir_entry->get_path()));
}
}
@ -655,9 +660,11 @@ auto encrypt_provider::is_directory(const std::string &api_path,
return api_error::success;
}
exists = utils::file::directory(
row->get_column("source_path").get_value<std::string>())
.exists();
exists =
utils::file::directory{
row->get_column("source_path").get_value<std::string>(),
}
.exists();
return api_error::success;
}
@ -675,7 +682,9 @@ auto encrypt_provider::is_file(const std::string &api_path,
}
exists =
utils::file::file(row->get_column("source_path").get_value<std::string>())
utils::file::file{
row->get_column("source_path").get_value<std::string>(),
}
.exists();
return api_error::success;
}
@ -686,20 +695,24 @@ auto encrypt_provider::is_file_writeable(const std::string & /*api_path*/) const
}
auto encrypt_provider::is_online() const -> bool {
return std::filesystem::exists(config_.get_encrypt_config().path);
return utils::file::file{
config_.get_encrypt_config().path,
}
.exists();
}
auto encrypt_provider::is_rename_supported() const -> bool { return false; }
auto encrypt_provider::process_directory_entry(
const std::filesystem::directory_entry &dir_entry,
const encrypt_config &cfg, std::string &api_path) const -> bool {
const auto add_directory = [this, &cfg](auto dir_path) -> std::string {
const utils::file::i_fs_item &dir_entry, const encrypt_config &cfg,
std::string &api_path) const -> bool {
const auto add_directory = [this,
&cfg](std::string_view dir_path) -> std::string {
auto encrypted_parts = utils::string::split(
utils::path::create_api_path(dir_path.string()), '/', false);
utils::path::create_api_path(dir_path), '/', false);
for (std::size_t part_idx = 1U; part_idx < encrypted_parts.size();
part_idx++) {
++part_idx) {
data_buffer encrypted_data;
utils::encryption::encrypt_data(
cfg.encryption_token,
@ -714,14 +727,9 @@ auto encrypt_provider::process_directory_entry(
std::size_t current_idx{1U};
std::string current_encrypted_path{};
std::string current_source_path{cfg.path};
for (const auto &part : dir_path) {
if (part.string() == "/") {
continue;
}
current_source_path =
utils::path::combine(current_source_path, {part.string()});
auto current_source_path{cfg.path};
for (auto &&part : utils::path::get_parts(dir_path)) {
current_source_path = utils::path::combine(current_source_path, {part});
std::string current_api_path{};
auto result = db::db_select{*db_, directory_table}
@ -763,19 +771,21 @@ auto encrypt_provider::process_directory_entry(
return current_encrypted_path;
};
if (dir_entry.is_directory()) {
api_path = add_directory(dir_entry.path().lexically_relative(cfg.path));
if (dir_entry.is_directory_item()) {
api_path = add_directory(
utils::path::get_relative_path(dir_entry.get_path(), cfg.path));
return false;
}
if (dir_entry.is_regular_file() && not dir_entry.is_symlink()) {
const auto relative_path = dir_entry.path().lexically_relative(cfg.path);
if (dir_entry.is_file_item() && not dir_entry.is_symlink()) {
auto relative_path =
utils::path::get_relative_path(dir_entry.get_path(), cfg.path);
std::string api_path_data{};
auto result = db::db_select{*db_, file_table}
.column("data")
.where("source_path")
.equals(dir_entry.path().string())
.equals(dir_entry.get_path())
.go();
std::optional<db::db_select::row> row;
if (result.get_row(row) && row.has_value()) {
@ -786,7 +796,7 @@ auto encrypt_provider::process_directory_entry(
result = db::db_select{*db_, directory_table}
.column("api_path")
.where("source_path")
.equals(dir_entry.path().parent_path().string())
.equals(utils::path::get_parent_path(dir_entry.get_path()))
.go();
row.reset();
if (result.get_row(row) && row.has_value()) {
@ -794,15 +804,15 @@ auto encrypt_provider::process_directory_entry(
}
if (api_parent.empty()) {
api_parent = add_directory(relative_path.parent_path());
api_parent = add_directory(utils::path::get_parent_path(relative_path));
}
if (api_path_data.empty()) {
stop_type stop_requested = false;
utils::encryption::encrypting_reader reader(
relative_path.filename().string(), dir_entry.path().string(),
utils::path::strip_to_file_name(relative_path), dir_entry.get_path(),
stop_requested, cfg.encryption_token,
relative_path.parent_path().string());
utils::path::get_parent_path(relative_path));
api_path = utils::path::create_api_path(api_parent + "/" +
reader.get_encrypted_file_name());
@ -810,17 +820,22 @@ auto encrypt_provider::process_directory_entry(
json data = {
{"api_path", api_path},
{"iv_list", iv_list},
{"original_file_size", dir_entry.file_size()},
{
"original_file_size",
(dynamic_cast<const utils::file::i_file *>(&dir_entry)
->size()
.value_or(0U)),
},
};
auto ins_res = db::db_insert{*db_, file_table}
.column_value("source_path", dir_entry.path().string())
.column_value("source_path", dir_entry.get_path())
.column_value("data", data.dump())
.go();
// TODO handle error
ins_res = db::db_insert{*db_, source_table}
.column_value("api_path", api_path)
.column_value("source_path", dir_entry.path().string())
.column_value("source_path", dir_entry.get_path())
.go();
// TODO handle error
event_system::instance().raise<filesystem_item_added>(api_path,
@ -886,13 +901,12 @@ auto encrypt_provider::read_file_bytes(const std::string &api_path,
unique_recur_mutex_lock reader_lookup_lock(reader_lookup_mtx_);
if (file_data.at("original_file_size").get<std::uint64_t>() != file_size) {
const auto relative_path =
std::filesystem::path(source_path).lexically_relative(cfg.path);
auto relative_path = utils::path::get_relative_path(source_path, cfg.path);
auto info = std::make_shared<reader_info>();
info->reader = std::make_unique<utils::encryption::encrypting_reader>(
relative_path.filename().string(), source_path, stop_requested,
cfg.encryption_token, relative_path.parent_path().string());
relative_path, source_path, stop_requested, cfg.encryption_token,
utils::path::get_parent_path(relative_path));
reader_lookup_[source_path] = info;
iv_list = info->reader->get_iv_list();
@ -963,9 +977,9 @@ void encrypt_provider::remove_deleted_files() {
}
}
for (const auto &row : row_list) {
for (auto &&row : row_list) {
auto source_path = row.get_column("source_path").get_value<std::string>();
if (not std::filesystem::exists(source_path)) {
if (not utils::path::exists(source_path)) {
auto api_path = row.get_column("api_path").get_value<std::string>();
result = db::db_select{*db_, file_table}
.column("source_path")
@ -977,7 +991,7 @@ void encrypt_provider::remove_deleted_files() {
}
}
for (const auto &item : removed_list) {
for (auto &&item : removed_list) {
if (not item.directory) {
auto del_res = db::db_select{*db_, source_table}
.delete_query()
@ -996,7 +1010,7 @@ void encrypt_provider::remove_deleted_files() {
}
}
for (const auto &item : removed_list) {
for (auto &&item : removed_list) {
if (item.directory) {
auto del_res = db::db_select{*db_, source_table}
.delete_query()
@ -1041,7 +1055,7 @@ auto encrypt_provider::start(api_item_added_callback /*api_item_added*/,
}
db_.reset(db3);
for (const auto &create : sql_create_tables) {
for (auto &&create : sql_create_tables) {
std::string err;
if (not db::execute_sql(*db_, create.second, err)) {
utils::error::raise_error(function_name, "failed to create table|" +

View File

@ -288,7 +288,7 @@ auto meta_db::set_item_meta(const std::string &api_path,
// TODO handle error
}
for (const auto &item : meta) {
for (auto &&item : meta) {
existing_meta[item.first] = item.second;
}

View File

@ -179,13 +179,13 @@ auto s3_provider::create_path_directories(
std::string cur_key{'/'};
std::string cur_path{'/'};
for (std::size_t i = 0U; i < path_parts.size(); i++) {
for (std::size_t idx = 0U; idx < path_parts.size(); ++idx) {
if (is_encrypted) {
cur_key = utils::path::create_api_path(
utils::path::combine(cur_key, {key_parts.at(i)}));
utils::path::combine(cur_key, {key_parts.at(idx)}));
}
cur_path = utils::path::create_api_path(
utils::path::combine(cur_path, {path_parts.at(i)}));
utils::path::combine(cur_path, {path_parts.at(idx)}));
api_meta_map meta{};
auto res = get_item_meta(cur_path, meta);
@ -206,7 +206,7 @@ auto s3_provider::create_path_directories(
auto s3_provider::decrypt_object_name(std::string &object_name) const
-> api_error {
auto parts = utils::string::split(object_name, '/', false);
for (auto &part : parts) {
for (auto &&part : parts) {
if (not utils::encryption::decrypt_file_name(
get_config().get_s3_config().encryption_token, part)) {
return api_error::decryption_error;
@ -368,14 +368,14 @@ auto s3_provider::get_directory_items_impl(
};
auto node_list = doc.select_nodes("/ListBucketResult/CommonPrefixes/Prefix");
for (const auto &node : node_list) {
for (auto &&node : node_list) {
add_directory_item(
true, node.node().text().as_string(),
[](const directory_item &) -> std::uint64_t { return 0U; });
}
node_list = doc.select_nodes("/ListBucketResult/Contents");
for (const auto &node : node_list) {
for (auto &&node : node_list) {
auto child_object_name = utils::path::create_api_path(
node.node().select_node("Key").node().text().as_string());
if (child_object_name != utils::path::create_api_path(prefix)) {
@ -446,7 +446,7 @@ auto s3_provider::get_file_list(api_file_list &list) const -> api_error {
}
auto node_list = doc.select_nodes("/ListBucketResult/Contents");
for (const auto &node : node_list) {
for (auto &&node : node_list) {
auto api_path =
std::string{node.node().select_node("Key").node().text().as_string()};
if (not utils::string::ends_with(api_path, "/")) {
@ -689,10 +689,10 @@ auto s3_provider::read_file_bytes(const std::string &api_path, std::size_t size,
&stop_requested](std::size_t read_size, std::size_t read_offset,
data_buffer &read_buffer) -> api_error {
auto res = api_error::error;
for (std::uint32_t i = 0U;
for (std::uint32_t idx = 0U;
not stop_requested && res != api_error::success &&
i < get_config().get_retry_read_count() + 1U;
i++) {
idx < get_config().get_retry_read_count() + 1U;
++idx) {
curl::requests::http_get get{};
get.aws_service = "aws:amz:" + cfg.region + ":s3";
get.headers["response-content-type"] = "binary/octet-stream";
@ -713,13 +713,13 @@ auto s3_provider::read_file_bytes(const std::string &api_path, std::size_t size,
function_name, api_path, api_error::comm_error,
"read file bytes failed|offset|" + std::to_string(read_offset) +
"|size|" + std::to_string(read_size) + "|retry|" +
std::to_string(i + 1U));
std::to_string(idx + 1U));
} else {
utils::error::raise_api_path_error(
function_name, api_path, response_code,
"read file bytes failed|offset|" + std::to_string(read_offset) +
"|size|" + std::to_string(read_size) + "|retry|" +
std::to_string(i + 1U));
std::to_string(idx + 1U));
}
std::this_thread::sleep_for(1s);
};

View File

@ -80,7 +80,7 @@ auto sia_provider::get_directory_item_count(const std::string &api_path) const
std::uint64_t item_count{};
if (object_list.contains("entries")) {
for (const auto &entry : object_list.at("entries")) {
for (auto &&entry : object_list.at("entries")) {
try {
auto name = entry.at("name").get<std::string>();
auto entry_api_path = utils::path::create_api_path(name);
@ -118,7 +118,7 @@ auto sia_provider::get_directory_items_impl(
}
if (object_list.contains("entries")) {
for (const auto &entry : object_list.at("entries")) {
for (auto &&entry : object_list.at("entries")) {
try {
auto name = entry.at("name").get<std::string>();
auto entry_api_path = utils::path::create_api_path(name);
@ -208,7 +208,7 @@ auto sia_provider::get_file_list(api_file_list &list) const -> api_error {
}
if (object_list.contains("entries")) {
for (const auto &entry : object_list.at("entries")) {
for (auto &&entry : object_list.at("entries")) {
auto name = entry.at("name").get<std::string>();
auto entry_api_path = utils::path::create_api_path(name);
@ -534,9 +534,10 @@ auto sia_provider::read_file_bytes(const std::string &api_path,
long /*response_code*/) { buffer = data; };
auto res = api_error::comm_error;
for (std::uint32_t i = 0U; not stop_requested && res != api_error::success &&
i < get_config().get_retry_read_count() + 1U;
i++) {
for (std::uint32_t idx = 0U;
not stop_requested && res != api_error::success &&
idx < get_config().get_retry_read_count() + 1U;
++idx) {
long response_code{};
const auto notify_retry = [&]() {
if (response_code == 0) {
@ -544,13 +545,13 @@ auto sia_provider::read_file_bytes(const std::string &api_path,
function_name, api_path, api_error::comm_error,
"read file bytes failed|offset|" + std::to_string(offset) +
"|size|" + std::to_string(size) + "|retry|" +
std::to_string(i + 1U));
std::to_string(idx + 1U));
} else {
utils::error::raise_api_path_error(
function_name, api_path, response_code,
"read file bytes failed|offset|" + std::to_string(offset) +
"|size|" + std::to_string(size) + "|retry|" +
std::to_string(i + 1U));
std::to_string(idx + 1U));
}
std::this_thread::sleep_for(1s);
};

View File

@ -49,7 +49,7 @@ void change_to_process_directory() {
#else
readlink("/proc/self/exe", &path[0U], path.size());
#endif
path = utils::path::get_parent_directory(path);
path = utils::path::get_parent_path(path);
chdir(path.c_str());
#endif
}

View File

@ -458,11 +458,6 @@ struct http_range final {
using http_headers = std::unordered_map<std::string, std::string>;
using http_query_parameters = std::map<std::string, std::string>;
using http_ranges = std::vector<http_range>;
struct encrypt_config {
std::string encryption_token;
std::string path;
};
#endif // defined(PROJECT_ENABLE_CURL)
} // namespace repertory
#endif // defined(__cplusplus)

View File

@ -102,6 +102,12 @@ struct i_fs_item {
[[nodiscard]] virtual auto is_directory_item() const -> bool = 0;
[[nodiscard]] auto is_file_item() const -> bool {
return not is_directory_item();
}
[[nodiscard]] virtual auto is_symlink() const -> bool = 0;
[[nodiscard]] virtual auto move_to(std::string_view new_path) -> bool = 0;
[[nodiscard]] virtual auto move_to(std::wstring_view new_path) -> bool {
@ -279,7 +285,9 @@ public:
[[nodiscard]] auto is_read_only() const -> bool override {
return read_only_;
};
}
[[nodiscard]] auto is_symlink() const -> bool override;
[[nodiscard]] auto move_to(std::string_view new_path) -> bool override;
@ -374,7 +382,11 @@ public:
[[nodiscard]] auto is_read_only() const -> bool override {
return file_->is_read_only();
};
}
[[nodiscard]] auto is_symlink() const -> bool override {
return file_->is_symlink();
}
[[nodiscard]] auto move_to(std::string_view new_path) -> bool override;
@ -489,7 +501,11 @@ public:
[[nodiscard]] auto is_read_only() const -> bool override {
return file_->is_read_only();
};
}
[[nodiscard]] auto is_symlink() const -> bool override {
return file_->is_symlink();
}
[[nodiscard]] auto move_to(std::string_view new_path) -> bool override;
@ -624,6 +640,8 @@ public:
[[nodiscard]] auto get_path() const -> std::string override { return path_; }
[[nodiscard]] auto is_symlink() const -> bool override;
[[nodiscard]] auto move_to(std::string_view new_path) -> bool override;
[[nodiscard]] auto remove() -> bool override;
@ -724,8 +742,9 @@ public:
[[nodiscard]] auto is_read_only() const -> bool override {
return read_only_;
};
}
[[nodiscard]] auto is_symlink() const -> bool override;
[[nodiscard]] auto move_to(std::string_view new_path) -> bool override;
[[nodiscard]] auto open(bool read_only) -> bool;
@ -853,6 +872,8 @@ public:
return smb_get_uri_path(path_, user, password);
}
[[nodiscard]] auto is_symlink() const -> bool override;
[[nodiscard]] auto move_to(std::string_view new_path) -> bool override;
[[nodiscard]] auto remove() -> bool override;

View File

@ -221,6 +221,10 @@ combine(std::wstring_view path,
[[nodiscard]] auto inline create_api_path(std::wstring_view path)
-> std::wstring;
[[nodiscard]] auto exists(std::string_view path) -> bool;
[[nodiscard]] auto exists(std::wstring_view path) -> bool;
[[nodiscard]] inline auto finalize(std::string_view path) -> std::string;
[[nodiscard]] inline auto finalize(std::wstring_view path) -> std::wstring;
@ -244,9 +248,22 @@ get_parent_api_path(std::string_view path) -> std::string;
[[nodiscard]] inline auto
get_parent_api_path(std::wstring_view path) -> std::wstring;
[[nodiscard]] auto get_parent_directory(std::string_view path) -> std::string;
[[nodiscard]] auto get_parent_path(std::string_view path) -> std::string;
[[nodiscard]] auto get_parent_directory(std::wstring_view path) -> std::wstring;
[[nodiscard]] auto get_parent_path(std::wstring_view path) -> std::wstring;
[[nodiscard]] inline auto
get_parts(std::string_view path) -> std::vector<std::string>;
[[nodiscard]] inline auto
get_parts_w(std::wstring_view path) -> std::vector<std::wstring>;
[[nodiscard]] auto get_relative_path(std::string_view path,
std::string_view root_path) -> std::string;
[[nodiscard]] auto
get_relative_path(std::wstring_view path,
std::wstring_view root_path) -> std::wstring;
[[nodiscard]] auto make_file_uri(std::string_view path) -> std::string;
@ -485,6 +502,23 @@ inline auto get_parent_api_path(std::string_view path) -> std::string {
inline auto get_parent_api_path(std::wstring_view path) -> std::wstring {
return get_parent_api_path_t<std::wstring>(path);
}
template <typename string_t>
[[nodiscard]] inline auto
get_parts_t(std::basic_string_view<typename string_t::value_type> path)
-> std::vector<string_t> {
return utils::string::split(
path, get_directory_seperator<typename string_t::value_type>().at(0U),
false);
}
inline auto get_parts(std::string_view path) -> std::vector<std::string> {
return get_parts_t<std::string>(path);
}
inline auto get_parts_w(std::wstring_view path) -> std::vector<std::wstring> {
return get_parts_t<std::wstring>(path);
}
} // namespace repertory::utils::path
#endif // REPERTORY_INCLUDE_UTILS_PATH_HPP_

View File

@ -328,6 +328,22 @@ auto directory::get_items() const -> std::vector<fs_item_t> {
return {};
}
auto directory::is_symlink() const -> bool {
static constexpr const std::string_view function_name{
static_cast<const char *>(__FUNCTION__),
};
try {
return std::filesystem::is_symlink(path_);
} catch (const std::exception &e) {
utils::error::handle_exception(function_name, e);
} catch (...) {
utils::error::handle_exception(function_name);
}
return false;
}
auto directory::move_to(std::string_view new_path) -> bool { return false; }
auto directory::remove() -> bool {

View File

@ -259,6 +259,22 @@ auto file::get_time(time_types type) const -> std::uint64_t {
return i_fs_item::get_time(type);
}
auto file::is_symlink() const -> bool {
static constexpr const std::string_view function_name{
static_cast<const char *>(__FUNCTION__),
};
try {
return std::filesystem::is_symlink(path_);
} catch (const std::exception &e) {
utils::error::handle_exception(function_name, e);
} catch (...) {
utils::error::handle_exception(function_name);
}
return false;
}
auto file::move_to(std::string_view path) -> bool {
static constexpr const std::string_view function_name{
static_cast<const char *>(__FUNCTION__),

View File

@ -484,6 +484,25 @@ auto smb_directory::get_items() const -> std::vector<fs_item_t> {
return {};
}
auto smb_directory::is_symlink() const -> bool {
static constexpr const std::string_view function_name{
static_cast<const char *>(__FUNCTION__),
};
try {
if (not session_) {
throw std::runtime_error("session not found|" + path_);
}
} catch (const std::exception &e) {
utils::error::handle_exception(function_name, e);
} catch (...) {
utils::error::handle_exception(function_name);
}
return false;
}
auto smb_directory::move_to(std::string_view new_path) -> bool {
static constexpr const std::string_view function_name{
static_cast<const char *>(__FUNCTION__),

View File

@ -139,6 +139,25 @@ auto smb_file::get_time(smb_session *session, smb_tid tid, std::string path,
return 0U;
}
auto smb_file::is_symlink() const -> bool {
static constexpr const std::string_view function_name{
static_cast<const char *>(__FUNCTION__),
};
try {
if (not session_) {
throw std::runtime_error("session not found|" + path_);
}
} catch (const std::exception &e) {
utils::error::handle_exception(function_name, e);
} catch (...) {
utils::error::handle_exception(function_name);
}
return false;
}
auto smb_file::move_to(std::string_view new_path) -> bool {
static constexpr const std::string_view function_name{
static_cast<const char *>(__FUNCTION__),

View File

@ -112,6 +112,15 @@ auto absolute(std::wstring_view path) -> std::wstring {
return utils::string::from_utf8(absolute(utils::string::to_utf8(path)));
}
auto exists(std::string_view path) -> bool {
return utils::file::file{path}.exists() ||
utils::file::directory{path}.exists();
}
auto exists(std::wstring_view path) -> bool {
return exists(utils::string::to_utf8(path));
}
auto find_program_in_path(const std::string &name_without_extension)
-> std::string {
static std::mutex mtx{};
@ -143,7 +152,7 @@ auto find_program_in_path(const std::string &name_without_extension)
static constexpr const auto split_char = ':';
#endif // defined(_WIN32)
const auto search_path_list = utils::string::split(path, split_char, false);
auto search_path_list = utils::string::split(path, split_char, false);
for (auto &&search_path : search_path_list) {
for (auto &&extension : extension_list) {
auto exec_path = combine(
@ -164,7 +173,7 @@ find_program_in_path(std::wstring_view name_without_extension) -> std::wstring {
find_program_in_path(utils::string::to_utf8(name_without_extension)));
}
auto get_parent_directory(std::string_view path) -> std::string {
auto get_parent_path(std::string_view path) -> std::string {
auto abs_path = absolute(path);
#if defined(_WIN32)
@ -177,9 +186,32 @@ auto get_parent_directory(std::string_view path) -> std::string {
return finalize(abs_path);
}
auto get_parent_directory(std::wstring_view path) -> std::wstring {
auto get_parent_path(std::wstring_view path) -> std::wstring {
return utils::string::from_utf8(
get_parent_directory(utils::string::to_utf8(path)));
get_parent_path(utils::string::to_utf8(path)));
}
auto get_relative_path(std::string_view path,
std::string_view root_path) -> std::string {
auto abs_path = absolute(path);
auto abs_root_path =
absolute(root_path) + std::string{get_directory_seperator<char>()};
#if defined(_WIN32)
if (utils::string::to_lower(abs_path).starts_with(
utils::string::to_lower(abs_root_path))) {
#else // !defined(_WIN32)
if (abs_path.starts_with(abs_root_path)) {
#endif // defined(_WIN32)
return abs_path.substr(abs_root_path.size());
}
return abs_path;
}
auto get_relative_path(std::wstring_view path,
std::wstring_view root_path) -> std::wstring {
return utils::string::from_utf8(get_relative_path(
utils::string::to_utf8(path), utils::string::to_utf8(root_path)));
}
auto contains_trash_directory(std::string_view path) -> bool {

View File

@ -33,7 +33,7 @@ static void delete_generated_files() {
for (auto &&path : generated_files) {
if (parent_path->empty()) {
parent_path =
repertory::utils::path::get_parent_directory(path->get_path());
repertory::utils::path::get_parent_path(path->get_path());
}
[[maybe_unused]] auto removed = path->remove();

View File

@ -423,53 +423,53 @@ TEST(utils_path, absolute_can_resolve_path_variables) {
#endif // defined(_WIN32)
}
TEST(utils_path, get_parent_directory) {
TEST(utils_path, get_parent_path) {
#if defined(_WIN32)
{
auto dir = R"(c:\test)";
auto parent = utils::path::get_parent_directory(dir);
auto parent = utils::path::get_parent_path(dir);
EXPECT_STREQ("c:", parent.c_str());
dir = R"(c:\test\file.txt)";
parent = utils::path::get_parent_directory(dir);
parent = utils::path::get_parent_path(dir);
EXPECT_STREQ(R"(c:\test)", parent.c_str());
dir = "c:";
parent = utils::path::get_parent_directory(dir);
parent = utils::path::get_parent_path(dir);
EXPECT_STREQ("c:", parent.c_str());
}
{
auto dir = LR"(c:\test)";
auto parent = utils::path::get_parent_directory(dir);
auto parent = utils::path::get_parent_path(dir);
EXPECT_STREQ(L"c:", parent.c_str());
dir = LR"(c:\test\file.txt)";
parent = utils::path::get_parent_directory(dir);
parent = utils::path::get_parent_path(dir);
EXPECT_STREQ(LR"(c:\test)", parent.c_str());
dir = L"c:";
parent = utils::path::get_parent_directory(dir);
parent = utils::path::get_parent_path(dir);
EXPECT_STREQ(L"c:", parent.c_str());
}
#else // !defined(_WIN32)
{
auto dir = "/test";
auto parent = utils::path::get_parent_directory(dir);
auto parent = utils::path::get_parent_path(dir);
EXPECT_STREQ("/", parent.c_str());
dir = "/test/test";
parent = utils::path::get_parent_directory(dir);
parent = utils::path::get_parent_path(dir);
EXPECT_STREQ("/test", parent.c_str());
}
{
auto dir = L"/test";
auto parent = utils::path::get_parent_directory(dir);
auto parent = utils::path::get_parent_path(dir);
EXPECT_STREQ(L"/", parent.c_str());
dir = L"/test/test";
parent = utils::path::get_parent_directory(dir);
parent = utils::path::get_parent_path(dir);
EXPECT_STREQ(L"/test", parent.c_str());
}
#endif // defined(_WIN32)