aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2013-09-03 15:25:51 +0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2013-09-03 15:25:51 +0200
commitc57ed84e286047a9f3c103cf689ae04381c23dad (patch)
tree6131d83676a518b05c081d19f50c556ae36fbd3f /src
parentef4f5ba85e487f567115d60e3cb4b53d81af6ea1 (diff)
Check for name collisions in the input Nix expressions
Diffstat (limited to 'src')
-rw-r--r--src/nix-env/nix-env.cc12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc
index 1e1e4d00d..e4cc66e76 100644
--- a/src/nix-env/nix-env.cc
+++ b/src/nix-env/nix-env.cc
@@ -101,7 +101,7 @@ static bool isNixExpr(const Path & path, struct stat & st)
static void getAllExprs(EvalState & state,
- const Path & path, Value & v)
+ const Path & path, StringSet & attrs, Value & v)
{
Strings names = readDirectory(path);
StringSet namesSorted(names.begin(), names.end());
@@ -126,6 +126,11 @@ static void getAllExprs(EvalState & state,
string attrName = *i;
if (hasSuffix(attrName, ".nix"))
attrName = string(attrName, 0, attrName.size() - 4);
+ if (attrs.find(attrName) != attrs.end()) {
+ printMsg(lvlError, format("warning: name collision in input Nix expressions, skipping `%1%'") % path2);
+ continue;
+ }
+ attrs.insert(attrName);
// FIXME: make loading lazy.
Value & v2(*state.allocAttr(v, state.symbols.create(attrName)));
state.evalFile(path2, v2);
@@ -133,7 +138,7 @@ static void getAllExprs(EvalState & state,
else if (S_ISDIR(st.st_mode))
/* `path2' is a directory (with no default.nix in it);
recurse into it. */
- getAllExprs(state, path2, v);
+ getAllExprs(state, path2, attrs, v);
}
}
@@ -158,7 +163,8 @@ static void loadSourceExpr(EvalState & state, const Path & path, Value & v)
if (S_ISDIR(st.st_mode)) {
state.mkAttrs(v, 16);
state.mkList(*state.allocAttr(v, state.symbols.create("_combineChannels")), 0);
- getAllExprs(state, path, v);
+ StringSet attrs;
+ getAllExprs(state, path, attrs, v);
v.attrs->sort();
}
}