aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/file-system.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/file-system.cc
parent5fc6fcb31035f79a8e590f07d73dc6cc592e9e29 (diff)
Support relative and `~/` paths in config settings
Change-Id: I5566a9858ba255f4ac5051d1368c7dfb24460f0a
Diffstat (limited to 'src/libutil/file-system.cc')
-rw-r--r--src/libutil/file-system.cc15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/libutil/file-system.cc b/src/libutil/file-system.cc
index 631cf076b..234c73163 100644
--- a/src/libutil/file-system.cc
+++ b/src/libutil/file-system.cc
@@ -117,6 +117,21 @@ Path realPath(Path const & path)
return ret;
}
+Path tildePath(Path const & path, const std::optional<Path> & home)
+{
+ if (path.starts_with("~/")) {
+ if (home) {
+ return *home + "/" + path.substr(2);
+ } else {
+ throw UsageError("`~` path not allowed: %1%", path);
+ }
+ } else if (path.starts_with('~')) {
+ throw UsageError("`~` paths must start with `~/`: %1%", path);
+ } else {
+ return path;
+ }
+}
+
void chmodPath(const Path & path, mode_t mode)
{
if (chmod(path.c_str(), mode) == -1)