aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/util.cc
diff options
context:
space:
mode:
authorArtemis Tosini <lix@artem.ist>2024-05-19 22:07:58 +0000
committerArtemis Tosini <lix@artem.ist>2024-05-19 22:07:58 +0000
commit5411fbf20467c5dd561048311519056688b1154d (patch)
tree96f46127cb5c10d16a77633fe836b6858c4b0876 /src/libutil/util.cc
parent139d31f87658c420622f6880a4bdfee8b522f87c (diff)
libutil: Create chmodPath function
Move the identical static `chmod_` functions in libstore to libutil. the function is called `chmodPath` instead of `chmod` as otherwise it will shadow the standard library chmod in the nix namespace, which is somewhat confusing. Change-Id: I7b5ce379c6c602e3d3a1bbc49dbb70b1ae8f7bad
Diffstat (limited to 'src/libutil/util.cc')
-rw-r--r--src/libutil/util.cc8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index bc2dd1802..2c0fcc897 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -184,6 +184,11 @@ Path canonPath(PathView path, bool resolveSymlinks)
return s.empty() ? "/" : std::move(s);
}
+void chmodPath(const Path & path, mode_t mode)
+{
+ if (chmod(path.c_str(), mode) == -1)
+ throw SysError("setting permissions on '%s'", path);
+}
Path dirOf(const PathView path)
{
@@ -1799,8 +1804,7 @@ AutoCloseFD createUnixDomainSocket(const Path & path, mode_t mode)
bind(fdSocket.get(), path);
- if (chmod(path.c_str(), mode) == -1)
- throw SysError("changing permissions on '%1%'", path);
+ chmodPath(path.c_str(), mode);
if (listen(fdSocket.get(), 100) == -1)
throw SysError("cannot listen on socket '%1%'", path);