From 77c13cdf566ffedc70d8860571afae8a6d43b552 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 19 Nov 2013 00:03:11 +0100 Subject: Add a toJSON primop --- src/libexpr/eval.cc | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) (limited to 'src/libexpr/eval.cc') 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); -- cgit 1.4.1