about summary refs log tree commit diff
path: root/src/libutil
diff options
context:
space:
mode:
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/archive.cc3
-rw-r--r--src/libutil/util.cc7
-rw-r--r--src/libutil/util.hh3
3 files changed, 11 insertions, 2 deletions
diff --git a/src/libutil/archive.cc b/src/libutil/archive.cc
index b19ff4bf99a1..ab4cd47351b3 100644
--- a/src/libutil/archive.cc
+++ b/src/libutil/archive.cc
@@ -319,8 +319,7 @@ struct RestoreSink : ParseSink
     void createSymlink(const Path & path, const string & target)
     {
         Path p = dstPath + path;
-        if (symlink(target.c_str(), p.c_str()) == -1)
-            throw SysError(format("creating symlink `%1%'") % p);
+        nix::createSymlink(target, p);
     }
 };
 
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index 740d767a4ea6..b264fc5f3d13 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -386,6 +386,13 @@ Paths createDirs(const Path & path)
 }
 
 
+void createSymlink(const Path & target, const Path & link)
+{
+    if (symlink(target.c_str(), link.c_str()))
+        throw SysError(format("creating symlink from `%1%' to `%2%'") % link % target);
+}
+
+
 LogType logType = ltPretty;
 Verbosity verbosity = lvlInfo;
 
diff --git a/src/libutil/util.hh b/src/libutil/util.hh
index 0351220c2a24..5d0408f9b528 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -93,6 +93,9 @@ Path createTempDir(const Path & tmpRoot = "", const Path & prefix = "nix",
    list of created directories, in order of creation. */
 Paths createDirs(const Path & path);
 
+/* Create a symlink. */
+void createSymlink(const Path & target, const Path & link);
+
 
 template<class T, class A>
 T singleton(const A & a)