Skip to content

Commit

Permalink
downloadTarball should not redownload the source file if not needed
Browse files Browse the repository at this point in the history
If 1) the store path for the unpacked source is valid, and 2) the file
at the source has not changed, downloadTarball shouldn't redownload the
source file.
  • Loading branch information
yshui committed Feb 11, 2024
1 parent f19ee2f commit 0a6ce08
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/libfetchers/tarball.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ DownloadTarballResult downloadTarball(
.immutableUrl = maybeGetStrAttr(cached->infoAttrs, "immutableUrl"),
};

auto res = downloadFile(store, url, name, locked, headers);
assert(res.storePathValid);
auto res = downloadFile(store, url, name, locked, headers, cached.has_value());

std::optional<StorePath> unpackedStorePath;
time_t lastModified;
Expand All @@ -158,6 +157,11 @@ DownloadTarballResult downloadTarball(
} else {
Path tmpDir = createTempDir();
AutoDelete autoDelete(tmpDir, true);
if (!res.storePathValid) {
debug("source etag didn't match unpacked etag, or server returned 304 with a different etag.");
res = downloadFile(store, url, name, locked);
assert(res.storePathValid);
}
unpackTarfile(store->toRealPath(res.storePath), tmpDir);
auto members = readDirectory(tmpDir);
if (members.size() != 1)
Expand Down

0 comments on commit 0a6ce08

Please sign in to comment.