Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/libfetchers/filtering-source-accessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ std::pair<CanonPath, std::optional<std::string>> FilteringSourceAccessor::getFin
return next->getFingerprint(prefix / path);
}

void FilteringSourceAccessor::invalidateCache(const CanonPath & path)
{
next->invalidateCache(prefix / path);
}

void FilteringSourceAccessor::checkAccess(const CanonPath & path)
{
if (!isAllowed(path))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ struct FilteringSourceAccessor : SourceAccessor

std::pair<CanonPath, std::optional<std::string>> getFingerprint(const CanonPath & path) override;

void invalidateCache(const CanonPath & path) override;

/**
* Call `makeNotAllowedError` to throw a `RestrictedPathError`
* exception if `isAllowed()` returns `false` for `path`.
Expand Down
2 changes: 2 additions & 0 deletions src/libflake/flake.cc
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,8 @@ lockFlake(const Settings & settings, EvalState & state, const FlakeRef & topRef,
CanonPath((topRef.subdir == "" ? "" : topRef.subdir + "/") + "flake.lock"),
newLockFileS,
commitMessage);

flake.lockFilePath().invalidateCache();
}

/* Rewriting the lockfile changed the top-level
Expand Down
2 changes: 2 additions & 0 deletions src/libutil/include/nix/util/posix-source-accessor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public:
return trackLastModified ? std::optional{mtime} : std::nullopt;
}

void invalidateCache(const CanonPath & path) override;

private:

/**
Expand Down
5 changes: 5 additions & 0 deletions src/libutil/include/nix/util/source-accessor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ struct SourceAccessor : std::enable_shared_from_this<SourceAccessor>
{
return std::nullopt;
}

/**
* Invalidate any cached value the accessor may have for the specified path.
*/
virtual void invalidateCache(const CanonPath & path) {}
};

/**
Expand Down
5 changes: 5 additions & 0 deletions src/libutil/include/nix/util/source-path.hh
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ struct SourcePath
return {accessor, accessor->resolveSymlinks(path, mode)};
}

void invalidateCache() const
{
accessor->invalidateCache(path);
}

friend class std::hash<nix::SourcePath>;
};

Expand Down
6 changes: 6 additions & 0 deletions src/libutil/mounted-source-accessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ struct MountedSourceAccessorImpl : MountedSourceAccessor
auto [accessor, subpath] = resolve(path);
return accessor->getFingerprint(subpath);
}

void invalidateCache(const CanonPath & path) override
{
auto [accessor, subpath] = resolve(path);
accessor->invalidateCache(subpath);
}
};

ref<MountedSourceAccessor> makeMountedSourceAccessor(std::map<CanonPath, ref<SourceAccessor>> mounts)
Expand Down
11 changes: 8 additions & 3 deletions src/libutil/posix-source-accessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ bool PosixSourceAccessor::pathExists(const CanonPath & path)
return nix::pathExists(makeAbsPath(path).string());
}

using Cache = boost::concurrent_flat_map<Path, std::optional<PosixStat>>;
static Cache cache;

std::optional<PosixStat> PosixSourceAccessor::cachedLstat(const CanonPath & path)
{
using Cache = boost::concurrent_flat_map<Path, std::optional<PosixStat>>;
static Cache cache;

// Note: we convert std::filesystem::path to Path because the
// former is not hashable on libc++.
Path absPath = makeAbsPath(path).string();
Expand All @@ -106,6 +106,11 @@ std::optional<PosixStat> PosixSourceAccessor::cachedLstat(const CanonPath & path
return st;
}

void PosixSourceAccessor::invalidateCache(const CanonPath & path)
{
cache.erase(makeAbsPath(path).string());
}

std::optional<SourceAccessor::Stat> PosixSourceAccessor::maybeLstat(const CanonPath & path)
{
if (auto parent = path.parent())
Expand Down
6 changes: 6 additions & 0 deletions src/libutil/union-source-accessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ struct UnionSourceAccessor : SourceAccessor
}
return {path, std::nullopt};
}

void invalidateCache(const CanonPath & path) override
{
for (auto & accessor : accessors)
accessor->invalidateCache(path);
}
};

ref<SourceAccessor> makeUnionSourceAccessor(std::vector<ref<SourceAccessor>> && accessors)
Expand Down
Loading