mirror of
https://github.com/NixOS/nix.git
synced 2025-11-16 07:22:43 +01:00
Merge pull request #14050 from NixOS/fix-fetch-to-store-caching
Fix fetchToStore caching
This commit is contained in:
commit
1e709554d5
21 changed files with 188 additions and 92 deletions
|
|
@ -121,7 +121,7 @@ struct SourceAccessor : std::enable_shared_from_this<SourceAccessor>
|
|||
std::string typeString();
|
||||
};
|
||||
|
||||
Stat lstat(const CanonPath & path);
|
||||
virtual Stat lstat(const CanonPath & path);
|
||||
|
||||
virtual std::optional<Stat> maybeLstat(const CanonPath & path) = 0;
|
||||
|
||||
|
|
@ -180,6 +180,27 @@ struct SourceAccessor : std::enable_shared_from_this<SourceAccessor>
|
|||
*/
|
||||
std::optional<std::string> fingerprint;
|
||||
|
||||
/**
|
||||
* Return the fingerprint for `path`. This is usually the
|
||||
* fingerprint of the current accessor, but for composite
|
||||
* accessors (like `MountedSourceAccessor`), we want to return the
|
||||
* fingerprint of the "inner" accessor if the current one lacks a
|
||||
* fingerprint.
|
||||
*
|
||||
* So this method is intended to return the most-outer accessor
|
||||
* that has a fingerprint for `path`. It also returns the path that `path`
|
||||
* corresponds to in that accessor.
|
||||
*
|
||||
* For example: in a `MountedSourceAccessor` that has
|
||||
* `/nix/store/foo` mounted,
|
||||
* `getFingerprint("/nix/store/foo/bar")` will return the path
|
||||
* `/bar` and the fingerprint of the `/nix/store/foo` accessor.
|
||||
*/
|
||||
virtual std::pair<CanonPath, std::optional<std::string>> getFingerprint(const CanonPath & path)
|
||||
{
|
||||
return {path, fingerprint};
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the maximum last-modified time of the files in this
|
||||
* tree, if available.
|
||||
|
|
|
|||
|
|
@ -27,6 +27,12 @@ struct MountedSourceAccessorImpl : MountedSourceAccessor
|
|||
return accessor->readFile(subpath);
|
||||
}
|
||||
|
||||
Stat lstat(const CanonPath & path) override
|
||||
{
|
||||
auto [accessor, subpath] = resolve(path);
|
||||
return accessor->lstat(subpath);
|
||||
}
|
||||
|
||||
std::optional<Stat> maybeLstat(const CanonPath & path) override
|
||||
{
|
||||
auto [accessor, subpath] = resolve(path);
|
||||
|
|
@ -85,6 +91,14 @@ struct MountedSourceAccessorImpl : MountedSourceAccessor
|
|||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::pair<CanonPath, std::optional<std::string>> getFingerprint(const CanonPath & path) override
|
||||
{
|
||||
if (fingerprint)
|
||||
return {path, fingerprint};
|
||||
auto [accessor, subpath] = resolve(path);
|
||||
return accessor->getFingerprint(subpath);
|
||||
}
|
||||
};
|
||||
|
||||
ref<MountedSourceAccessor> makeMountedSourceAccessor(std::map<CanonPath, ref<SourceAccessor>> mounts)
|
||||
|
|
|
|||
|
|
@ -72,6 +72,18 @@ struct UnionSourceAccessor : SourceAccessor
|
|||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::pair<CanonPath, std::optional<std::string>> getFingerprint(const CanonPath & path) override
|
||||
{
|
||||
if (fingerprint)
|
||||
return {path, fingerprint};
|
||||
for (auto & accessor : accessors) {
|
||||
auto [subpath, fingerprint] = accessor->getFingerprint(path);
|
||||
if (fingerprint)
|
||||
return {subpath, fingerprint};
|
||||
}
|
||||
return {path, std::nullopt};
|
||||
}
|
||||
};
|
||||
|
||||
ref<SourceAccessor> makeUnionSourceAccessor(std::vector<ref<SourceAccessor>> && accessors)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue