From e8a4317f314d34c43823db2a266c94061e51fd9e Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 11 Mar 2025 09:16:18 +0100 Subject: [PATCH] config/Path: simplify tilde expansion --- src/config/Path.cxx | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/config/Path.cxx b/src/config/Path.cxx index b59e35d48..bdeb71443 100644 --- a/src/config/Path.cxx +++ b/src/config/Path.cxx @@ -80,17 +80,12 @@ ParsePath(std::string_view path) if (path.empty()) return GetConfiguredHome(); - if (path.front() == '/') { - path.remove_prefix(1); + const auto [user, rest] = Split(path, '/'); + const auto home = user.empty() + ? GetConfiguredHome() + : GetHome(std::string{user}.c_str()); - return GetConfiguredHome() / - AllocatedPath::FromUTF8Throw(path); - } else { - const auto [user, rest] = Split(path, '/'); - - return GetHome(std::string{user}.c_str()) - / AllocatedPath::FromUTF8Throw(rest); - } + return home / AllocatedPath::FromUTF8Throw(rest); } else if (path.starts_with('$')) { path.remove_prefix(1);