aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/config.cc
diff options
context:
space:
mode:
authorRebecca Turner <rbt@sent.as>2024-08-25 11:58:55 -0700
committerRebecca Turner <rbt@sent.as>2024-08-25 15:54:22 -0700
commit690f07272e58bfe86d12adb0bd6c81c031f930fd (patch)
treee01efa0e48d38eb44eb1d3445719a6adab29a33a /src/libutil/config.cc
parent5fc6fcb31035f79a8e590f07d73dc6cc592e9e29 (diff)
Support relative and `~/` paths in config settings
Change-Id: I5566a9858ba255f4ac5051d1368c7dfb24460f0a
Diffstat (limited to 'src/libutil/config.cc')
-rw-r--r--src/libutil/config.cc14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/libutil/config.cc b/src/libutil/config.cc
index 333deb388..778da1413 100644
--- a/src/libutil/config.cc
+++ b/src/libutil/config.cc
@@ -126,7 +126,7 @@ static void applyConfigInner(const std::string & contents, const ApplyConfigOpti
if (!options.path) {
throw UsageError("can only include configuration '%1%' from files", tokens[1]);
}
- auto pathToInclude = absPath(tokens[1], dirOf(*options.path));
+ auto pathToInclude = absPath(tildePath(tokens[1], options.home), dirOf(*options.path));
if (pathExists(pathToInclude)) {
auto includeOptions = ApplyConfigOptions {
.path = pathToInclude,
@@ -437,10 +437,16 @@ template class BaseSetting<DeprecatedFeatures>;
static Path parsePath(const AbstractSetting & s, const std::string & str, const ApplyConfigOptions & options)
{
- if (str == "")
+ if (str == "") {
throw UsageError("setting '%s' is a path and paths cannot be empty", s.name);
- else
- return canonPath(str);
+ } else {
+ auto tildeResolvedPath = tildePath(str, options.home);
+ if (options.path) {
+ return absPath(tildeResolvedPath, dirOf(*options.path));
+ } else {
+ return canonPath(tildeResolvedPath);
+ }
+ }
}
template<> Path PathsSetting<Path>::parse(const std::string & str, const ApplyConfigOptions & options) const