@@ -123,8 +123,6 @@ struct PathInputScheme : InputScheme
123123
124124 auto absPath = getAbsPath (input);
125125
126- Activity act (*logger, lvlTalkative, actUnknown, fmt (" copying %s to the store" , absPath));
127-
128126 // FIXME: check whether access to 'path' is allowed.
129127 auto storePath = store->maybeParseStorePath (absPath.string ());
130128
@@ -133,43 +131,33 @@ struct PathInputScheme : InputScheme
133131
134132 time_t mtime = 0 ;
135133 if (!storePath || storePath->name () != " source" || !store->isValidPath (*storePath)) {
134+ Activity act (*logger, lvlTalkative, actUnknown, fmt (" copying %s to the store" , absPath));
136135 // FIXME: try to substitute storePath.
137136 auto src = sinkToSource (
138137 [&](Sink & sink) { mtime = dumpPathAndGetMtime (absPath.string (), sink, defaultPathFilter); });
139138 storePath = store->addToStoreFromDump (*src, " source" );
140139 }
141140
142- // To avoid copying the path again to the /nix/store, we need to add a cache entry.
143- ContentAddressMethod method = ContentAddressMethod::Raw::NixArchive;
144- auto fp = getFingerprint (store, input);
145- if (fp) {
146- auto cacheKey = makeFetchToStoreCacheKey (input.getName (), *fp, method, " /" );
147- input.settings ->getCache ()->upsert (cacheKey, *store, {}, *storePath);
148- }
141+ auto accessor = ref{store->getFSAccessor (*storePath)};
142+
143+ // To prevent `fetchToStore()` copying the path again to Nix
144+ // store, pre-create an entry in the fetcher cache.
145+ auto info = store->queryPathInfo (*storePath);
146+ accessor->fingerprint =
147+ fmt (" path:%s" , store->queryPathInfo (*storePath)->narHash .to_string (HashFormat::SRI, true ));
148+ input.settings ->getCache ()->upsert (
149+ makeFetchToStoreCacheKey (
150+ input.getName (), *accessor->fingerprint , ContentAddressMethod::Raw::NixArchive, " /" ),
151+ *store,
152+ {},
153+ *storePath);
149154
150155 /* Trust the lastModified value supplied by the user, if
151156 any. It's not a "secure" attribute so we don't care. */
152157 if (!input.getLastModified ())
153158 input.attrs .insert_or_assign (" lastModified" , uint64_t (mtime));
154159
155- return {ref{store->getFSAccessor (*storePath)}, std::move (input)};
156- }
157-
158- std::optional<std::string> getFingerprint (ref<Store> store, const Input & input) const override
159- {
160- if (isRelative (input))
161- return std::nullopt ;
162-
163- /* If this path is in the Nix store, use the hash of the
164- store object and the subpath. */
165- auto path = getAbsPath (input);
166- try {
167- auto [storePath, subPath] = store->toStorePath (path.string ());
168- auto info = store->queryPathInfo (storePath);
169- return fmt (" path:%s:%s" , info->narHash .to_string (HashFormat::Base16, false ), subPath);
170- } catch (Error &) {
171- return std::nullopt ;
172- }
160+ return {accessor, std::move (input)};
173161 }
174162
175163 std::optional<ExperimentalFeature> experimentalFeature () const override
0 commit comments