From c0dba76ecd9648ff00f900dcbfd3d57874655be0 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Fri, 2 Aug 2024 21:30:17 -0500 Subject: [PATCH] fixes --- repertory/librepertory/src/app_config.cpp | 33 +++++++++------ .../src/platform/unix_platform.cpp | 8 ++-- support/3rd_party/include/utils/path.hpp | 6 --- support/3rd_party/src/utils/path.cpp | 40 ++++++++++--------- .../3rd_party/test/src/utils/path_test.cpp | 16 -------- 5 files changed, 46 insertions(+), 57 deletions(-) diff --git a/repertory/librepertory/src/app_config.cpp b/repertory/librepertory/src/app_config.cpp index 2170749b..0c161b14 100644 --- a/repertory/librepertory/src/app_config.cpp +++ b/repertory/librepertory/src/app_config.cpp @@ -159,20 +159,20 @@ auto app_config::default_data_directory(const provider_type &prov) }); #else #if defined(__APPLE__) - auto data_directory = utils::path::resolve( + auto data_directory = utils::path::combine("~", { "Library", "Application Support", REPERTORY_DATA_NAME, app_config::get_provider_name(prov), - })); + }); #else - auto data_directory = utils::path::resolve( + auto data_directory = utils::path::combine("~", { ".local", REPERTORY_DATA_NAME, app_config::get_provider_name(prov), - })); + }); #endif #endif return data_directory; @@ -327,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); diff --git a/repertory/librepertory/src/platform/unix_platform.cpp b/repertory/librepertory/src/platform/unix_platform.cpp index d3557fa0..6f411f8b 100644 --- a/repertory/librepertory/src/platform/unix_platform.cpp +++ b/repertory/librepertory/src/platform/unix_platform.cpp @@ -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 } diff --git a/support/3rd_party/include/utils/path.hpp b/support/3rd_party/include/utils/path.hpp index bfcaedc4..8c64e704 100644 --- a/support/3rd_party/include/utils/path.hpp +++ b/support/3rd_party/include/utils/path.hpp @@ -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; diff --git a/support/3rd_party/src/utils/path.cpp b/support/3rd_party/src/utils/path.cpp index 3679112f..51ff88f9 100644 --- a/support/3rd_party/src/utils/path.cpp +++ b/support/3rd_party/src/utils/path.cpp @@ -33,6 +33,26 @@ static const std::string directory_seperator_str{ static const std::wstring directory_seperator_str_w{ repertory::utils::path::directory_seperator_w, }; + +#if !defined(_WIN32) +[[nodiscard]] auto resolve(std::string path) -> std::string { + std::string home{}; + repertory::utils::use_getpwuid(getuid(), [&home](struct passwd *pw) { + home = (pw->pw_dir ? pw->pw_dir : ""); + if (home.empty() || ((home == "/") && (getuid() != 0))) { + home = repertory::utils::path::combine("/home", {pw->pw_name}); + } + }); + + return repertory::utils::string::replace(path, "~", home); +} + +[[nodiscard]] auto resolve(std::wstring_view path) -> std::wstring { + return repertory::utils::string::from_utf8( + resolve(repertory::utils::string::to_utf8(path))); +} +#endif // !defined(_WIN32) + } // namespace namespace repertory::utils::path { @@ -45,6 +65,8 @@ auto absolute(std::string_view path) -> std::string { abs_path = _fullpath(temp.c_str(), abs_path.data(), MAX_PATH); } #else + abs_path = resolve(abs_path); + if (not abs_path.empty() && (abs_path.at(0U) != '/')) { auto found{false}; std::string tmp{abs_path}; @@ -185,24 +207,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()); diff --git a/support/3rd_party/test/src/utils/path_test.cpp b/support/3rd_party/test/src/utils/path_test.cpp index f6c7ddfb..4cfb25f1 100644 --- a/support/3rd_party/test/src/utils/path_test.cpp +++ b/support/3rd_party/test/src/utils/path_test.cpp @@ -245,20 +245,4 @@ TEST(utils_path, finalize) { EXPECT_STREQ("/cow/moose/dog/chicken", s.c_str()); #endif } - -#if !defined(_WIN32) -TEST(utils_path, resolve) { - std::cout << utils::path::resolve("~") << std::endl; - std::cout << utils::path::combine("~", - { - ".local", - }) - << std::endl; - std::cout << utils::path::resolve(utils::path::combine("~", - { - ".local", - })) - << std::endl; -} -#endif // !defined(_WIN32) } // namespace repertory