Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions src/libfetchers/fetchers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -276,24 +276,10 @@ void Input::checkLocks(Input specified, Input & result)
}
}

if (auto prevLastModified = specified.getLastModified()) {
if (result.getLastModified() != prevLastModified)
throw Error(
"'lastModified' attribute mismatch in input '%s', expected %d, got %d",
result.to_string(),
*prevLastModified,
result.getLastModified().value_or(-1));
}

if (auto prevRev = specified.getRev()) {
if (result.getRev() != prevRev)
throw Error("'rev' attribute mismatch in input '%s', expected %s", result.to_string(), prevRev->gitRev());
}

if (auto prevRevCount = specified.getRevCount()) {
if (result.getRevCount() != prevRevCount)
throw Error("'revCount' attribute mismatch in input '%s', expected %d", result.to_string(), *prevRevCount);
}
}

std::pair<ref<SourceAccessor>, Input> Input::getAccessor(const Settings & settings, ref<Store> store) const
Expand Down
21 changes: 11 additions & 10 deletions src/libfetchers/git.cc
Original file line number Diff line number Diff line change
Expand Up @@ -738,13 +738,17 @@ struct GitInputScheme : InputScheme

auto rev = *input.getRev();

Attrs infoAttrs({
{"rev", rev.gitRev()},
{"lastModified", getLastModified(settings, repoInfo, repoDir, rev)},
});

if (!getShallowAttr(input))
infoAttrs.insert_or_assign("revCount", getRevCount(settings, repoInfo, repoDir, rev));
/* Skip lastModified computation if it's already supplied by the caller.
We don't care if they specify an incorrect value; it doesn't
matter for security, unlike narHash. */
if (!input.attrs.contains("lastModified"))
input.attrs.insert_or_assign("lastModified", getLastModified(settings, repoInfo, repoDir, rev));

if (!getShallowAttr(input)) {
/* Like lastModified, skip revCount if supplied by the caller. */
if (!input.attrs.contains("revCount"))
input.attrs.insert_or_assign("revCount", getRevCount(settings, repoInfo, repoDir, rev));
}

printTalkative("using revision %s of repo '%s'", rev.gitRev(), repoInfo.locationToArg());

Expand Down Expand Up @@ -800,9 +804,6 @@ struct GitInputScheme : InputScheme
}

assert(!origRev || origRev == rev);
if (!getShallowAttr(input))
input.attrs.insert_or_assign("revCount", getIntAttr(infoAttrs, "revCount"));
input.attrs.insert_or_assign("lastModified", getIntAttr(infoAttrs, "lastModified"));

return {accessor, std::move(input)};
}
Expand Down
1 change: 0 additions & 1 deletion tests/nixos/tarball-flakes.nix
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ in

# Check that fetching fails if we provide incorrect attributes.
machine.fail("nix flake metadata --json http://localhost/tags/latest.tar.gz?rev=493300eb13ae6fb387fbd47bf54a85915acc31c0")
machine.fail("nix flake metadata --json http://localhost/tags/latest.tar.gz?revCount=789")
machine.fail("nix flake metadata --json http://localhost/tags/latest.tar.gz?narHash=sha256-tbudgBSg+bHWHiHnlteNzN8TUvI80ygS9IULh4rklEw=")
'';

Expand Down