Skip to content

Commit

Permalink
callPathFilter(): Pass a lazy store path
Browse files Browse the repository at this point in the history
  • Loading branch information
edolstra committed Apr 30, 2024
1 parent 71575a2 commit 333d35a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
8 changes: 2 additions & 6 deletions src/libexpr/eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ void EvalState::mkPos(Value & v, PosIdx p)
auto origin = positions.originOf(p);
if (auto path = std::get_if<SourcePath>(&origin)) {
auto attrs = buildBindings(3);
attrs.alloc(sFile).mkString(encodePath(*path));
attrs.alloc(sFile).mkString(encodePath(*path)); // FIXME
makePositionThunks(*this, p, attrs.alloc(sLine), attrs.alloc(sColumn));
v.mkAttrs(attrs);
} else
Expand All @@ -977,12 +977,8 @@ void EvalState::mkStorePathString(const StorePath & p, Value & v)

void EvalState::mkPathString(Value & v, const SourcePath & path)
{
assert(path.path.isRoot());

auto s = encodePath(path);

v.mkString(
s,
encodePath(path),
NixStringContext {
NixStringContextElem::InputAccessor { .accessor = path.accessor->number },
});
Expand Down
1 change: 0 additions & 1 deletion src/libexpr/eval.hh
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,6 @@ public:
bool callPathFilter(
Value * filterFun,
const SourcePath & path,
std::string_view pathArg,
PosIdx pos);

private:
Expand Down
11 changes: 8 additions & 3 deletions src/libexpr/primops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2269,15 +2269,20 @@ static RegisterPrimOp primop_toFile({
bool EvalState::callPathFilter(
Value * filterFun,
const SourcePath & path,
std::string_view pathArg,
PosIdx pos)
{
auto st = path.lstat();

/* Call the filter function. The first argument is the path, the
second is a string indicating the type of the file. */
Value arg1;
arg1.mkString(pathArg);
if (path.accessor == rootFS)
arg1.mkString(path.path.abs());
else
/* Backwards compatibility: encode the path as a lazy store
path string with context so that e.g. `dirOf path ==
"/nix/store"`. */
mkPathString(arg1, path);

// assert that type is not "unknown"
Value * args []{&arg1, fileTypeToString(*this, st.type)};
Expand Down Expand Up @@ -2320,7 +2325,7 @@ static void addPath(
if (filterFun)
filter = std::make_unique<PathFilter>([&](const Path & p) {
auto p2 = CanonPath(p);
return state.callPathFilter(filterFun, {path.accessor, p2}, p2.abs(), pos);
return state.callPathFilter(filterFun, {path.accessor, p2}, pos);
});

std::optional<StorePath> expectedStorePath;
Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/primops/filterPath.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct FilterPathInputAccessor : CachingFilteringInputAccessor
return false;
// Note that unlike 'builtins.{path,filterSource}', we don't
// pass the prefix to the filter function.
return state.callPathFilter(filterFun, {next, prefix / path}, path.abs(), pos);
return state.callPathFilter(filterFun, {next, prefix / path}, pos);
}
};

Expand Down

0 comments on commit 333d35a

Please sign in to comment.