diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2013-11-19 00:03:11 +0100 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2013-11-19 00:04:11 +0100 |
commit | 77c13cdf566ffedc70d8860571afae8a6d43b552 (patch) | |
tree | 80d2c35c450911d0401e8a95d28ff9d8904b53fc /src/libexpr/eval.cc | |
parent | 285df765b91588e39d6f35a32e30b84c3cb5be75 (diff) |
Add a toJSON primop
Diffstat (limited to 'src/libexpr/eval.cc')
-rw-r--r-- | src/libexpr/eval.cc | 43 |
1 files changed, 23 insertions, 20 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index c2db006c1..3db4bb66f 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); |