mirror of
https://github.com/NixOS/nix.git
synced 2025-12-18 15:01:08 +01:00
Path fetcher: Simplify fingerprint computation
This commit is contained in:
parent
3450a72ba0
commit
ec6d5c7de3
1 changed files with 15 additions and 27 deletions
|
|
@ -123,8 +123,6 @@ struct PathInputScheme : InputScheme
|
||||||
|
|
||||||
auto absPath = getAbsPath(input);
|
auto absPath = getAbsPath(input);
|
||||||
|
|
||||||
Activity act(*logger, lvlTalkative, actUnknown, fmt("copying %s to the store", absPath));
|
|
||||||
|
|
||||||
// FIXME: check whether access to 'path' is allowed.
|
// FIXME: check whether access to 'path' is allowed.
|
||||||
auto storePath = store->maybeParseStorePath(absPath.string());
|
auto storePath = store->maybeParseStorePath(absPath.string());
|
||||||
|
|
||||||
|
|
@ -133,43 +131,33 @@ struct PathInputScheme : InputScheme
|
||||||
|
|
||||||
time_t mtime = 0;
|
time_t mtime = 0;
|
||||||
if (!storePath || storePath->name() != "source" || !store->isValidPath(*storePath)) {
|
if (!storePath || storePath->name() != "source" || !store->isValidPath(*storePath)) {
|
||||||
|
Activity act(*logger, lvlTalkative, actUnknown, fmt("copying %s to the store", absPath));
|
||||||
// FIXME: try to substitute storePath.
|
// FIXME: try to substitute storePath.
|
||||||
auto src = sinkToSource(
|
auto src = sinkToSource(
|
||||||
[&](Sink & sink) { mtime = dumpPathAndGetMtime(absPath.string(), sink, defaultPathFilter); });
|
[&](Sink & sink) { mtime = dumpPathAndGetMtime(absPath.string(), sink, defaultPathFilter); });
|
||||||
storePath = store->addToStoreFromDump(*src, "source");
|
storePath = store->addToStoreFromDump(*src, "source");
|
||||||
}
|
}
|
||||||
|
|
||||||
// To avoid copying the path again to the /nix/store, we need to add a cache entry.
|
auto accessor = ref{store->getFSAccessor(*storePath)};
|
||||||
ContentAddressMethod method = ContentAddressMethod::Raw::NixArchive;
|
|
||||||
auto fp = getFingerprint(store, input);
|
// To prevent `fetchToStore()` copying the path again to Nix
|
||||||
if (fp) {
|
// store, pre-create an entry in the fetcher cache.
|
||||||
auto cacheKey = makeFetchToStoreCacheKey(input.getName(), *fp, method, "/");
|
auto info = store->queryPathInfo(*storePath);
|
||||||
input.settings->getCache()->upsert(cacheKey, *store, {}, *storePath);
|
accessor->fingerprint =
|
||||||
}
|
fmt("path:%s", store->queryPathInfo(*storePath)->narHash.to_string(HashFormat::SRI, true));
|
||||||
|
input.settings->getCache()->upsert(
|
||||||
|
makeFetchToStoreCacheKey(
|
||||||
|
input.getName(), *accessor->fingerprint, ContentAddressMethod::Raw::NixArchive, "/"),
|
||||||
|
*store,
|
||||||
|
{},
|
||||||
|
*storePath);
|
||||||
|
|
||||||
/* Trust the lastModified value supplied by the user, if
|
/* Trust the lastModified value supplied by the user, if
|
||||||
any. It's not a "secure" attribute so we don't care. */
|
any. It's not a "secure" attribute so we don't care. */
|
||||||
if (!input.getLastModified())
|
if (!input.getLastModified())
|
||||||
input.attrs.insert_or_assign("lastModified", uint64_t(mtime));
|
input.attrs.insert_or_assign("lastModified", uint64_t(mtime));
|
||||||
|
|
||||||
return {ref{store->getFSAccessor(*storePath)}, std::move(input)};
|
return {accessor, std::move(input)};
|
||||||
}
|
|
||||||
|
|
||||||
std::optional<std::string> getFingerprint(ref<Store> store, const Input & input) const override
|
|
||||||
{
|
|
||||||
if (isRelative(input))
|
|
||||||
return std::nullopt;
|
|
||||||
|
|
||||||
/* If this path is in the Nix store, use the hash of the
|
|
||||||
store object and the subpath. */
|
|
||||||
auto path = getAbsPath(input);
|
|
||||||
try {
|
|
||||||
auto [storePath, subPath] = store->toStorePath(path.string());
|
|
||||||
auto info = store->queryPathInfo(storePath);
|
|
||||||
return fmt("path:%s:%s", info->narHash.to_string(HashFormat::Base16, false), subPath);
|
|
||||||
} catch (Error &) {
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<ExperimentalFeature> experimentalFeature() const override
|
std::optional<ExperimentalFeature> experimentalFeature() const override
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue