mirror of
https://github.com/NixOS/nix.git
synced 2025-11-11 04:56:01 +01:00
Fix path field in fetcher cache
86785fd9d1 was broken because it was
storing the full path in the MountedSourceAccessor as the `path` field
in the fetcher cache key (i.e. including the
/nix/store/... prefix). Especially in the case of lazy (virtual) store
paths, this didn't work at all because those paths are different every time.
This commit is contained in:
parent
cbedb8e19a
commit
8b9cb382e9
7 changed files with 38 additions and 49 deletions
|
|
@ -31,10 +31,14 @@ StorePath fetchToStore(
|
|||
// a `PosixSourceAccessor` pointing to a store path.
|
||||
|
||||
std::optional<fetchers::Cache::Key> cacheKey;
|
||||
std::optional<std::string> fingerprint;
|
||||
|
||||
if (!filter && (fingerprint = path.accessor->getFingerprint(path.path))) {
|
||||
cacheKey = makeFetchToStoreCacheKey(std::string{name}, *fingerprint, method, path.path.abs());
|
||||
auto [subpath, fingerprint] =
|
||||
filter
|
||||
? std::pair<CanonPath, std::optional<std::string>>{path.path, std::nullopt}
|
||||
: path.accessor->getFingerprint(path.path);
|
||||
|
||||
if (fingerprint) {
|
||||
cacheKey = makeFetchToStoreCacheKey(std::string{name}, *fingerprint, method, subpath.abs());
|
||||
if (auto res = fetchers::getCache()->lookupStorePath(*cacheKey, store, mode == FetchMode::DryRun)) {
|
||||
debug("store path cache hit for '%s'", path);
|
||||
return res->storePath;
|
||||
|
|
|
|||
|
|
@ -338,8 +338,7 @@ std::pair<ref<SourceAccessor>, Input> Input::getAccessorUnchecked(ref<Store> sto
|
|||
|
||||
auto accessor = make_ref<SubstitutedSourceAccessor>(makeStorePathAccessor(store, storePath));
|
||||
|
||||
if (auto fingerprint = getFingerprint(store))
|
||||
accessor->setFingerprint(*fingerprint);
|
||||
accessor->fingerprint = getFingerprint(store);
|
||||
|
||||
// FIXME: ideally we would use the `showPath()` of the
|
||||
// "real" accessor for this fetcher type.
|
||||
|
|
@ -353,10 +352,8 @@ std::pair<ref<SourceAccessor>, Input> Input::getAccessorUnchecked(ref<Store> sto
|
|||
|
||||
auto [accessor, result] = scheme->getAccessor(store, *this);
|
||||
|
||||
assert(!accessor->getFingerprint(CanonPath::root));
|
||||
|
||||
if (auto fingerprint = result.getFingerprint(store))
|
||||
accessor->setFingerprint(*fingerprint);
|
||||
assert(!accessor->fingerprint);
|
||||
accessor->fingerprint = result.getFingerprint(store);
|
||||
|
||||
return {accessor, std::move(result)};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,16 +58,13 @@ std::string FilteringSourceAccessor::showPath(const CanonPath & path)
|
|||
return displayPrefix + next->showPath(prefix / path) + displaySuffix;
|
||||
}
|
||||
|
||||
std::optional<std::string> FilteringSourceAccessor::getFingerprint(const CanonPath & path)
|
||||
std::pair<CanonPath, std::optional<std::string>> FilteringSourceAccessor::getFingerprint(const CanonPath & path)
|
||||
{
|
||||
if (fingerprint)
|
||||
return {path, fingerprint};
|
||||
return next->getFingerprint(prefix / path);
|
||||
}
|
||||
|
||||
void FilteringSourceAccessor::setFingerprint(std::string fingerprint)
|
||||
{
|
||||
next->setFingerprint(std::move(fingerprint));
|
||||
}
|
||||
|
||||
void FilteringSourceAccessor::checkAccess(const CanonPath & path)
|
||||
{
|
||||
if (!isAllowed(path))
|
||||
|
|
|
|||
|
|
@ -50,9 +50,7 @@ struct FilteringSourceAccessor : SourceAccessor
|
|||
|
||||
std::string showPath(const CanonPath & path) override;
|
||||
|
||||
std::optional<std::string> getFingerprint(const CanonPath & path) override;
|
||||
|
||||
void setFingerprint(std::string fingerprint) override;
|
||||
std::pair<CanonPath, std::optional<std::string>> getFingerprint(const CanonPath & path) override;
|
||||
|
||||
/**
|
||||
* Call `makeNotAllowedError` to throw a `RestrictedPathError`
|
||||
|
|
|
|||
|
|
@ -52,16 +52,6 @@ struct ForwardingSourceAccessor : SourceAccessor
|
|||
{
|
||||
return next->getPhysicalPath(path);
|
||||
}
|
||||
|
||||
std::optional<std::string> getFingerprint(const CanonPath & path) override
|
||||
{
|
||||
return next->getFingerprint(path);
|
||||
}
|
||||
|
||||
void setFingerprint(std::string fingerprint) override
|
||||
{
|
||||
next->setFingerprint(std::move(fingerprint));
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -177,28 +177,32 @@ struct SourceAccessor : std::enable_shared_from_this<SourceAccessor>
|
|||
SymlinkResolution mode = SymlinkResolution::Full);
|
||||
|
||||
/**
|
||||
* Return a string that uniquely represents the contents of this
|
||||
* accessor. This is used for caching lookups (see
|
||||
* `fetchToStore()`).
|
||||
*
|
||||
* Fingerprints are generally for the entire accessor, but this
|
||||
* method takes a `path` argument to support accessors like
|
||||
* `MountedSourceAccessor` that combine multiple underlying
|
||||
* accessors. A fingerprint should only be returned if it uniquely
|
||||
* represents everything under `path`.
|
||||
* A string that uniquely represents the contents of this
|
||||
* accessor. This is used for caching lookups (see `fetchToStore()`).
|
||||
*/
|
||||
virtual std::optional<std::string> getFingerprint(const CanonPath & path)
|
||||
{
|
||||
return _fingerprint;
|
||||
}
|
||||
std::optional<std::string> fingerprint;
|
||||
|
||||
virtual void setFingerprint(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)
|
||||
{
|
||||
_fingerprint = std::move(fingerprint);
|
||||
return {path, fingerprint};
|
||||
}
|
||||
|
||||
std::optional<std::string> _fingerprint;
|
||||
|
||||
/**
|
||||
* Return the maximum last-modified time of the files in this
|
||||
* tree, if available.
|
||||
|
|
|
|||
|
|
@ -91,12 +91,11 @@ struct MountedSourceAccessorImpl : MountedSourceAccessor
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
std::optional<std::string> getFingerprint(const CanonPath & path) override
|
||||
std::pair<CanonPath, std::optional<std::string>> getFingerprint(const CanonPath & path) override
|
||||
{
|
||||
if (fingerprint)
|
||||
return {path, fingerprint};
|
||||
auto [accessor, subpath] = resolve(path);
|
||||
// FIXME: check that there are no mounts underneath the mount
|
||||
// point of `accessor`, since that would invalidate the
|
||||
// fingerprint. (However we don't have such at the moment.)
|
||||
return accessor->getFingerprint(subpath);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue