aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2018-05-22 13:02:14 +0200
committerEelco Dolstra <edolstra@gmail.com>2018-05-22 13:02:14 +0200
commit9fd7cf98dbec047343baefa65cd26ce4493bee53 (patch)
treeb9a1e8e121bdd3ee75579c6b4d4bd6cf143722e4
parent9064dd2f4daab34718c0143be235e8eb95c671bd (diff)
Memoise checkSourcePath()
This prevents hydra-eval-jobs from statting the same files over and over again.
-rw-r--r--src/libexpr/eval.cc8
-rw-r--r--src/libexpr/eval.hh4
2 files changed, 11 insertions, 1 deletions
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 <map>
+#include <unordered_map>
namespace nix {
@@ -100,6 +101,9 @@ private:
std::map<std::string, std::pair<bool, std::string>> searchPathResolved;
+ /* Cache used by checkSourcePath(). */
+ std::unordered_map<Path, Path> resolvedPaths;
+
public:
EvalState(const Strings & _searchPath, ref<Store> store);