[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
23/376: findFile: Realise the context of the path attributes
From: |
Ludovic Courtès |
Subject: |
23/376: findFile: Realise the context of the path attributes |
Date: |
Wed, 28 Jan 2015 22:03:47 +0000 |
civodul pushed a commit to tag 1.8
in repository guix.
commit 718f20da6d79466f91c49849bcf91a688aaa871e
Author: Shea Levy <address@hidden>
Date: Fri May 30 15:43:31 2014 -0400
findFile: Realise the context of the path attributes
---
src/libexpr/nixexpr.hh | 1 +
src/libexpr/primops.cc | 62 ++++++++++++++++++++++++++++++++++--------------
2 files changed, 45 insertions(+), 18 deletions(-)
diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/nixexpr.hh
index 3df9dd4..b8d0929 100644
--- a/src/libexpr/nixexpr.hh
+++ b/src/libexpr/nixexpr.hh
@@ -16,6 +16,7 @@ MakeError(ThrownError, AssertionError)
MakeError(Abort, EvalError)
MakeError(TypeError, EvalError)
MakeError(ImportError, EvalError) // error building an imported derivation
+MakeError(FindError, EvalError) // error building a nix-path component
MakeError(UndefinedVarError, Error)
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index f270ca3..fecaf37 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -37,36 +37,52 @@ std::pair<string, string> decodeContext(const string & s)
}
-/* Load and evaluate an expression from path specified by the
- argument. */
-static void prim_scopedImport(EvalState & state, const Pos & pos, Value * *
args, Value & v)
+struct InvalidPathError : EvalError
{
- PathSet context;
- Path path = state.coerceToPath(pos, *args[1], context);
+ Path path;
+ InvalidPathError(const Path & path) :
+ EvalError(format("path `%1%' is not valid") % path), path(path) {};
+};
+
+static void realiseContext(const PathSet & context)
+{
PathSet drvs;
for (auto & i : context) {
std::pair<string, string> decoded = decodeContext(i);
Path ctx = decoded.first;
assert(isStorePath(ctx));
if (!store->isValidPath(ctx))
- throw EvalError(format("cannot import `%1%', since path `%2%' is
not valid, at %3%")
- % path % ctx % pos);
+ throw InvalidPathError(ctx);
if (isDerivation(ctx))
drvs.insert(decoded.first + "!" + decoded.second);
}
if (!drvs.empty()) {
- try {
- /* For performance, prefetch all substitute info. */
- PathSet willBuild, willSubstitute, unknown;
- unsigned long long downloadSize, narSize;
- queryMissing(*store, drvs,
- willBuild, willSubstitute, unknown, downloadSize, narSize);
+ /* For performance, prefetch all substitute info. */
+ PathSet willBuild, willSubstitute, unknown;
+ unsigned long long downloadSize, narSize;
+ queryMissing(*store, drvs,
+ willBuild, willSubstitute, unknown, downloadSize, narSize);
- store->buildPaths(drvs);
- } catch (Error & e) {
- throw ImportError(e.msg());
- }
+ store->buildPaths(drvs);
+ }
+}
+
+
+/* Load and evaluate an expression from path specified by the
+ argument. */
+static void prim_scopedImport(EvalState & state, const Pos & pos, Value * *
args, Value & v)
+{
+ PathSet context;
+ Path path = state.coerceToPath(pos, *args[1], context);
+
+ try {
+ realiseContext(context);
+ } catch (InvalidPathError & e) {
+ throw EvalError(format("cannot import `%1%', since path `%2%' is not
valid, at %3%")
+ % path % e.path % pos);
+ } catch (Error & e) {
+ throw ImportError(e.msg());
}
if (isStorePath(path) && store->isValidPath(path) && isDerivation(path)) {
@@ -660,6 +676,7 @@ static void prim_findFile(EvalState & state, const Pos &
pos, Value * * args, Va
SearchPath searchPath;
+ PathSet context;
for (unsigned int n = 0; n < args[0]->list.length; ++n) {
Value & v2(*args[0]->list.elems[n]);
state.forceAttrs(v2, pos);
@@ -672,13 +689,22 @@ static void prim_findFile(EvalState & state, const Pos &
pos, Value * * args, Va
i = v2.attrs->find(state.symbols.create("path"));
if (i == v2.attrs->end())
throw EvalError(format("attribute `path' missing, at %1%") % pos);
- PathSet context;
string path = state.coerceToPath(pos, *i->value, context);
searchPath.push_back(std::pair<string, Path>(prefix, path));
}
string path = state.forceStringNoCtx(*args[1], pos);
+
+ try {
+ realiseContext(context);
+ } catch (InvalidPathError & e) {
+ throw EvalError(format("cannot find `%1%', since path `%2%' is not
valid, at %3%")
+ % path % e.path % pos);
+ } catch (Error & e) {
+ throw FindError(e.msg());
+ }
+
mkPath(v, state.findFile(searchPath, path).c_str());
}
- 33/376: Manual: html -> xhtml, (continued)
- 33/376: Manual: html -> xhtml, Ludovic Courtès, 2015/01/28
- 25/376: Fix bogus warnings about dumping large paths, Ludovic Courtès, 2015/01/28
- 36/376: Fix compilation error on some versions of GCC, Ludovic Courtès, 2015/01/28
- 37/376: Add a test for the SSH substituter, Ludovic Courtès, 2015/01/28
- 38/376: Fix security hole in ‘nix-store --serve’, Ludovic Courtès, 2015/01/28
- 35/376: Don't build on Ubuntu 10.10, Ludovic Courtès, 2015/01/28
- 34/376: Add builtin function ‘fromJSON’, Ludovic Courtès, 2015/01/28
- 41/376: nix-copy-closure: Restore compression and the progress viewer, Ludovic Courtès, 2015/01/28
- 40/376: Remove maybeVfork, Ludovic Courtès, 2015/01/28
- 39/376: nix-copy-closure: Fix race condition, Ludovic Courtès, 2015/01/28
- 23/376: findFile: Realise the context of the path attributes,
Ludovic Courtès <=
- 44/376: nix-copy-closure: Fix --dry-run, Ludovic Courtès, 2015/01/28
- 46/376: Fix use of sysread, Ludovic Courtès, 2015/01/28
- 45/376: nix-copy-closure -s: Do substitutions via ‘nix-store --serve’, Ludovic Courtès, 2015/01/28
- 48/376: Fix broken Pid constructor, Ludovic Courtès, 2015/01/28
- 42/376: Refactoring: Move all fork handling into a higher-order function, Ludovic Courtès, 2015/01/28
- 49/376: Allow $NIX_BUILD_HOOK to be relative to Nix libexec directory, Ludovic Courtès, 2015/01/28
- 52/376: Fix test, Ludovic Courtès, 2015/01/28
- 54/376: build-remote.pl: Don't keep a shell process around, Ludovic Courtès, 2015/01/28
- 55/376: build-remote.pl: Fix building multiple output derivations, Ludovic Courtès, 2015/01/28
- 47/376: Replace message "importing path <...>" with "exporting path <...>", Ludovic Courtès, 2015/01/28