5 Commits

Author SHA1 Message Date
e6bd5834f8 updates
Some checks reported errors
BlockStorage/repertory/pipeline/head Something is wrong with the build of this commit
2024-08-28 17:15:35 -05:00
685e715884 updates 2024-08-28 12:02:48 -05:00
d92a2d5e1c updates 2024-08-28 12:01:37 -05:00
0320bb964f refactor 2024-08-28 11:06:19 -05:00
82b3efff0c updated build system 2024-08-28 11:00:44 -05:00
39 changed files with 405 additions and 4782 deletions

View File

@ -140,7 +140,6 @@ endif()
-DPROJECT_DESC=${PROJECT_DESC} -DPROJECT_DESC=${PROJECT_DESC}
-DPROJECT_DIST_DIR=${PROJECT_DIST_DIR} -DPROJECT_DIST_DIR=${PROJECT_DIST_DIR}
-DPROJECT_ENABLE_WIN32_LONG_PATH_NAMES=${PROJECT_ENABLE_WIN32_LONG_PATH_NAMES} -DPROJECT_ENABLE_WIN32_LONG_PATH_NAMES=${PROJECT_ENABLE_WIN32_LONG_PATH_NAMES}
-DPROJECT_ENABLE_BACKWARD_CPP=${PROJECT_ENABLE_BACKWARD_CPP}
-DPROJECT_ENABLE_BOOST=${PROJECT_ENABLE_BOOST} -DPROJECT_ENABLE_BOOST=${PROJECT_ENABLE_BOOST}
-DPROJECT_ENABLE_CPP_HTTPLIB=${PROJECT_ENABLE_CPP_HTTPLIB} -DPROJECT_ENABLE_CPP_HTTPLIB=${PROJECT_ENABLE_CPP_HTTPLIB}
-DPROJECT_ENABLE_CURL=${PROJECT_ENABLE_CURL} -DPROJECT_ENABLE_CURL=${PROJECT_ENABLE_CURL}

View File

@ -11,7 +11,6 @@ include(cmake/libraries/openssl.cmake)
include(cmake/libraries/boost.cmake) include(cmake/libraries/boost.cmake)
include(cmake/libraries/backward_cpp.cmake)
include(cmake/libraries/cpp_httplib.cmake) include(cmake/libraries/cpp_httplib.cmake)
include(cmake/libraries/curl.cmake) include(cmake/libraries/curl.cmake)
include(cmake/libraries/fuse.cmake) include(cmake/libraries/fuse.cmake)

View File

@ -1,11 +0,0 @@
if(PROJECT_ENABLE_BACKWARD_CPP AND PROJECT_BUILD)
if(PROJECT_IS_MINGW)
add_definitions(-DPROJECT_ENABLE_BACKWARD_CPP)
link_libraries(msvcr90)
else()
add_definitions(-DBACKWARD_HAS_BFD)
link_libraries(bfd)
endif()
endif()

View File

@ -1,4 +1,3 @@
option(PROJECT_ENABLE_BACKWARD_CPP "Enable backward-cpp" ON)
option(PROJECT_ENABLE_BOOST "Enable boost libraries" ON) option(PROJECT_ENABLE_BOOST "Enable boost libraries" ON)
option(PROJECT_ENABLE_CPP_HTTPLIB "Enable cpp-httplib" ON) option(PROJECT_ENABLE_CPP_HTTPLIB "Enable cpp-httplib" ON)
option(PROJECT_ENABLE_CURL "Enable curl library" ON) option(PROJECT_ENABLE_CURL "Enable curl library" ON)

View File

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

View File

@ -21,7 +21,7 @@ PROJECT_PUBLIC_KEY=${DEVELOPER_PUBLIC_KEY}
PROJECT_ENABLE_WIN32_LONG_PATH_NAMES=OFF PROJECT_ENABLE_WIN32_LONG_PATH_NAMES=OFF
PROJECT_ENABLE_BACKWARD_CPP=ON PROJECT_ENABLE_BACKWARD_CPP=OFF
PROJECT_ENABLE_BOOST=ON PROJECT_ENABLE_BOOST=ON
PROJECT_ENABLE_CPP_HTTPLIB=ON PROJECT_ENABLE_CPP_HTTPLIB=ON
PROJECT_ENABLE_CURL=ON PROJECT_ENABLE_CURL=ON
@ -36,7 +36,6 @@ PROJECT_ENABLE_STDUUID=ON
PROJECT_ENABLE_TESTING=ON PROJECT_ENABLE_TESTING=ON
PROJECT_ENABLE_WINFSP=ON PROJECT_ENABLE_WINFSP=ON
PROJECT_KEEP_BACKWARD_CPP=1
PROJECT_STATIC_LINK=ON PROJECT_STATIC_LINK=ON
PROJECT_MINGW64_COPY_DEPENDENCIES+=() PROJECT_MINGW64_COPY_DEPENDENCIES+=()

View File

@ -1,15 +1,3 @@
if (NOT PROJECT_STATIC_LINK)
include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/deps/include)
if(PROJECT_IS_MINGW)
link_libraries(msvcr90)
endif()
list(APPEND PROJECT_ADDITIONAL_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/deps/src/backward.cpp
)
endif()
set(CMAKE_CXX_FLAGS "-include common.hpp ${CMAKE_CXX_FLAGS}") set(CMAKE_CXX_FLAGS "-include common.hpp ${CMAKE_CXX_FLAGS}")
add_project_library(lib${PROJECT_NAME} "" "" "${PROJECT_ADDITIONAL_SOURCES}") add_project_library(lib${PROJECT_NAME} "" "" "${PROJECT_ADDITIONAL_SOURCES}")

View File

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

View File

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

View File

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

View File

@ -437,7 +437,7 @@ auto fuse_base::mount(std::vector<std::string> args) -> int {
auto ret = parse_args(args); auto ret = parse_args(args);
if (ret == 0) { if (ret == 0) {
std::vector<const char *> fuse_argv(args.size()); 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(); 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 fuse_base::parse_args(std::vector<std::string> &args) -> int {
auto force_no_console = false; 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") { if (args[i] == "-nc") {
force_no_console = true; force_no_console = true;
} }
} }
utils::collection::remove_element(args, "-nc"); 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") { if (args[i] == "-f") {
console_enabled_ = not force_no_console; console_enabled_ = not force_no_console;
} else if (args[i].find("-o") == 0) { } 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); 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) { if (option.find("gid") == 0) {
const auto parts = utils::string::split(option, '=', true); const auto parts = utils::string::split(option, '=', true);
if (parts.size() == 2u) { 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; api_meta_map meta;
if ((res = provider_.get_item_meta(api_path, meta)) == api_error::success) { 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)) { if (utils::collection::excludes(META_USED_NAMES, meta_item.first)) {
auto attribute_name = meta_item.first; auto attribute_name = meta_item.first;
#if defined(__APPLE__) #if defined(__APPLE__)

View File

@ -166,9 +166,9 @@ auto fuse_drive_base::check_parent_access(const std::string &api_path,
// Ignore root // Ignore root
if (api_path != "/") { if (api_path != "/") {
if ((mask & X_OK) == X_OK) { 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(); (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) && if (((ret = check_access(parent, X_OK)) == api_error::success) &&
(parent == "/")) { (parent == "/")) {
break; break;
@ -179,7 +179,7 @@ auto fuse_drive_base::check_parent_access(const std::string &api_path,
if (ret == api_error::success) { if (ret == api_error::success) {
mask &= (~X_OK); mask &= (~X_OK);
if (mask != 0) { 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) { void remote_open_file_table::close_all(const std::string &client_id) {
std::vector<remote::file_handle> compat_handles; std::vector<remote::file_handle> compat_handles;
unique_recur_mutex_lock compat_lock(compat_mutex_); 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) { if (kv.second.client_id == client_id) {
compat_handles.emplace_back(kv.first); compat_handles.emplace_back(kv.first);
} }
} }
compat_lock.unlock(); compat_lock.unlock();
for (auto &handle : compat_handles) { for (auto &&handle : compat_handles) {
#if defined(_WIN32) #if defined(_WIN32)
_close(static_cast<int>(handle)); _close(static_cast<int>(handle));
#else #else
@ -57,14 +57,14 @@ void remote_open_file_table::close_all(const std::string &client_id) {
std::vector<native_handle> handles; std::vector<native_handle> handles;
unique_recur_mutex_lock file_lock(file_mutex_); 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) { if (kv.second.client_id == client_id) {
handles.emplace_back(kv.first); handles.emplace_back(kv.first);
} }
} }
file_lock.unlock(); file_lock.unlock();
for (auto &handle : handles) { for (auto &&handle : handles) {
#if defined(_WIN32) #if defined(_WIN32)
::CloseHandle(handle); ::CloseHandle(handle);
#else #else
@ -75,7 +75,7 @@ void remote_open_file_table::close_all(const std::string &client_id) {
std::vector<std::uint64_t> dirs; std::vector<std::uint64_t> dirs;
unique_recur_mutex_lock directory_lock(directory_mutex_); unique_recur_mutex_lock directory_lock(directory_mutex_);
for (auto &kv : directory_lookup_) { for (auto &&kv : directory_lookup_) {
if (kv.first == client_id) { if (kv.first == client_id) {
dirs.insert(dirs.end(), kv.second.begin(), kv.second.end()); 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(); file_lock.unlock();
for (auto &handle : open_list) { for (auto &&handle : open_list) {
remove_open_info(handle); remove_open_info(handle);
} }
for (auto &handle : compat_open_list) { for (auto &&handle : compat_open_list) {
remove_compat_open_info(handle); remove_compat_open_info(handle);
} }
} }

View File

@ -479,8 +479,7 @@ auto winfsp_drive::get_security_by_name(
if (descriptor_size != nullptr) { if (descriptor_size != nullptr) {
ULONG size{}; ULONG size{};
PSECURITY_DESCRIPTOR sec_desc{}; PSECURITY_DESCRIPTOR sec_desc{};
if (::ConvertStringSecurityDescriptorToSecurityDescriptorA(
if (::ConvertStringSecurityDescriptorToSecurityDescriptor(
"O:BAG:BAD:P(A;;FA;;;SY)(A;;FA;;;BA)(A;;FA;;;WD)", "O:BAG:BAD:P(A;;FA;;;SY)(A;;FA;;;BA)(A;;FA;;;WD)",
SDDL_REVISION_1, &sec_desc, &size) != 0) { SDDL_REVISION_1, &sec_desc, &size) != 0) {
if (size > *descriptor_size) { if (size > *descriptor_size) {
@ -511,6 +510,11 @@ auto winfsp_drive::GetSecurityByName(PWSTR file_name, PUINT32 attributes,
std::uint64_t sds = descriptor_size == nullptr ? 0U : *descriptor_size; std::uint64_t sds = descriptor_size == nullptr ? 0U : *descriptor_size;
auto ret = get_security_by_name(file_name, attributes, descriptor, auto ret = get_security_by_name(file_name, attributes, descriptor,
sds > 0U ? &sds : nullptr); sds > 0U ? &sds : nullptr);
if (attributes != nullptr) {
event_system::instance().raise<debug_log>(
std::string{function_name}, api_path,
std::to_string(*attributes & FILE_ATTRIBUTE_DIRECTORY));
}
if (sds != 0U) { if (sds != 0U) {
*descriptor_size = static_cast<SIZE_T>(sds); *descriptor_size = static_cast<SIZE_T>(sds);
} }
@ -592,7 +596,7 @@ auto winfsp_drive::mount(const std::vector<std::string> &drive_args) -> int {
const auto force_no_console = utils::collection::includes(drive_args, "-nc"); const auto force_no_console = utils::collection::includes(drive_args, "-nc");
auto enable_console = false; auto enable_console = false;
for (const auto &arg : drive_args) { for (auto &&arg : drive_args) {
if (arg == "-f") { if (arg == "-f") {
if (not force_no_console) { if (not force_no_console) {
enable_console = true; enable_console = true;
@ -709,6 +713,8 @@ auto winfsp_drive::Open(PWSTR file_name, UINT32 create_options,
std::uint64_t handle{}; std::uint64_t handle{};
std::shared_ptr<i_open_file> file; std::shared_ptr<i_open_file> file;
error = fm_->open(api_path, directory, ofd, handle, file); error = fm_->open(api_path, directory, ofd, handle, file);
event_system::instance().raise<debug_log>(
std::string{function_name}, api_path, std::to_string(handle));
if (error == api_error::success) { if (error == api_error::success) {
api_meta_map meta; api_meta_map meta;
error = provider_.get_item_meta(api_path, meta); error = provider_.get_item_meta(api_path, meta);
@ -899,6 +905,7 @@ auto winfsp_drive::ReadDirectory(PVOID /*file_node*/, PVOID file_desc,
static constexpr const std::string_view function_name{ static constexpr const std::string_view function_name{
static_cast<const char *>(__FUNCTION__), static_cast<const char *>(__FUNCTION__),
}; };
event_system::instance().raise<debug_log>(std::string{function_name}, "", "");
std::string api_path; std::string api_path;
auto error = api_error::invalid_handle; auto error = api_error::invalid_handle;

View File

@ -116,7 +116,7 @@ file_manager::file_manager(app_config &config, i_provider &provider)
} }
db_.reset(db3); db_.reset(db3);
for (const auto &create_item : sql_create_tables) { for (auto &&create_item : sql_create_tables) {
std::string err; std::string err;
if (not db::execute_sql(*db_, create_item.second, err)) { if (not db::execute_sql(*db_, create_item.second, err)) {
db_.reset(); db_.reset();
@ -176,12 +176,12 @@ void file_manager::close_timed_out_files() {
} }
return items; return items;
}); });
for (const auto &closeable_file : closeable_list) { for (auto &&closeable_file : closeable_list) {
open_file_lookup_.erase(closeable_file->get_api_path()); open_file_lookup_.erase(closeable_file->get_api_path());
} }
file_lock.unlock(); file_lock.unlock();
for (auto &closeable_file : closeable_list) { for (auto &&closeable_file : closeable_list) {
closeable_file->close(); closeable_file->close();
event_system::instance().raise<item_timeout>( event_system::instance().raise<item_timeout>(
closeable_file->get_api_path()); 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; std::unordered_map<std::string, std::size_t> ret;
recur_mutex_lock open_lock(open_file_mtx_); 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(); 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); queue_upload(active_item.api_path, active_item.source_path, false);
} }
active_items.clear(); active_items.clear();
@ -937,7 +937,7 @@ void file_manager::stop() {
open_file_lookup_.clear(); open_file_lookup_.clear();
upload_lock.lock(); upload_lock.lock();
for (auto &item : upload_lookup_) { for (auto &&item : upload_lookup_) {
item.second->stop(); item.second->stop();
} }
upload_notify_.notify_all(); 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 { void file_manager::update_used_space(std::uint64_t &used_space) const {
recur_mutex_lock open_lock(open_file_mtx_); 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{}; std::uint64_t file_size{};
auto res = provider_.get_file_size(item.second->get_api_path(), file_size); auto res = provider_.get_file_size(item.second->get_api_path(), file_size);
if ((res == api_error::success) && 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"); 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 = fsi_.source_path =
utils::path::combine(parent, {utils::create_uuid_string()}); utils::path::combine(parent, {utils::create_uuid_string()});
const auto res = provider_.set_item_meta(fsi_.api_path, META_SOURCE, 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> { -> std::vector<std::uint64_t> {
recur_mutex_lock file_lock(file_mtx_); recur_mutex_lock file_lock(file_mtx_);
std::vector<std::uint64_t> ret; std::vector<std::uint64_t> ret;
for (const auto &item : open_data_) { for (auto &&item : open_data_) {
ret.emplace_back(item.first); 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_ = last_chunk_ =
std::min(total_chunks_ - 1U, first_chunk_ + ring_state_.size() - 1U); std::min(total_chunks_ - 1U, first_chunk_ + ring_state_.size() - 1U);
} else { } else {
for (std::size_t i = 0U; i < added; i++) { for (std::size_t idx = 0U; idx < added; ++idx) {
ring_state_[(first_chunk_ + i) % ring_state_.size()] = true; ring_state_[(first_chunk_ + idx) % ring_state_.size()] = true;
} }
first_chunk_ += added; first_chunk_ += added;
current_chunk_ += count; current_chunk_ += count;
@ -220,8 +220,8 @@ void file_manager::ring_buffer_open_file::reverse(std::size_t count) {
last_chunk_ = last_chunk_ =
std::min(total_chunks_ - 1U, first_chunk_ + ring_state_.size() - 1U); std::min(total_chunks_ - 1U, first_chunk_ + ring_state_.size() - 1U);
} else { } else {
for (std::size_t i = 0U; i < removed; i++) { for (std::size_t idx = 0U; idx < removed; ++idx) {
ring_state_[(last_chunk_ - i) % ring_state_.size()] = true; ring_state_[(last_chunk_ - idx) % ring_state_.size()] = true;
} }
first_chunk_ -= removed; first_chunk_ -= removed;
current_chunk_ -= count; 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; auto res = api_error::success;
for (std::size_t chunk = start_chunk_index; 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_) { if (chunk > current_chunk_) {
forward(chunk - current_chunk_); forward(chunk - current_chunk_);
} else if (chunk < current_chunk_) { } else if (chunk < current_chunk_) {

View File

@ -29,8 +29,8 @@
#if defined(PROJECT_REQUIRE_ALPINE) && !defined(PROJECT_IS_MINGW) #if defined(PROJECT_REQUIRE_ALPINE) && !defined(PROJECT_IS_MINGW)
#include <filesystem> #include <filesystem>
#include <stdlib.h>
#include <pthread.h> #include <pthread.h>
#include <stdlib.h>
#endif // defined(PROJECT_REQUIRE_ALPINE) && !defined (PROJECT_IS_MINGW) #endif // defined(PROJECT_REQUIRE_ALPINE) && !defined (PROJECT_IS_MINGW)
#if defined(PROJECT_ENABLE_LIBSODIUM) #if defined(PROJECT_ENABLE_LIBSODIUM)
@ -44,6 +44,9 @@
#include "spdlog/spdlog.h" #include "spdlog/spdlog.h"
#include "initialize.hpp" #include "initialize.hpp"
#if defined(PROJECT_REQUIRE_ALPINE) && !defined(PROJECT_IS_MINGW)
#include "utils/path.hpp"
#endif // defined(PROJECT_REQUIRE_ALPINE) && !defined (PROJECT_IS_MINGW)
namespace repertory { namespace repertory {
auto project_initialize() -> bool { auto project_initialize() -> bool {
@ -61,11 +64,7 @@ auto project_initialize() -> bool {
pthread_attr_setguardsize(&attr, guard_size); pthread_attr_setguardsize(&attr, guard_size);
pthread_setattr_default_np(&attr); pthread_setattr_default_np(&attr);
const auto icu_dir = setenv("ICU_DATA", utils::path::combine(".", {"/icu"}).c_str(), 1);
std::filesystem::absolute(std::filesystem::path{"./icu"})
.lexically_normal()
.string();
setenv("ICU_DATA", icu_dir.c_str(), 1);
} }
#endif // defined(PROJECT_REQUIRE_ALPINE) && !defined (PROJECT_IS_MINGW) #endif // defined(PROJECT_REQUIRE_ALPINE) && !defined (PROJECT_IS_MINGW)

View File

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

View File

@ -72,9 +72,16 @@ encrypt_provider::encrypt_provider(app_config &config) : config_(config) {}
auto encrypt_provider::create_api_file( auto encrypt_provider::create_api_file(
const std::string &api_path, bool directory, const std::string &api_path, bool directory,
const std::string &source_path) -> api_file { const std::string &source_path) -> api_file {
static constexpr const std::string_view function_name{
static_cast<const char *>(__FUNCTION__),
};
#if defined(_WIN32) #if defined(_WIN32)
struct _stat64 buf {}; struct _stat64 buf {};
_stat64(source_path.c_str(), &buf); auto res = _stat64(source_path.c_str(), &buf);
event_system::instance().raise<debug_log>(
std::string{function_name}, source_path,
std::to_string(res) + ':' + std::to_string(directory));
#else #else
struct stat buf {}; struct stat buf {};
stat(source_path.c_str(), &buf); stat(source_path.c_str(), &buf);
@ -130,9 +137,15 @@ auto encrypt_provider::create_api_file(
void encrypt_provider::create_item_meta(api_meta_map &meta, bool directory, void encrypt_provider::create_item_meta(api_meta_map &meta, bool directory,
const api_file &file) { const api_file &file) {
static constexpr const std::string_view function_name{
static_cast<const char *>(__FUNCTION__),
};
#if defined(_WIN32) #if defined(_WIN32)
struct _stat64 buf {}; struct _stat64 buf {};
_stat64(file.source_path.c_str(), &buf); auto res = _stat64(file.source_path.c_str(), &buf);
event_system::instance().raise<debug_log>(
std::string{function_name}, file.source_path, std::to_string(res));
#else #else
struct stat buf {}; struct stat buf {};
stat(file.source_path.c_str(), &buf); stat(file.source_path.c_str(), &buf);
@ -191,7 +204,11 @@ auto encrypt_provider::do_fs_operation(
: api_error::item_not_found; : api_error::item_not_found;
} }
auto exists = utils::file::file(source_path).exists(); auto exists =
utils::file::file{
source_path,
}
.exists();
if (exists && directory) { if (exists && directory) {
return api_error::item_exists; return api_error::item_exists;
} }
@ -199,7 +216,11 @@ auto encrypt_provider::do_fs_operation(
return api_error::item_not_found; return api_error::item_not_found;
} }
exists = utils::file::directory(source_path).exists(); exists =
utils::file::directory{
source_path,
}
.exists();
if (exists && not directory) { if (exists && not directory) {
return api_error::item_exists; return api_error::item_exists;
} }
@ -265,10 +286,7 @@ auto encrypt_provider::get_directory_item_count(
[&api_path, &count](const encrypt_config & /* cfg */, [&api_path, &count](const encrypt_config & /* cfg */,
const std::string &source_path) -> api_error { const std::string &source_path) -> api_error {
try { try {
for ([[maybe_unused]] const auto &dir_entry : count = utils::file::directory{source_path}.count();
std::filesystem::directory_iterator(source_path)) {
count++;
}
} catch (const std::exception &ex) { } catch (const std::exception &ex) {
utils::error::raise_api_path_error( utils::error::raise_api_path_error(
function_name, api_path, source_path, ex, function_name, api_path, source_path, ex,
@ -295,15 +313,15 @@ auto encrypt_provider::get_directory_items(
[this, &list](const encrypt_config &cfg, [this, &list](const encrypt_config &cfg,
const std::string &source_path) -> api_error { const std::string &source_path) -> api_error {
try { try {
for (const auto &dir_entry : for (auto &&dir_entry :
std::filesystem::directory_iterator(source_path)) { utils::file::directory{source_path}.get_items()) {
try { try {
std::string current_api_path{}; std::string current_api_path{};
if (dir_entry.is_directory()) { if (dir_entry->is_directory_item()) {
auto result = db::db_select{*db_, directory_table} auto result = db::db_select{*db_, directory_table}
.column("api_path") .column("api_path")
.where("source_path") .where("source_path")
.equals(dir_entry.path().string()) .equals(dir_entry->get_path())
.go(); .go();
std::optional<db::db_select::row> row; std::optional<db::db_select::row> row;
if (result.get_row(row) && row.has_value()) { if (result.get_row(row) && row.has_value()) {
@ -311,12 +329,13 @@ auto encrypt_provider::get_directory_items(
row->get_column("api_path").get_value<std::string>(); row->get_column("api_path").get_value<std::string>();
} }
if (current_api_path.empty()) { 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} result = db::db_select{*db_, directory_table}
.column("api_path") .column("api_path")
.where("source_path") .where("source_path")
.equals(dir_entry.path().string()) .equals(dir_entry->get_path())
.go(); .go();
row.reset(); row.reset();
if (not(result.get_row(row) && row.has_value())) { if (not(result.get_row(row) && row.has_value())) {
@ -331,7 +350,7 @@ auto encrypt_provider::get_directory_items(
auto result = db::db_select{*db_, file_table} auto result = db::db_select{*db_, file_table}
.column("data") .column("data")
.where("source_path") .where("source_path")
.equals(dir_entry.path().string()) .equals(dir_entry->get_path())
.go(); .go();
std::optional<db::db_select::row> row; std::optional<db::db_select::row> row;
if (result.get_row(row) && row.has_value()) { if (result.get_row(row) && row.has_value()) {
@ -340,7 +359,7 @@ auto encrypt_provider::get_directory_items(
} }
if (api_path_data.empty()) { 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)) { current_api_path)) {
continue; continue;
} }
@ -351,14 +370,14 @@ auto encrypt_provider::get_directory_items(
} }
} }
auto file = auto file = create_api_file(current_api_path,
create_api_file(current_api_path, dir_entry.is_directory(), dir_entry->is_directory_item(),
dir_entry.path().string()); dir_entry->get_path());
directory_item dir_item{}; directory_item dir_item{};
dir_item.api_parent = file.api_parent; dir_item.api_parent = file.api_parent;
dir_item.api_path = file.api_path; 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.resolved = true;
dir_item.size = file.file_size; dir_item.size = file.file_size;
create_item_meta(dir_item.meta, dir_item.directory, file); create_item_meta(dir_item.meta, dir_item.directory, file);
@ -366,7 +385,7 @@ auto encrypt_provider::get_directory_items(
list.emplace_back(std::move(dir_item)); list.emplace_back(std::move(dir_item));
} catch (const std::exception &ex) { } catch (const std::exception &ex) {
utils::error::raise_error(function_name, ex, utils::error::raise_error(function_name, ex,
dir_entry.path().string(), dir_entry->get_path(),
"failed to process directory item"); "failed to process directory item");
} }
} }
@ -429,14 +448,17 @@ auto encrypt_provider::get_file_list(api_file_list &list) const -> api_error {
}; };
const auto cfg = config_.get_encrypt_config(); const auto cfg = config_.get_encrypt_config();
event_system::instance().raise<debug_log>(std::string{function_name},
cfg.path, "");
try { try {
for (const auto &dir_entry : for (auto &&dir_entry : utils::file::directory{cfg.path}.get_items()) {
std::filesystem::recursive_directory_iterator(cfg.path)) { event_system::instance().raise<debug_log>(
std::string{function_name}, cfg.path, dir_entry->get_path());
std::string api_path{}; std::string api_path{};
if (process_directory_entry(dir_entry, cfg, api_path)) { if (process_directory_entry(*dir_entry.get(), cfg, api_path)) {
list.emplace_back(create_api_file(api_path, dir_entry.is_directory(), list.emplace_back(create_api_file(
dir_entry.path().string())); api_path, dir_entry->is_directory_item(), dir_entry->get_path()));
} }
} }
@ -481,6 +503,10 @@ auto encrypt_provider::get_file_size(
auto encrypt_provider::get_filesystem_item( auto encrypt_provider::get_filesystem_item(
const std::string &api_path, bool directory, const std::string &api_path, bool directory,
filesystem_item &fsi) const -> api_error { filesystem_item &fsi) const -> api_error {
static constexpr const std::string_view function_name{
static_cast<const char *>(__FUNCTION__),
};
auto result = db::db_select{*db_, source_table} auto result = db::db_select{*db_, source_table}
.column("source_path") .column("source_path")
.where("api_path") .where("api_path")
@ -493,6 +519,9 @@ auto encrypt_provider::get_filesystem_item(
auto source_path = row->get_column("source_path").get_value<std::string>(); auto source_path = row->get_column("source_path").get_value<std::string>();
event_system::instance().raise<debug_log>(
std::string{function_name}, source_path, std::to_string(directory));
if (directory) { if (directory) {
result = db::db_select{*db_, directory_table} result = db::db_select{*db_, directory_table}
.column("api_path") .column("api_path")
@ -583,6 +612,10 @@ auto encrypt_provider::get_pinned_files() const -> std::vector<std::string> {
auto encrypt_provider::get_item_meta(const std::string &api_path, auto encrypt_provider::get_item_meta(const std::string &api_path,
api_meta_map &meta) const -> api_error { api_meta_map &meta) const -> api_error {
static constexpr const std::string_view function_name{
static_cast<const char *>(__FUNCTION__),
};
auto result = db::db_select{*db_, source_table} auto result = db::db_select{*db_, source_table}
.column("source_path") .column("source_path")
.where("api_path") .where("api_path")
@ -602,6 +635,8 @@ auto encrypt_provider::get_item_meta(const std::string &api_path,
} }
auto file = create_api_file(api_path, exists, source_path); auto file = create_api_file(api_path, exists, source_path);
event_system::instance().raise<debug_log>(
std::string{function_name}, api_path, exists ? "true" : "false");
create_item_meta(meta, exists, file); create_item_meta(meta, exists, file);
return api_error::success; return api_error::success;
} }
@ -655,8 +690,10 @@ auto encrypt_provider::is_directory(const std::string &api_path,
return api_error::success; return api_error::success;
} }
exists = utils::file::directory( exists =
row->get_column("source_path").get_value<std::string>()) utils::file::directory{
row->get_column("source_path").get_value<std::string>(),
}
.exists(); .exists();
return api_error::success; return api_error::success;
} }
@ -675,7 +712,9 @@ auto encrypt_provider::is_file(const std::string &api_path,
} }
exists = 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(); .exists();
return api_error::success; return api_error::success;
} }
@ -686,20 +725,24 @@ auto encrypt_provider::is_file_writeable(const std::string & /*api_path*/) const
} }
auto encrypt_provider::is_online() const -> bool { auto encrypt_provider::is_online() const -> bool {
return std::filesystem::exists(config_.get_encrypt_config().path); return utils::file::directory{
config_.get_encrypt_config().path,
}
.exists();
} }
auto encrypt_provider::is_rename_supported() const -> bool { return false; } auto encrypt_provider::is_rename_supported() const -> bool { return false; }
auto encrypt_provider::process_directory_entry( auto encrypt_provider::process_directory_entry(
const std::filesystem::directory_entry &dir_entry, const utils::file::i_fs_item &dir_entry, const encrypt_config &cfg,
const encrypt_config &cfg, std::string &api_path) const -> bool { std::string &api_path) const -> bool {
const auto add_directory = [this, &cfg](auto dir_path) -> std::string { const auto add_directory = [this,
&cfg](std::string_view dir_path) -> std::string {
auto encrypted_parts = utils::string::split( 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(); for (std::size_t part_idx = 1U; part_idx < encrypted_parts.size();
part_idx++) { ++part_idx) {
data_buffer encrypted_data; data_buffer encrypted_data;
utils::encryption::encrypt_data( utils::encryption::encrypt_data(
cfg.encryption_token, cfg.encryption_token,
@ -714,14 +757,9 @@ auto encrypt_provider::process_directory_entry(
std::size_t current_idx{1U}; std::size_t current_idx{1U};
std::string current_encrypted_path{}; std::string current_encrypted_path{};
std::string current_source_path{cfg.path}; auto current_source_path{cfg.path};
for (const auto &part : dir_path) { for (auto &&part : utils::path::get_parts(dir_path)) {
if (part.string() == "/") { current_source_path = utils::path::combine(current_source_path, {part});
continue;
}
current_source_path =
utils::path::combine(current_source_path, {part.string()});
std::string current_api_path{}; std::string current_api_path{};
auto result = db::db_select{*db_, directory_table} auto result = db::db_select{*db_, directory_table}
@ -763,19 +801,21 @@ auto encrypt_provider::process_directory_entry(
return current_encrypted_path; return current_encrypted_path;
}; };
if (dir_entry.is_directory()) { if (dir_entry.is_directory_item()) {
api_path = add_directory(dir_entry.path().lexically_relative(cfg.path)); api_path = add_directory(
utils::path::get_relative_path(dir_entry.get_path(), cfg.path));
return false; return false;
} }
if (dir_entry.is_regular_file() && not dir_entry.is_symlink()) { if (dir_entry.is_file_item() && not dir_entry.is_symlink()) {
const auto relative_path = dir_entry.path().lexically_relative(cfg.path); auto relative_path =
utils::path::get_relative_path(dir_entry.get_path(), cfg.path);
std::string api_path_data{}; std::string api_path_data{};
auto result = db::db_select{*db_, file_table} auto result = db::db_select{*db_, file_table}
.column("data") .column("data")
.where("source_path") .where("source_path")
.equals(dir_entry.path().string()) .equals(dir_entry.get_path())
.go(); .go();
std::optional<db::db_select::row> row; std::optional<db::db_select::row> row;
if (result.get_row(row) && row.has_value()) { if (result.get_row(row) && row.has_value()) {
@ -786,7 +826,7 @@ auto encrypt_provider::process_directory_entry(
result = db::db_select{*db_, directory_table} result = db::db_select{*db_, directory_table}
.column("api_path") .column("api_path")
.where("source_path") .where("source_path")
.equals(dir_entry.path().parent_path().string()) .equals(utils::path::get_parent_path(dir_entry.get_path()))
.go(); .go();
row.reset(); row.reset();
if (result.get_row(row) && row.has_value()) { if (result.get_row(row) && row.has_value()) {
@ -794,15 +834,15 @@ auto encrypt_provider::process_directory_entry(
} }
if (api_parent.empty()) { 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()) { if (api_path_data.empty()) {
stop_type stop_requested = false; stop_type stop_requested = false;
utils::encryption::encrypting_reader reader( 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, 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 + "/" + api_path = utils::path::create_api_path(api_parent + "/" +
reader.get_encrypted_file_name()); reader.get_encrypted_file_name());
@ -810,17 +850,22 @@ auto encrypt_provider::process_directory_entry(
json data = { json data = {
{"api_path", api_path}, {"api_path", api_path},
{"iv_list", iv_list}, {"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} 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()) .column_value("data", data.dump())
.go(); .go();
// TODO handle error // TODO handle error
ins_res = db::db_insert{*db_, source_table} ins_res = db::db_insert{*db_, source_table}
.column_value("api_path", api_path) .column_value("api_path", api_path)
.column_value("source_path", dir_entry.path().string()) .column_value("source_path", dir_entry.get_path())
.go(); .go();
// TODO handle error // TODO handle error
event_system::instance().raise<filesystem_item_added>(api_path, event_system::instance().raise<filesystem_item_added>(api_path,
@ -886,13 +931,12 @@ auto encrypt_provider::read_file_bytes(const std::string &api_path,
unique_recur_mutex_lock reader_lookup_lock(reader_lookup_mtx_); unique_recur_mutex_lock reader_lookup_lock(reader_lookup_mtx_);
if (file_data.at("original_file_size").get<std::uint64_t>() != file_size) { if (file_data.at("original_file_size").get<std::uint64_t>() != file_size) {
const auto relative_path = auto relative_path = utils::path::get_relative_path(source_path, cfg.path);
std::filesystem::path(source_path).lexically_relative(cfg.path);
auto info = std::make_shared<reader_info>(); auto info = std::make_shared<reader_info>();
info->reader = std::make_unique<utils::encryption::encrypting_reader>( info->reader = std::make_unique<utils::encryption::encrypting_reader>(
relative_path.filename().string(), source_path, stop_requested, relative_path, source_path, stop_requested, cfg.encryption_token,
cfg.encryption_token, relative_path.parent_path().string()); utils::path::get_parent_path(relative_path));
reader_lookup_[source_path] = info; reader_lookup_[source_path] = info;
iv_list = info->reader->get_iv_list(); iv_list = info->reader->get_iv_list();
@ -963,9 +1007,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>(); 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>(); auto api_path = row.get_column("api_path").get_value<std::string>();
result = db::db_select{*db_, file_table} result = db::db_select{*db_, file_table}
.column("source_path") .column("source_path")
@ -977,7 +1021,7 @@ void encrypt_provider::remove_deleted_files() {
} }
} }
for (const auto &item : removed_list) { for (auto &&item : removed_list) {
if (not item.directory) { if (not item.directory) {
auto del_res = db::db_select{*db_, source_table} auto del_res = db::db_select{*db_, source_table}
.delete_query() .delete_query()
@ -996,7 +1040,7 @@ void encrypt_provider::remove_deleted_files() {
} }
} }
for (const auto &item : removed_list) { for (auto &&item : removed_list) {
if (item.directory) { if (item.directory) {
auto del_res = db::db_select{*db_, source_table} auto del_res = db::db_select{*db_, source_table}
.delete_query() .delete_query()
@ -1041,7 +1085,7 @@ auto encrypt_provider::start(api_item_added_callback /*api_item_added*/,
} }
db_.reset(db3); db_.reset(db3);
for (const auto &create : sql_create_tables) { for (auto &&create : sql_create_tables) {
std::string err; std::string err;
if (not db::execute_sql(*db_, create.second, err)) { if (not db::execute_sql(*db_, create.second, err)) {
utils::error::raise_error(function_name, "failed to create table|" + 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 // TODO handle error
} }
for (const auto &item : meta) { for (auto &&item : meta) {
existing_meta[item.first] = item.second; 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_key{'/'};
std::string cur_path{'/'}; 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) { if (is_encrypted) {
cur_key = utils::path::create_api_path( 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( 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{}; api_meta_map meta{};
auto res = get_item_meta(cur_path, 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 auto s3_provider::decrypt_object_name(std::string &object_name) const
-> api_error { -> api_error {
auto parts = utils::string::split(object_name, '/', false); auto parts = utils::string::split(object_name, '/', false);
for (auto &part : parts) { for (auto &&part : parts) {
if (not utils::encryption::decrypt_file_name( if (not utils::encryption::decrypt_file_name(
get_config().get_s3_config().encryption_token, part)) { get_config().get_s3_config().encryption_token, part)) {
return api_error::decryption_error; 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"); auto node_list = doc.select_nodes("/ListBucketResult/CommonPrefixes/Prefix");
for (const auto &node : node_list) { for (auto &&node : node_list) {
add_directory_item( add_directory_item(
true, node.node().text().as_string(), true, node.node().text().as_string(),
[](const directory_item &) -> std::uint64_t { return 0U; }); [](const directory_item &) -> std::uint64_t { return 0U; });
} }
node_list = doc.select_nodes("/ListBucketResult/Contents"); 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( auto child_object_name = utils::path::create_api_path(
node.node().select_node("Key").node().text().as_string()); node.node().select_node("Key").node().text().as_string());
if (child_object_name != utils::path::create_api_path(prefix)) { 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"); auto node_list = doc.select_nodes("/ListBucketResult/Contents");
for (const auto &node : node_list) { for (auto &&node : node_list) {
auto api_path = auto api_path =
std::string{node.node().select_node("Key").node().text().as_string()}; std::string{node.node().select_node("Key").node().text().as_string()};
if (not utils::string::ends_with(api_path, "/")) { 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, &stop_requested](std::size_t read_size, std::size_t read_offset,
data_buffer &read_buffer) -> api_error { data_buffer &read_buffer) -> api_error {
auto res = api_error::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 && not stop_requested && res != api_error::success &&
i < get_config().get_retry_read_count() + 1U; idx < get_config().get_retry_read_count() + 1U;
i++) { ++idx) {
curl::requests::http_get get{}; curl::requests::http_get get{};
get.aws_service = "aws:amz:" + cfg.region + ":s3"; get.aws_service = "aws:amz:" + cfg.region + ":s3";
get.headers["response-content-type"] = "binary/octet-stream"; 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, function_name, api_path, api_error::comm_error,
"read file bytes failed|offset|" + std::to_string(read_offset) + "read file bytes failed|offset|" + std::to_string(read_offset) +
"|size|" + std::to_string(read_size) + "|retry|" + "|size|" + std::to_string(read_size) + "|retry|" +
std::to_string(i + 1U)); std::to_string(idx + 1U));
} else { } else {
utils::error::raise_api_path_error( utils::error::raise_api_path_error(
function_name, api_path, response_code, function_name, api_path, response_code,
"read file bytes failed|offset|" + std::to_string(read_offset) + "read file bytes failed|offset|" + std::to_string(read_offset) +
"|size|" + std::to_string(read_size) + "|retry|" + "|size|" + std::to_string(read_size) + "|retry|" +
std::to_string(i + 1U)); std::to_string(idx + 1U));
} }
std::this_thread::sleep_for(1s); 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{}; std::uint64_t item_count{};
if (object_list.contains("entries")) { if (object_list.contains("entries")) {
for (const auto &entry : object_list.at("entries")) { for (auto &&entry : object_list.at("entries")) {
try { try {
auto name = entry.at("name").get<std::string>(); auto name = entry.at("name").get<std::string>();
auto entry_api_path = utils::path::create_api_path(name); 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")) { if (object_list.contains("entries")) {
for (const auto &entry : object_list.at("entries")) { for (auto &&entry : object_list.at("entries")) {
try { try {
auto name = entry.at("name").get<std::string>(); auto name = entry.at("name").get<std::string>();
auto entry_api_path = utils::path::create_api_path(name); 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")) { 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 name = entry.at("name").get<std::string>();
auto entry_api_path = utils::path::create_api_path(name); 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; }; long /*response_code*/) { buffer = data; };
auto res = api_error::comm_error; auto res = api_error::comm_error;
for (std::uint32_t i = 0U; not stop_requested && res != api_error::success && for (std::uint32_t idx = 0U;
i < get_config().get_retry_read_count() + 1U; not stop_requested && res != api_error::success &&
i++) { idx < get_config().get_retry_read_count() + 1U;
++idx) {
long response_code{}; long response_code{};
const auto notify_retry = [&]() { const auto notify_retry = [&]() {
if (response_code == 0) { 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, function_name, api_path, api_error::comm_error,
"read file bytes failed|offset|" + std::to_string(offset) + "read file bytes failed|offset|" + std::to_string(offset) +
"|size|" + std::to_string(size) + "|retry|" + "|size|" + std::to_string(size) + "|retry|" +
std::to_string(i + 1U)); std::to_string(idx + 1U));
} else { } else {
utils::error::raise_api_path_error( utils::error::raise_api_path_error(
function_name, api_path, response_code, function_name, api_path, response_code,
"read file bytes failed|offset|" + std::to_string(offset) + "read file bytes failed|offset|" + std::to_string(offset) +
"|size|" + std::to_string(size) + "|retry|" + "|size|" + std::to_string(size) + "|retry|" +
std::to_string(i + 1U)); std::to_string(idx + 1U));
} }
std::this_thread::sleep_for(1s); std::this_thread::sleep_for(1s);
}; };

View File

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

View File

@ -1,7 +1,6 @@
#!/bin/bash #!/bin/bash
PROJECT_LIBRARIES=( PROJECT_LIBRARIES=(
BACKWARD_CPP
BOOST BOOST
CPP_HTTPLIB CPP_HTTPLIB
CURL CURL
@ -18,7 +17,6 @@ PROJECT_LIBRARIES=(
) )
declare -A PROJECT_CLEANUP declare -A PROJECT_CLEANUP
PROJECT_CLEANUP[BACKWARD_CPP]="include/backward.hpp:src/backward.cpp"
PROJECT_CLEANUP[BOOST]="3rd_party/boost_*" PROJECT_CLEANUP[BOOST]="3rd_party/boost_*"
PROJECT_CLEANUP[CPP_HTTPLIB]="3rd_party/cpp-httplib-*" PROJECT_CLEANUP[CPP_HTTPLIB]="3rd_party/cpp-httplib-*"
PROJECT_CLEANUP[CURL]="3rd_party/curl-*" PROJECT_CLEANUP[CURL]="3rd_party/curl-*"

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -102,6 +102,12 @@ struct i_fs_item {
[[nodiscard]] virtual auto is_directory_item() const -> bool = 0; [[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::string_view new_path) -> bool = 0;
[[nodiscard]] virtual auto move_to(std::wstring_view new_path) -> bool { [[nodiscard]] virtual auto move_to(std::wstring_view new_path) -> bool {
@ -279,7 +285,9 @@ public:
[[nodiscard]] auto is_read_only() const -> bool override { [[nodiscard]] auto is_read_only() const -> bool override {
return read_only_; return read_only_;
}; }
[[nodiscard]] auto is_symlink() const -> bool override;
[[nodiscard]] auto move_to(std::string_view new_path) -> 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 { [[nodiscard]] auto is_read_only() const -> bool override {
return file_->is_read_only(); 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; [[nodiscard]] auto move_to(std::string_view new_path) -> bool override;
@ -489,7 +501,11 @@ public:
[[nodiscard]] auto is_read_only() const -> bool override { [[nodiscard]] auto is_read_only() const -> bool override {
return file_->is_read_only(); 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; [[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 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 move_to(std::string_view new_path) -> bool override;
[[nodiscard]] auto remove() -> bool override; [[nodiscard]] auto remove() -> bool override;
@ -724,8 +742,9 @@ public:
[[nodiscard]] auto is_read_only() const -> bool override { [[nodiscard]] auto is_read_only() const -> bool override {
return read_only_; return read_only_;
}; }
[[nodiscard]] auto is_symlink() const -> bool override;
[[nodiscard]] auto move_to(std::string_view new_path) -> bool override; [[nodiscard]] auto move_to(std::string_view new_path) -> bool override;
[[nodiscard]] auto open(bool read_only) -> bool; [[nodiscard]] auto open(bool read_only) -> bool;
@ -853,6 +872,8 @@ public:
return smb_get_uri_path(path_, user, password); 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 move_to(std::string_view new_path) -> bool override;
[[nodiscard]] auto remove() -> 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) [[nodiscard]] auto inline create_api_path(std::wstring_view path)
-> std::wstring; -> 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::string_view path) -> std::string;
[[nodiscard]] inline auto finalize(std::wstring_view path) -> std::wstring; [[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 [[nodiscard]] inline auto
get_parent_api_path(std::wstring_view path) -> std::wstring; 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; [[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 { inline auto get_parent_api_path(std::wstring_view path) -> std::wstring {
return get_parent_api_path_t<std::wstring>(path); 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 } // namespace repertory::utils::path
#endif // REPERTORY_INCLUDE_UTILS_PATH_HPP_ #endif // REPERTORY_INCLUDE_UTILS_PATH_HPP_

View File

@ -1,45 +0,0 @@
// Pick your poison.
//
// On GNU/Linux, you have few choices to get the most out of your stack trace.
//
// By default you get:
// - object filename
// - function name
//
// In order to add:
// - source filename
// - line and column numbers
// - source code snippet (assuming the file is accessible)
// Install one of the following libraries then uncomment one of the macro (or
// better, add the detection of the lib and the macro definition in your build
// system)
// - apt-get install libdw-dev ...
// - g++/clang++ -ldw ...
// #define BACKWARD_HAS_DW 1
// - apt-get install binutils-dev ...
// - g++/clang++ -lbfd ...
// #define BACKWARD_HAS_BFD 1
// - apt-get install libdwarf-dev ...
// - g++/clang++ -ldwarf ...
// #define BACKWARD_HAS_DWARF 1
// Regardless of the library you choose to read the debug information,
// for potentially more detailed stack traces you can use libunwind
// - apt-get install libunwind-dev
// - g++/clang++ -lunwind
// #define BACKWARD_HAS_LIBUNWIND 1
#include "backward.hpp"
#if defined(PROJECT_ENABLE_BACKWARD_CPP)
namespace backward {
backward::SignalHandling sh;
} // namespace backward
#endif // defined(PROJECT_ENABLE_BACKWARD_CPP)

View File

@ -328,6 +328,22 @@ auto directory::get_items() const -> std::vector<fs_item_t> {
return {}; 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::move_to(std::string_view new_path) -> bool { return false; }
auto directory::remove() -> bool { 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); 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 { auto file::move_to(std::string_view path) -> bool {
static constexpr const std::string_view function_name{ static constexpr const std::string_view function_name{
static_cast<const char *>(__FUNCTION__), static_cast<const char *>(__FUNCTION__),

View File

@ -484,6 +484,25 @@ auto smb_directory::get_items() const -> std::vector<fs_item_t> {
return {}; 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 { auto smb_directory::move_to(std::string_view new_path) -> bool {
static constexpr const std::string_view function_name{ static constexpr const std::string_view function_name{
static_cast<const char *>(__FUNCTION__), static_cast<const char *>(__FUNCTION__),

View File

@ -139,6 +139,25 @@ auto smb_file::get_time(smb_session *session, smb_tid tid, std::string path,
return 0U; 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 { auto smb_file::move_to(std::string_view new_path) -> bool {
static constexpr const std::string_view function_name{ static constexpr const std::string_view function_name{
static_cast<const char *>(__FUNCTION__), static_cast<const char *>(__FUNCTION__),

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))); 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) auto find_program_in_path(const std::string &name_without_extension)
-> std::string { -> std::string {
static std::mutex mtx{}; 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 = ':'; static constexpr const auto split_char = ':';
#endif // defined(_WIN32) #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 &&search_path : search_path_list) {
for (auto &&extension : extension_list) { for (auto &&extension : extension_list) {
auto exec_path = combine( 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))); 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); auto abs_path = absolute(path);
#if defined(_WIN32) #if defined(_WIN32)
@ -177,9 +186,32 @@ auto get_parent_directory(std::string_view path) -> std::string {
return finalize(abs_path); 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( 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 { 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) { for (auto &&path : generated_files) {
if (parent_path->empty()) { if (parent_path->empty()) {
parent_path = 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(); [[maybe_unused]] auto removed = path->remove();

View File

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