From 0e7f77a59a90d8cdb9560feeff4f3a48ab888843 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sat, 30 May 2020 00:59:13 +0200 Subject: [PATCH] Check revCount / lastModified input attributes if specified --- src/libfetchers/fetchers.cc | 18 ++++++++++++++---- src/libfetchers/github.cc | 1 + 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/libfetchers/fetchers.cc b/src/libfetchers/fetchers.cc index e4852d662..aac8aa8c5 100644 --- a/src/libfetchers/fetchers.cc +++ b/src/libfetchers/fetchers.cc @@ -111,13 +111,23 @@ std::pair Input::fetch(ref store) const auto narHash = store->queryPathInfo(tree.storePath)->narHash; input.attrs.insert_or_assign("narHash", narHash.to_string(SRI)); - if (auto narHash2 = getNarHash()) { - if (narHash != *narHash2) + if (auto prevNarHash = getNarHash()) { + if (narHash != *prevNarHash) throw Error("NAR hash mismatch in input '%s' (%s), expected '%s', got '%s'", - to_string(), tree.actualPath, narHash2->to_string(SRI), narHash.to_string(SRI)); + to_string(), tree.actualPath, prevNarHash->to_string(SRI), narHash.to_string(SRI)); } - // FIXME: check lastModified, revCount + if (auto prevLastModified = getLastModified()) { + if (input.getLastModified() != prevLastModified) + throw Error("'lastModified' attribute mismatch in input '%s', expected %d", + input.to_string(), *prevLastModified); + } + + if (auto prevRevCount = getRevCount()) { + if (input.getRevCount() != prevRevCount) + throw Error("'revCount' attribute mismatch in input '%s', expected %d", + input.to_string(), *prevRevCount); + } input.immutable = true; diff --git a/src/libfetchers/github.cc b/src/libfetchers/github.cc index 8d113967e..d20b5d00c 100644 --- a/src/libfetchers/github.cc +++ b/src/libfetchers/github.cc @@ -45,6 +45,7 @@ struct GitArchiveInputScheme : InputScheme throw BadURL("URL '%s' contains multiple branch/tag names", url.url); ref = value; } + // FIXME: barf on unsupported attributes } if (ref && rev)