1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-12-01 14:41:00 +01:00

fetchToStore(): Fix caching

This was broken because MountedSourceAccessor did not return a
fingerprint. Previously fingerprints were global to an accessor, but
with a MountedSourceAccessor the fingerprint can be different for each
mount point.
This commit is contained in:
Eelco Dolstra 2025-06-06 22:02:45 +02:00
parent f8ef941c04
commit 86785fd9d1
8 changed files with 72 additions and 9 deletions

View file

@ -52,6 +52,16 @@ 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));
}
};
}

View file

@ -177,10 +177,27 @@ struct SourceAccessor : std::enable_shared_from_this<SourceAccessor>
SymlinkResolution mode = SymlinkResolution::Full);
/**
* A string that uniquely represents the contents of this
* accessor. This is used for caching lookups (see `fetchToStore()`).
* 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`.
*/
std::optional<std::string> fingerprint;
virtual std::optional<std::string> getFingerprint(const CanonPath & path)
{
return _fingerprint;
}
virtual void setFingerprint(std::string fingerprint)
{
_fingerprint = std::move(fingerprint);
}
std::optional<std::string> _fingerprint;
/**
* Return the maximum last-modified time of the files in this

View file

@ -90,6 +90,15 @@ struct MountedSourceAccessorImpl : MountedSourceAccessor
else
return nullptr;
}
std::optional<std::string> getFingerprint(const CanonPath & path) override
{
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);
}
};
ref<MountedSourceAccessor> makeMountedSourceAccessor(std::map<CanonPath, ref<SourceAccessor>> mounts)