fixes
This commit is contained in:
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());
|
||||
|
Reference in New Issue
Block a user