aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/download.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstore/download.cc')
-rw-r--r--src/libstore/download.cc19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/libstore/download.cc b/src/libstore/download.cc
index 149c84765..8e0d7d42a 100644
--- a/src/libstore/download.cc
+++ b/src/libstore/download.cc
@@ -819,6 +819,7 @@ CachedDownloadResult Downloader::downloadCached(
CachedDownloadResult result;
result.storePath = store->printStorePath(*expectedStorePath);
result.path = store->toRealPath(result.storePath);
+ assert(!request.getLastModified); // FIXME
return result;
}
}
@@ -900,35 +901,43 @@ CachedDownloadResult Downloader::downloadCached(
std::optional<StorePath> unpackedStorePath;
if (pathExists(unpackedLink)) {
unpackedStorePath = store->parseStorePath(readLink(unpackedLink));
- // FIXME
store->addTempRoot(*unpackedStorePath);
if (!store->isValidPath(*unpackedStorePath))
unpackedStorePath.reset();
+ else
+ result.lastModified = lstat(unpackedLink).st_mtime;
}
if (!unpackedStorePath) {
printInfo("unpacking '%s'...", url);
Path tmpDir = createTempDir();
AutoDelete autoDelete(tmpDir, true);
- unpackTarfile(store->toRealPath(store->printStorePath(*storePath)), tmpDir);
+ unpackTarfile(store->toRealPath(*storePath), tmpDir);
auto members = readDirectory(tmpDir);
if (members.size() != 1)
throw nix::Error("tarball '%s' contains an unexpected number of top-level files", url);
auto topDir = tmpDir + "/" + members.begin()->name;
+ result.lastModified = lstat(topDir).st_mtime;
unpackedStorePath = store->addToStore(name, topDir, true, htSHA256, defaultPathFilter, NoRepair);
}
- replaceSymlink(store->printStorePath(*unpackedStorePath), unpackedLink);
+ // Store the last-modified date of the tarball in the symlink
+ // mtime. This saves us from having to store it somewhere
+ // else.
+ replaceSymlink(store->printStorePath(*unpackedStorePath), unpackedLink, result.lastModified);
storePath = std::move(*unpackedStorePath);
}
if (expectedStorePath && *storePath != *expectedStorePath) {
unsigned int statusCode = 102;
Hash gotHash = request.unpack
- ? hashPath(request.expectedHash.type, store->toRealPath(store->printStorePath(*storePath))).first
- : hashFile(request.expectedHash.type, store->toRealPath(store->printStorePath(*storePath)));
+ ? hashPath(request.expectedHash.type, store->toRealPath(*storePath)).first
+ : hashFile(request.expectedHash.type, store->toRealPath(*storePath));
throw nix::Error(statusCode, "hash mismatch in file downloaded from '%s':\n wanted: %s\n got: %s",
url, request.expectedHash.to_string(), gotHash.to_string());
}
+ if (request.gcRoot)
+ store->addIndirectRoot(fileLink);
+
result.storePath = store->printStorePath(*storePath);
result.path = store->toRealPath(result.storePath);
return result;