5 Commits

Author SHA1 Message Date
d659a5e04d updated build system
Some checks reported errors
BlockStorage/repertory/pipeline/head Something is wrong with the build of this commit
2024-08-02 22:34:01 -05:00
99c0246720 updated build system 2024-08-02 21:41:44 -05:00
c0dba76ecd fixes 2024-08-02 21:30:17 -05:00
e37a375c18 fix 2024-08-02 21:01:21 -05:00
6718eb374d fix 2024-08-02 20:59:41 -05:00
9 changed files with 157 additions and 97 deletions

View File

@ -55,7 +55,7 @@ public:
get_provider_name(const provider_type &prov) -> std::string;
public:
app_config(const provider_type &prov, const std::string &data_directory = "");
app_config(const provider_type &prov, std::string_view data_directory = "");
~app_config() { save(); }

View File

@ -54,7 +54,7 @@ constexpr const auto retry_save_count = 5U;
namespace repertory {
app_config::app_config(const provider_type &prov,
const std::string &data_directory)
std::string_view data_directory)
: prov_(prov),
api_auth_(utils::generate_random_string(default_api_auth_size)),
api_port_(default_rpc_port(prov)),
@ -151,19 +151,28 @@ auto app_config::default_api_port(const provider_type &prov) -> std::uint16_t {
auto app_config::default_data_directory(const provider_type &prov)
-> std::string {
#if defined(_WIN32)
auto data_directory = utils::path::combine(
utils::get_local_app_data_directory(),
{std::string{REPERTORY_DATA_NAME}, app_config::get_provider_name(prov)});
auto data_directory =
utils::path::combine(utils::get_local_app_data_directory(),
{
REPERTORY_DATA_NAME,
app_config::get_provider_name(prov),
});
#else
#if defined(__APPLE__)
auto data_directory =
utils::path::resolve(std::string{"~/Library/Application Support/"} +
std::string{REPERTORY_DATA_NAME} + '/' +
app_config::get_provider_name(prov));
utils::path::combine("~", {
"Library",
"Application Support",
REPERTORY_DATA_NAME,
app_config::get_provider_name(prov),
});
#else
auto data_directory = utils::path::resolve(
std::string{"~/.local/"} + std::string{REPERTORY_DATA_NAME} + '/' +
app_config::get_provider_name(prov));
auto data_directory =
utils::path::combine("~", {
".local",
REPERTORY_DATA_NAME,
app_config::get_provider_name(prov),
});
#endif
#endif
return data_directory;
@ -318,18 +327,25 @@ auto app_config::get_max_cache_size_bytes() const -> std::uint64_t {
auto app_config::get_provider_api_password(const provider_type &prov)
-> std::string {
#if defined(_WIN32)
auto api_file =
utils::path::combine(utils::get_local_app_data_directory(),
{get_provider_display_name(prov), "apipassword"});
auto api_file = utils::path::combine(utils::get_local_app_data_directory(),
{
get_provider_display_name(prov),
"apipassword",
});
#else
#if defined(__APPLE__)
auto api_file =
utils::path::combine(utils::path::resolve("~"),
{"/Library/Application Support",
get_provider_display_name(prov), "apipassword"});
auto api_file = utils::path::combine("~", {
"/",
"Library",
"Application Support",
get_provider_display_name(prov),
"apipassword",
});
#else
auto api_file = utils::path::combine(
utils::path::resolve("~/."), {get_provider_name(prov), "apipassword"});
auto api_file = utils::path::combine("~/.", {
get_provider_name(prov),
"apipassword",
});
#endif
#endif
auto lines = utils::file::read_file_lines(api_file);
@ -528,6 +544,7 @@ auto app_config::load() -> bool {
auto ret = false;
const auto config_file_path = get_config_file_path();
std::cout << config_file_path << std::endl;
recur_mutex_lock lock(read_write_mutex_);
if (utils::file::is_file(config_file_path)) {
try {

View File

@ -93,11 +93,11 @@ auto lock_data::get_mount_state(json &mount_state) -> bool {
auto lock_data::get_state_directory() -> std::string {
#if defined(__APPLE__)
return utils::path::resolve("~/Library/Application Support/" +
std::string{REPERTORY_DATA_NAME} + "/state");
return utils::path::absolute("~/Library/Application Support/" +
std::string{REPERTORY_DATA_NAME} + "/state");
#else
return utils::path::resolve("~/.local/" + std::string{REPERTORY_DATA_NAME} +
"/state");
return utils::path::absolute("~/.local/" + std::string{REPERTORY_DATA_NAME} +
"/state");
#endif
}

View File

@ -91,6 +91,7 @@ mount(std::vector<const char *> args, std::string data_directory,
#endif
const auto drive_args =
utils::cli::parse_drive_options(args, prov, data_directory);
std::cout << data_directory << std::endl;
app_config config(prov, data_directory);
#if defined(_WIN32)
if (config.get_enable_mount_manager() &&

View File

@ -141,9 +141,9 @@ get_not_directory_seperator<wchar_t>() -> std::basic_string_view<wchar_t> {
return not_directory_seperator_w;
}
[[nodiscard]] inline auto absolute(std::string_view path) -> std::string;
[[nodiscard]] auto absolute(std::string_view path) -> std::string;
[[nodiscard]] inline auto absolute(std::wstring_view path) -> std::wstring;
[[nodiscard]] auto absolute(std::wstring_view path) -> std::wstring;
[[nodiscard]] inline auto
combine(std::string path,
@ -212,12 +212,6 @@ get_parent_api_path(std::wstring_view path) -> std::wstring;
[[nodiscard]] auto remove_file_name(std::wstring_view path) -> std::wstring;
#if !defined(_WIN32)
[[nodiscard]] auto resolve(std::string path) -> std::string;
[[nodiscard]] auto resolve(std::wstring_view path) -> std::wstring;
#endif // !defined(_WIN32)
[[nodiscard]] auto strip_to_file_name(std::string path) -> std::string;
[[nodiscard]] auto strip_to_file_name(std::wstring path) -> std::wstring;
@ -226,14 +220,6 @@ get_parent_api_path(std::wstring_view path) -> std::wstring;
[[nodiscard]] auto unmake_file_uri(std::wstring_view uri) -> std::wstring;
inline auto absolute(std::string_view path) -> std::string {
return std::filesystem::absolute(finalize(path)).lexically_normal().string();
}
inline auto absolute(std::wstring_view path) -> std::wstring {
return std::filesystem::absolute(finalize(path)).lexically_normal().wstring();
}
template <typename string_t>
[[nodiscard]] inline auto combine_t(
string_t path,

View File

@ -21,6 +21,7 @@
*/
#include "utils/common.hpp"
#include "utils/path.hpp"
#include "utils/string.hpp"
namespace repertory::utils {
@ -138,28 +139,7 @@ auto get_next_available_port(std::uint16_t first_port,
#endif // defined(PROJECT_ENABLE_BOOST)
auto resolve_variables(std::string str) -> std::string {
#if defined(HAS_WORDEXP_H)
wordexp_t wt{};
int ret{};
if ((ret = wordexp(std::string{str}.c_str(), &wt, 0)) != 0) {
throw std::runtime_error("'wordexp()' failed|" + std::to_string(ret));
}
str = wt.we_wordv[0U];
wordfree(&wt);
#else // !defined(HAS_WORDEXP_H)
std::string dest;
dest.resize(::ExpandEnvironmentStringsA(str.c_str(), nullptr, 0));
::ExpandEnvironmentStringsA(str.c_str(), dest.data(),
static_cast<DWORD>(dest.size()));
str = std::string(dest.c_str(), strlen(dest.c_str()));
dest.resize(::GetFullPathNameA(str.c_str(), 0, nullptr, nullptr));
::GetFullPathNameA(str.c_str(), static_cast<DWORD>(dest.size()), dest.data(),
nullptr);
str = std::string(dest.c_str(), strlen(dest.c_str()));
#endif // defined(HAS_WORDEXP_H)
return str;
return utils::path::absolute(str);
}
auto resolve_variables(std::wstring_view str) -> std::wstring {

View File

@ -22,6 +22,7 @@
#include "utils/path.hpp"
#include "utils/common.hpp"
#include "utils/error.hpp"
#include "utils/string.hpp"
#include "utils/unix.hpp"
@ -33,9 +34,78 @@ static const std::string directory_seperator_str{
static const std::wstring directory_seperator_str_w{
repertory::utils::path::directory_seperator_w,
};
[[nodiscard]] auto resolve(std::string path) -> std::string {
static constexpr const std::string_view function_name{
static_cast<const char *>(__FUNCTION__),
};
#if defined(HAS_WORDEXP_H)
try {
wordexp_t wt{};
int ret{};
if ((ret = wordexp(path.c_str(), &wt, 0)) != 0) {
throw std::runtime_error("'wordexp()' failed|" + std::to_string(ret) +
'|' + path);
}
path = wt.we_wordv[0U];
wordfree(&wt);
} catch (const std::exception &e) {
repertory::utils::error::handle_exception(function_name, e);
} catch (...) {
repertory::utils::error::handle_exception(function_name);
}
#else // !defined(HAS_WORDEXP_H)
repertory::utils::string::replace(path, "~", "%USERPROFILE%");
std::string dest;
dest.resize(::ExpandEnvironmentStringsA(path.c_str(), nullptr, 0));
::ExpandEnvironmentStringsA(path.c_str(), dest.data(),
static_cast<DWORD>(dest.size()));
path = dest.c_str();
#endif // defined(HAS_WORDEXP_H)
return path;
}
} // namespace
namespace repertory::utils::path {
auto absolute(std::string_view path) -> std::string {
std::string abs_path{path};
#if defined(_WIN32)
if (not abs_path.empty() && ::PathIsRelative(abs_path.c_str())) {
std::string temp;
temp.resize(MAX_PATH + 1);
abs_path = _fullpath(temp.c_str(), abs_path.data(), MAX_PATH);
}
#else // !defined(_WIN32)
abs_path = resolve(finalize(abs_path));
if (not abs_path.empty() && (abs_path.at(0U) != '/')) {
auto found{false};
std::string tmp{abs_path};
do {
auto *res = realpath(tmp.c_str(), nullptr);
if (res) {
abs_path = combine(res, {abs_path.substr(tmp.size())});
free(res);
found = true;
} else if (tmp == ".") {
found = true;
} else {
tmp = dirname(tmp.data());
}
} while (not found);
}
#endif // defined(_WIN32)
return abs_path;
}
auto absolute(std::wstring_view path) -> std::wstring {
return utils::string::from_utf8(absolute(utils::string::to_utf8(path)));
}
auto find_program_in_path(const std::string &name_without_extension)
-> std::string {
static std::mutex mtx{};
@ -151,24 +221,6 @@ auto remove_file_name(std::string_view path) -> std::string {
return abs_path;
}
#if !defined(_WIN32)
auto resolve(std::string path) -> std::string {
std::string home{};
use_getpwuid(getuid(), [&home](struct passwd *pw) {
home = (pw->pw_dir ? pw->pw_dir : "");
if (home.empty() || ((home == "/") && (getuid() != 0))) {
home = combine("/home", {pw->pw_name});
}
});
return absolute(utils::string::replace(path, "~", home));
}
auto resolve(std::wstring_view path) -> std::wstring {
return utils::string::from_utf8(resolve(utils::string::to_utf8(path)));
}
#endif // !defined(_WIN32)
auto strip_to_file_name(std::string path) -> std::string {
#if defined(_WIN32)
return ::PathFindFileName(path.c_str());

View File

@ -21,6 +21,7 @@
*/
#include "gtest/gtest.h"
#include "utils/common.hpp"
#include "utils/path.hpp"
#include "utils/string.hpp"
@ -120,43 +121,43 @@ TEST(utils_path, combine) {
}
TEST(utils_path, format_path) {
std::string path{"\\"};
utils::path::format_path(path, utils::path::directory_seperator,
utils::path::not_directory_seperator);
std::string path{"./"};
utils::path::format_path(path, utils::path::slash, utils::path::backslash);
EXPECT_STREQ(".", path.c_str());
path = "~/.test";
utils::path::format_path(path, utils::path::slash, utils::path::backslash);
EXPECT_STREQ("~/.test", path.c_str());
path = "\\";
utils::path::format_path(path, utils::path::slash, utils::path::backslash);
EXPECT_STREQ("/", path.c_str());
path = "\\\\";
utils::path::format_path(path, utils::path::directory_seperator,
utils::path::not_directory_seperator);
utils::path::format_path(path, utils::path::slash, utils::path::backslash);
EXPECT_STREQ("/", path.c_str());
path = "\\\\\\";
utils::path::format_path(path, utils::path::directory_seperator,
utils::path::not_directory_seperator);
utils::path::format_path(path, utils::path::slash, utils::path::backslash);
EXPECT_STREQ("/", path.c_str());
path = "\\\\\\\\";
utils::path::format_path(path, utils::path::directory_seperator,
utils::path::not_directory_seperator);
utils::path::format_path(path, utils::path::slash, utils::path::backslash);
EXPECT_STREQ("/", path.c_str());
path = "/";
utils::path::format_path(path, utils::path::directory_seperator,
utils::path::not_directory_seperator);
utils::path::format_path(path, utils::path::slash, utils::path::backslash);
EXPECT_STREQ("/", path.c_str());
path = "//";
utils::path::format_path(path, utils::path::directory_seperator,
utils::path::not_directory_seperator);
utils::path::format_path(path, utils::path::slash, utils::path::backslash);
EXPECT_STREQ("/", path.c_str());
path = "///";
utils::path::format_path(path, utils::path::directory_seperator,
utils::path::not_directory_seperator);
utils::path::format_path(path, utils::path::slash, utils::path::backslash);
EXPECT_STREQ("/", path.c_str());
path = "////";
utils::path::format_path(path, utils::path::directory_seperator,
utils::path::not_directory_seperator);
utils::path::format_path(path, utils::path::slash, utils::path::backslash);
EXPECT_STREQ("/", path.c_str());
}
@ -245,4 +246,19 @@ TEST(utils_path, finalize) {
EXPECT_STREQ("/cow/moose/dog/chicken", s.c_str());
#endif
}
TEST(utils_path, absolute) {
auto dir = utils::path::absolute(std::filesystem::current_path().string());
auto path = utils::path::absolute(".");
EXPECT_STREQ(dir.c_str(), path.c_str());
path = utils::path::absolute("./");
EXPECT_STREQ(dir.c_str(), path.c_str());
auto home = utils::path::absolute(utils::get_environment_variable("HOME"));
path = utils::path::absolute("~");
EXPECT_STREQ(home.c_str(), path.c_str());
// path = utils::path::absolute("~/.local");
}
} // namespace repertory

View File

@ -82,6 +82,14 @@ TEST(utils_string, replace) {
std::wstring str_w3{L"///"};
utils::string::replace(str_w3, '/', '\\');
EXPECT_STREQ(L"\\\\\\", str_w3.c_str());
str.clear();
utils::string::replace(str, '/', '\\');
EXPECT_STREQ("", str.c_str());
str_w.clear();
utils::string::replace(str_w, '/', '\\');
EXPECT_STREQ(L"", str_w.c_str());
}
TEST(utils_string, replace_string) {