config/Path: simplify tilde expansion

This commit is contained in:
Max Kellermann
2025-03-11 09:16:18 +01:00
parent f4f5e94a36
commit e8a4317f31

@ -80,17 +80,12 @@ ParsePath(std::string_view path)
if (path.empty()) if (path.empty())
return GetConfiguredHome(); return GetConfiguredHome();
if (path.front() == '/') { const auto [user, rest] = Split(path, '/');
path.remove_prefix(1); const auto home = user.empty()
? GetConfiguredHome()
: GetHome(std::string{user}.c_str());
return GetConfiguredHome() / return home / AllocatedPath::FromUTF8Throw(rest);
AllocatedPath::FromUTF8Throw(path);
} else {
const auto [user, rest] = Split(path, '/');
return GetHome(std::string{user}.c_str())
/ AllocatedPath::FromUTF8Throw(rest);
}
} else if (path.starts_with('$')) { } else if (path.starts_with('$')) {
path.remove_prefix(1); path.remove_prefix(1);