diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 353097f89..b2df14968 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -352,6 +352,10 @@ Path EvalState::checkSourcePath(const Path & path_) { if (!allowedPaths) return path_; + auto i = resolvedPaths.find(path_); + if (i != resolvedPaths.end()) + return i->second; + bool found = false; for (auto & i : *allowedPaths) { @@ -369,8 +373,10 @@ Path EvalState::checkSourcePath(const Path & path_) Path path = canonPath(path_, true); for (auto & i : *allowedPaths) { - if (isDirOrInDir(path, i)) + if (isDirOrInDir(path, i)) { + resolvedPaths[path_] = path; return path; + } } throw RestrictedPathError("access to path '%1%' is forbidden in restricted mode", path); diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index 86e93a5ac..8594a2707 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -7,6 +7,7 @@ #include "hash.hh" #include +#include namespace nix { @@ -100,6 +101,9 @@ private: std::map> searchPathResolved; + /* Cache used by checkSourcePath(). */ + std::unordered_map resolvedPaths; + public: EvalState(const Strings & _searchPath, ref store);