aboutsummaryrefslogtreecommitdiff
path: root/src/libutil
diff options
context:
space:
mode:
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/archive.cc9
-rw-r--r--src/libutil/archive.hh2
-rw-r--r--src/libutil/error.hh2
-rw-r--r--src/libutil/util.cc8
-rw-r--r--src/libutil/util.hh7
5 files changed, 15 insertions, 13 deletions
diff --git a/src/libutil/archive.cc b/src/libutil/archive.cc
index 00536c1e1..a18c54ebf 100644
--- a/src/libutil/archive.cc
+++ b/src/libutil/archive.cc
@@ -389,13 +389,4 @@ void copyNAR(Source & source, Sink & sink)
}
-void copyPath(const Path & from, const Path & to)
-{
- auto source = sinkToSource([&](Sink & sink) {
- dumpPath(from, sink);
- });
- restorePath(to, *source);
-}
-
-
}
diff --git a/src/libutil/archive.hh b/src/libutil/archive.hh
index 2cf164a41..017b6633c 100644
--- a/src/libutil/archive.hh
+++ b/src/libutil/archive.hh
@@ -124,8 +124,6 @@ void restorePath(const Path & path, Source & source);
*/
void copyNAR(Source & source, Sink & sink);
-void copyPath(const Path & from, const Path & to);
-
inline constexpr std::string_view narVersionMagic1 = "nix-archive-1";
diff --git a/src/libutil/error.hh b/src/libutil/error.hh
index 924366580..323365d65 100644
--- a/src/libutil/error.hh
+++ b/src/libutil/error.hh
@@ -110,6 +110,8 @@ protected:
public:
BaseError(const BaseError &) = default;
+ BaseError & operator=(BaseError const & rhs) = default;
+
template<typename... Args>
BaseError(unsigned int status, const Args & ... args)
: err { .level = lvlError, .msg = HintFmt(args...), .status = status }
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);
diff --git a/src/libutil/util.hh b/src/libutil/util.hh
index 914d6cce0..14868776c 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -78,6 +78,13 @@ Path absPath(Path path,
Path canonPath(PathView path, bool resolveSymlinks = false);
/**
+ * Change the permissions of a path
+ * Not called `chmod` as it shadows and could be confused with
+ * `int chmod(char *, mode_t)`, which does not handle errors
+ */
+void chmodPath(const Path & path, mode_t mode);
+
+/**
* @return The directory part of the given canonical path, i.e.,
* everything before the final `/`. If the path is the root or an
* immediate child thereof (e.g., `/foo`), this means `/`