Commit dcd19c05 authored by Max Kellermann's avatar Max Kellermann

config/Path: use StringView::Split()

parent 109159e0
......@@ -23,11 +23,10 @@
#include "fs/Traits.hxx"
#include "fs/StandardDirectory.hxx"
#include "util/RuntimeError.hxx"
#include "util/StringView.hxx"
#include <cassert>
#include <string.h>
#ifndef _WIN32
#include <pwd.h>
......@@ -96,30 +95,18 @@ ParsePath(const char *path)
if (*path == '\0')
return GetConfiguredHome();
AllocatedPath home = nullptr;
if (*path == '/') {
home = GetConfiguredHome();
++path;
} else {
const char *slash = std::strchr(path, '/');
const char *end = slash == nullptr
? path + strlen(path)
: slash;
const std::string user(path, end);
home = GetHome(user.c_str());
if (slash == nullptr)
return home;
return GetConfiguredHome() /
AllocatedPath::FromUTF8Throw(path);
} else {
const auto [user, rest] =
StringView{path}.Split('/');
path = slash + 1;
return GetHome(std::string{user}.c_str())
/ AllocatedPath::FromUTF8Throw(rest);
}
if (home.IsNull())
return nullptr;
return home / AllocatedPath::FromUTF8Throw(path);
} else if (!PathTraitsUTF8::IsAbsolute(path)) {
throw FormatRuntimeError("not an absolute path: %s", path);
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment