diff options
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 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); |