about summary refs log tree commit diff
path: root/src/libexpr/eval.cc
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2013-11-18T23·03+0100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2013-11-18T23·04+0100
commit77c13cdf566ffedc70d8860571afae8a6d43b552 (patch)
tree80d2c35c450911d0401e8a95d28ff9d8904b53fc /src/libexpr/eval.cc
parent285df765b91588e39d6f35a32e30b84c3cb5be75 (diff)
Add a toJSON primop
Diffstat (limited to 'src/libexpr/eval.cc')
-rw-r--r--src/libexpr/eval.cc43
1 files changed, 23 insertions, 20 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index c2db006c1414..3db4bb66f435 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -1163,26 +1163,7 @@ string EvalState::coerceToString(Value & v, PathSet & context,
 
     if (v.type == tPath) {
         Path path(canonPath(v.path));
-
-        if (!copyToStore) return path;
-
-        if (nix::isDerivation(path))
-            throwEvalError("file names are not allowed to end in `%1%'", drvExtension);
-
-        Path dstPath;
-        if (srcToStore[path] != "")
-            dstPath = srcToStore[path];
-        else {
-            dstPath = settings.readOnlyMode
-                ? computeStorePathForPath(path).first
-                : store->addToStore(path, true, htSHA256, defaultPathFilter, repair);
-            srcToStore[path] = dstPath;
-            printMsg(lvlChatty, format("copied source `%1%' -> `%2%'")
-                % path % dstPath);
-        }
-
-        context.insert(dstPath);
-        return dstPath;
+        return copyToStore ? copyPathToStore(context, path) : path;
     }
 
     if (v.type == tAttrs) {
@@ -1218,6 +1199,28 @@ string EvalState::coerceToString(Value & v, PathSet & context,
 }
 
 
+string EvalState::copyPathToStore(PathSet & context, const Path & path)
+{
+    if (nix::isDerivation(path))
+        throwEvalError("file names are not allowed to end in `%1%'", drvExtension);
+
+    Path dstPath;
+    if (srcToStore[path] != "")
+        dstPath = srcToStore[path];
+    else {
+        dstPath = settings.readOnlyMode
+            ? computeStorePathForPath(path).first
+            : store->addToStore(path, true, htSHA256, defaultPathFilter, repair);
+        srcToStore[path] = dstPath;
+        printMsg(lvlChatty, format("copied source `%1%' -> `%2%'")
+            % path % dstPath);
+    }
+
+    context.insert(dstPath);
+    return dstPath;
+}
+
+
 Path EvalState::coerceToPath(Value & v, PathSet & context)
 {
     string path = coerceToString(v, context, false, false);