updated build system
This commit is contained in:
@ -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)
|
||||
|
@ -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;
|
||||
|
@ -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_
|
||||
|
@ -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 {
|
||||
|
@ -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__),
|
||||
|
@ -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__),
|
||||
|
@ -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__),
|
||||
|
@ -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 {
|
||||
|
@ -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();
|
||||
|
@ -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)
|
||||
|
Reference in New Issue
Block a user