From 690f07272e58bfe86d12adb0bd6c81c031f930fd Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Sun, 25 Aug 2024 11:58:55 -0700 Subject: Support relative and `~/` paths in config settings Change-Id: I5566a9858ba255f4ac5051d1368c7dfb24460f0a --- src/libutil/config.cc | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/libutil/config.cc') 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; 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::parse(const std::string & str, const ApplyConfigOptions & options) const -- cgit v1.2.3