mirror of
https://github.com/NixOS/nix
synced 2025-06-25 06:31:14 +02:00
Merge pull request #12924 from NixOS/mergify/bp/2.28-maintenance/pr-12911
create cache entry for paths already in the nix store (backport #12911)
This commit is contained in:
commit
0a66906e55
3 changed files with 30 additions and 7 deletions
|
@ -1,9 +1,23 @@
|
||||||
#include "nix/fetchers/fetch-to-store.hh"
|
#include "nix/fetchers/fetch-to-store.hh"
|
||||||
#include "nix/fetchers/fetchers.hh"
|
#include "nix/fetchers/fetchers.hh"
|
||||||
#include "nix/fetchers/cache.hh"
|
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
fetchers::Cache::Key makeFetchToStoreCacheKey(
|
||||||
|
const std::string &name,
|
||||||
|
const std::string &fingerprint,
|
||||||
|
ContentAddressMethod method,
|
||||||
|
const std::string &path)
|
||||||
|
{
|
||||||
|
return fetchers::Cache::Key{"fetchToStore", {
|
||||||
|
{"name", name},
|
||||||
|
{"fingerprint", fingerprint},
|
||||||
|
{"method", std::string{method.render()}},
|
||||||
|
{"path", path}
|
||||||
|
}};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
StorePath fetchToStore(
|
StorePath fetchToStore(
|
||||||
Store & store,
|
Store & store,
|
||||||
const SourcePath & path,
|
const SourcePath & path,
|
||||||
|
@ -19,12 +33,7 @@ StorePath fetchToStore(
|
||||||
std::optional<fetchers::Cache::Key> cacheKey;
|
std::optional<fetchers::Cache::Key> cacheKey;
|
||||||
|
|
||||||
if (!filter && path.accessor->fingerprint) {
|
if (!filter && path.accessor->fingerprint) {
|
||||||
cacheKey = fetchers::Cache::Key{"fetchToStore", {
|
cacheKey = makeFetchToStoreCacheKey(std::string{name}, *path.accessor->fingerprint, method, path.path.abs());
|
||||||
{"name", std::string{name}},
|
|
||||||
{"fingerprint", *path.accessor->fingerprint},
|
|
||||||
{"method", std::string{method.render()}},
|
|
||||||
{"path", path.path.abs()}
|
|
||||||
}};
|
|
||||||
if (auto res = fetchers::getCache()->lookupStorePath(*cacheKey, store)) {
|
if (auto res = fetchers::getCache()->lookupStorePath(*cacheKey, store)) {
|
||||||
debug("store path cache hit for '%s'", path);
|
debug("store path cache hit for '%s'", path);
|
||||||
return res->storePath;
|
return res->storePath;
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "nix/util/file-system.hh"
|
#include "nix/util/file-system.hh"
|
||||||
#include "nix/util/repair-flag.hh"
|
#include "nix/util/repair-flag.hh"
|
||||||
#include "nix/util/file-content-address.hh"
|
#include "nix/util/file-content-address.hh"
|
||||||
|
#include "nix/fetchers/cache.hh"
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
@ -22,4 +23,7 @@ StorePath fetchToStore(
|
||||||
PathFilter * filter = nullptr,
|
PathFilter * filter = nullptr,
|
||||||
RepairFlag repair = NoRepair);
|
RepairFlag repair = NoRepair);
|
||||||
|
|
||||||
|
fetchers::Cache::Key makeFetchToStoreCacheKey(
|
||||||
|
const std::string & name, const std::string & fingerprint, ContentAddressMethod method, const std::string & path);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
#include "nix/store/store-api.hh"
|
#include "nix/store/store-api.hh"
|
||||||
#include "nix/util/archive.hh"
|
#include "nix/util/archive.hh"
|
||||||
#include "nix/fetchers/store-path-accessor.hh"
|
#include "nix/fetchers/store-path-accessor.hh"
|
||||||
|
#include "nix/fetchers/cache.hh"
|
||||||
|
#include "nix/fetchers/fetch-to-store.hh"
|
||||||
|
|
||||||
namespace nix::fetchers {
|
namespace nix::fetchers {
|
||||||
|
|
||||||
|
@ -142,6 +144,14 @@ struct PathInputScheme : InputScheme
|
||||||
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.
|
||||||
|
ContentAddressMethod method = ContentAddressMethod::Raw::NixArchive;
|
||||||
|
auto fp = getFingerprint(store, input);
|
||||||
|
if (fp) {
|
||||||
|
auto cacheKey = makeFetchToStoreCacheKey(input.getName(), *fp, method, "/");
|
||||||
|
fetchers::getCache()->upsert(cacheKey, *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())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue