Skip to content

Commit

Permalink
Fix misread of source if path is already valid
Browse files Browse the repository at this point in the history
When receiving a stream of NARs through the ssh-ng protocol, an already
existing path would cause the NAR archive to not be read in the stream,
resulting in trying to parse the NAR as a ValidPathInfo. This results in
the error message:
    error: not an absolute path: 'nix-archive-1'

Fixes NixOS#6253

Usually this problem is avoided by running QueryValidPaths before
AddMultipleToStore, but can arise when two parallel nix processes gets
the same response from QueryValidPaths. This makes the problem more
prominent when running builds in parallel.
  • Loading branch information
simonrainerson authored and Théophane Hufschmitt committed Aug 7, 2023
1 parent 9113b42 commit 31a6e10
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/libstore/local-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1196,6 +1196,15 @@ void LocalStore::addToStore(const ValidPathInfo & info, Source & source,
if (checkSigs && pathInfoIsUntrusted(info))
throw Error("cannot add path '%s' because it lacks a signature by a trusted key", printStorePath(info.path));

/* In case we are not interested in reading the NAR: discard it. */
bool narRead = false;
Finally cleanup = [&]() {
if (!narRead) {
ParseSink sink;
parseDump(sink, source);
}
};

addTempRoot(info.path);

if (repair || !isValidPath(info.path)) {
Expand All @@ -1220,6 +1229,7 @@ void LocalStore::addToStore(const ValidPathInfo & info, Source & source,

TeeSource wrapperSource { source, hashSink };

narRead = true;
restorePath(realPath, wrapperSource);

auto hashResult = hashSink.finish();
Expand Down

0 comments on commit 31a6e10

Please sign in to comment.