aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/file-system.cc
diff options
context:
space:
mode:
authorrebecca “wiggles” turner <rbt@sent.as>2024-09-01 22:06:36 +0000
committerGerrit Code Review <gerrit@localhost>2024-09-01 22:06:36 +0000
commit02eb07cfd539c34c080cb1baf042e5e780c1fcc2 (patch)
tree0397ab434cce8b284a8d447594e2e1f3f35a1470 /src/libutil/file-system.cc
parentd75df91f74b6819f674f0733143fdf32580af183 (diff)
parent690f07272e58bfe86d12adb0bd6c81c031f930fd (diff)
Merge changes I5566a985,I88cf53d3 into main
* changes: Support relative and `~/` paths in config settings Thread `ApplyConfigOptions` through config parsing
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 1d266067e..8c69c9864 100644
--- a/src/libutil/file-system.cc
+++ b/src/libutil/file-system.cc
@@ -118,6 +118,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)