From 7d1f7f8d59fe1a9bbed3adc09a76de07ba84e8e8 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 17 Oct 2024 16:20:08 +0200 Subject: [PATCH] Tarball fetcher: Handle lock files that *do* contain lastModified Fixes flake-regressions/tests/DeterminateSystems/eva/0.1.0: error: 'lastModified' attribute mismatch in input 'https://api.flakehub.com/f/pinned/ipetkov/crane/0.14.1/018ac45c-ff5e-7076-b956-d478a0336516/source.tar.gz?narHash=sha256-mnE14re43v3/Jc50Jv0BKPMtEk7FEtDSligP6B5HwlI%3D', expected 1695511445 --- src/libfetchers/fetchers.cc | 4 ++-- src/libfetchers/tarball.cc | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/libfetchers/fetchers.cc b/src/libfetchers/fetchers.cc index 26229134d..9717533d6 100644 --- a/src/libfetchers/fetchers.cc +++ b/src/libfetchers/fetchers.cc @@ -220,8 +220,8 @@ void InputScheme::checkLocks(const Input & specified, const Input & final) const if (auto prevLastModified = specified.getLastModified()) { if (final.getLastModified() != prevLastModified) - throw Error("'lastModified' attribute mismatch in input '%s', expected %d", - final.to_string(), *prevLastModified); + throw Error("'lastModified' attribute mismatch in input '%s', expected %d, got %d", + final.to_string(), *prevLastModified, final.getLastModified().value_or(-1)); } if (auto prevRev = specified.getRev()) { diff --git a/src/libfetchers/tarball.cc b/src/libfetchers/tarball.cc index 27ad89b6e..e723d3061 100644 --- a/src/libfetchers/tarball.cc +++ b/src/libfetchers/tarball.cc @@ -384,11 +384,13 @@ struct TarballInputScheme : CurlInputScheme input = immutableInput; } - /* If we got a lastModified and the input is not final and - doesn't have one, then return it. Note that we don't do - this if the input is final for compatibility with old lock - files that didn't include lastModified. */ - if (result.lastModified && !_input.isFinal() && !input.attrs.contains("lastModified")) + /* If we got a lastModified, then return it. But for + compatibility with old lock files that didn't include + lastModified, don't do this if the original input was final + and didn't contain a lastModified. */ + if (result.lastModified + && !input.attrs.contains("lastModified") + && (!_input.isFinal() || _input.attrs.contains("lastModified"))) input.attrs.insert_or_assign("lastModified", uint64_t(result.lastModified)); input.attrs.insert_or_assign("narHash",