fixes
This commit is contained in:
6
support/3rd_party/include/utils/path.hpp
vendored
6
support/3rd_party/include/utils/path.hpp
vendored
@ -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;
|
||||
|
40
support/3rd_party/src/utils/path.cpp
vendored
40
support/3rd_party/src/utils/path.cpp
vendored
@ -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());
|
||||
|
16
support/3rd_party/test/src/utils/path_test.cpp
vendored
16
support/3rd_party/test/src/utils/path_test.cpp
vendored
@ -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
|
||||
|
Reference in New Issue
Block a user