mirror of
https://github.com/NixOS/nix
synced 2025-06-29 10:31:15 +02:00
GitArchiveInputScheme: Restore the lastModified attribute
This commit is contained in:
parent
219510b6ab
commit
7b1cda9ca2
3 changed files with 36 additions and 21 deletions
|
@ -243,7 +243,7 @@ static Repository openTarballCache()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Hash importTarball(Source & source)
|
TarballInfo importTarball(Source & source)
|
||||||
{
|
{
|
||||||
auto repo = openTarballCache();
|
auto repo = openTarballCache();
|
||||||
|
|
||||||
|
@ -308,6 +308,8 @@ Hash importTarball(Source & source)
|
||||||
|
|
||||||
size_t componentsToStrip = 1;
|
size_t componentsToStrip = 1;
|
||||||
|
|
||||||
|
time_t lastModified = 0;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
// FIXME: merge with extract_archive
|
// FIXME: merge with extract_archive
|
||||||
struct archive_entry * entry;
|
struct archive_entry * entry;
|
||||||
|
@ -321,6 +323,8 @@ Hash importTarball(Source & source)
|
||||||
else
|
else
|
||||||
archive.check(r);
|
archive.check(r);
|
||||||
|
|
||||||
|
lastModified = std::max(lastModified, archive_entry_mtime(entry));
|
||||||
|
|
||||||
auto pathComponents = tokenizeString<std::vector<std::string>>(path, "/");
|
auto pathComponents = tokenizeString<std::vector<std::string>>(path, "/");
|
||||||
|
|
||||||
std::span<const std::string> pathComponents2{pathComponents};
|
std::span<const std::string> pathComponents2{pathComponents};
|
||||||
|
@ -388,7 +392,10 @@ Hash importTarball(Source & source)
|
||||||
|
|
||||||
auto [oid, _name] = popBuilder();
|
auto [oid, _name] = popBuilder();
|
||||||
|
|
||||||
return Hash::parseAny(git_oid_tostr_s(&oid), htSHA1);
|
return TarballInfo {
|
||||||
|
.treeHash = Hash::parseAny(git_oid_tostr_s(&oid), htSHA1),
|
||||||
|
.lastModified = lastModified
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
ref<InputAccessor> makeTarballCacheAccessor(const Hash & rev)
|
ref<InputAccessor> makeTarballCacheAccessor(const Hash & rev)
|
||||||
|
|
|
@ -6,7 +6,13 @@ namespace nix {
|
||||||
|
|
||||||
ref<InputAccessor> makeGitInputAccessor(const CanonPath & path, const Hash & rev);
|
ref<InputAccessor> makeGitInputAccessor(const CanonPath & path, const Hash & rev);
|
||||||
|
|
||||||
Hash importTarball(Source & source);
|
struct TarballInfo
|
||||||
|
{
|
||||||
|
Hash treeHash;
|
||||||
|
time_t lastModified;
|
||||||
|
};
|
||||||
|
|
||||||
|
TarballInfo importTarball(Source & source);
|
||||||
|
|
||||||
ref<InputAccessor> makeTarballCacheAccessor(const Hash & rev);
|
ref<InputAccessor> makeTarballCacheAccessor(const Hash & rev);
|
||||||
|
|
||||||
|
|
|
@ -168,6 +168,8 @@ struct GitArchiveInputScheme : InputScheme
|
||||||
|
|
||||||
void checkLocks(const Input & specified, const Input & final) const override
|
void checkLocks(const Input & specified, const Input & final) const override
|
||||||
{
|
{
|
||||||
|
InputScheme::checkLocks(specified, final);
|
||||||
|
|
||||||
if (auto prevTreeHash = getTreeHash(specified)) {
|
if (auto prevTreeHash = getTreeHash(specified)) {
|
||||||
if (getTreeHash(final) != prevTreeHash)
|
if (getTreeHash(final) != prevTreeHash)
|
||||||
throw Error("Git tree hash mismatch in input '%s', expected '%s'",
|
throw Error("Git tree hash mismatch in input '%s', expected '%s'",
|
||||||
|
@ -201,7 +203,7 @@ struct GitArchiveInputScheme : InputScheme
|
||||||
|
|
||||||
virtual DownloadUrl getDownloadUrl(const Input & input) const = 0;
|
virtual DownloadUrl getDownloadUrl(const Input & input) const = 0;
|
||||||
|
|
||||||
std::pair<Input, Hash> downloadArchive(ref<Store> store, Input input) const
|
std::pair<Input, TarballInfo> downloadArchive(ref<Store> store, Input input) const
|
||||||
{
|
{
|
||||||
if (!maybeGetStrAttr(input.attrs, "ref")) input.attrs.insert_or_assign("ref", "HEAD");
|
if (!maybeGetStrAttr(input.attrs, "ref")) input.attrs.insert_or_assign("ref", "HEAD");
|
||||||
|
|
||||||
|
@ -214,14 +216,18 @@ struct GitArchiveInputScheme : InputScheme
|
||||||
auto cache = getCache();
|
auto cache = getCache();
|
||||||
|
|
||||||
auto treeHashKey = fmt("git-rev-to-tree-hash-%s", rev->gitRev());
|
auto treeHashKey = fmt("git-rev-to-tree-hash-%s", rev->gitRev());
|
||||||
|
auto lastModifiedKey = fmt("git-rev-to-last-modified-%s", rev->gitRev());
|
||||||
|
|
||||||
if (auto treeHashS = cache->queryFact(treeHashKey)) {
|
if (auto treeHashS = cache->queryFact(treeHashKey)) {
|
||||||
|
if (auto lastModifiedS = cache->queryFact(lastModifiedKey)) {
|
||||||
auto treeHash = Hash::parseAny(*treeHashS, htSHA1);
|
auto treeHash = Hash::parseAny(*treeHashS, htSHA1);
|
||||||
|
auto lastModified = string2Int<time_t>(*lastModifiedS).value();
|
||||||
if (tarballCacheContains(treeHash))
|
if (tarballCacheContains(treeHash))
|
||||||
return {std::move(input), treeHash};
|
return {std::move(input), TarballInfo { .treeHash = treeHash, .lastModified = lastModified }};
|
||||||
else
|
else
|
||||||
debug("Git tree with hash '%s' has disappeared from the cache, refetching...", treeHash.gitRev());
|
debug("Git tree with hash '%s' has disappeared from the cache, refetching...", treeHash.gitRev());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Stream the tarball into the tarball cache. */
|
/* Stream the tarball into the tarball cache. */
|
||||||
auto url = getDownloadUrl(input);
|
auto url = getDownloadUrl(input);
|
||||||
|
@ -232,26 +238,22 @@ struct GitArchiveInputScheme : InputScheme
|
||||||
getFileTransfer()->download(std::move(req), sink);
|
getFileTransfer()->download(std::move(req), sink);
|
||||||
});
|
});
|
||||||
|
|
||||||
auto treeHash = importTarball(*source);
|
auto tarballInfo = importTarball(*source);
|
||||||
|
|
||||||
cache->upsertFact(treeHashKey, treeHash.gitRev());
|
cache->upsertFact(treeHashKey, tarballInfo.treeHash.gitRev());
|
||||||
|
cache->upsertFact(lastModifiedKey, std::to_string(tarballInfo.lastModified));
|
||||||
|
|
||||||
return {std::move(input), treeHash};
|
return {std::move(input), tarballInfo};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<ref<InputAccessor>, Input> getAccessor(ref<Store> store, const Input & _input) const override
|
std::pair<ref<InputAccessor>, Input> getAccessor(ref<Store> store, const Input & _input) const override
|
||||||
{
|
{
|
||||||
auto [input, treeHash] = downloadArchive(store, _input);
|
auto [input, tarballInfo] = downloadArchive(store, _input);
|
||||||
|
|
||||||
input.attrs.insert_or_assign("treeHash", treeHash.gitRev());
|
input.attrs.insert_or_assign("treeHash", tarballInfo.treeHash.gitRev());
|
||||||
|
input.attrs.insert_or_assign("lastModified", uint64_t(tarballInfo.lastModified));
|
||||||
|
|
||||||
auto accessor = makeTarballCacheAccessor(treeHash);
|
auto accessor = makeTarballCacheAccessor(tarballInfo.treeHash);
|
||||||
|
|
||||||
#if 0
|
|
||||||
auto lastModified = accessor->getLastModified();
|
|
||||||
assert(lastModified);
|
|
||||||
input.attrs.insert_or_assign("lastModified", uint64_t(*lastModified));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
accessor->setPathDisplay("«" + input.to_string() + "»");
|
accessor->setPathDisplay("«" + input.to_string() + "»");
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue