1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-21 09:49:36 +01:00

Refactor downloadCached() interface

(cherry picked from commit df3f5a78d5)
This commit is contained in:
Eelco Dolstra 2019-05-22 23:36:29 +02:00
parent 7b9c68766d
commit f8b30338ac
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
6 changed files with 63 additions and 49 deletions

View file

@ -57,11 +57,23 @@ struct DownloadResult
{
bool cached = false;
std::string etag;
std::string effectiveUrl;
std::string effectiveUri;
std::shared_ptr<std::string> data;
uint64_t bodySize = 0;
};
struct CachedDownloadRequest
{
std::string uri;
bool unpack = false;
std::string name;
Hash expectedHash;
unsigned int ttl = settings.tarballTtl;
CachedDownloadRequest(const std::string & uri)
: uri(uri) { }
};
struct CachedDownloadResult
{
// Note: 'storePath' may be different from 'path' when using a
@ -69,6 +81,7 @@ struct CachedDownloadResult
Path storePath;
Path path;
std::optional<std::string> etag;
std::string effectiveUri;
};
class Store;
@ -96,10 +109,7 @@ struct Downloader
and is more recent than tarball-ttl seconds. Otherwise,
use the recorded ETag to verify if the server has a more
recent version, and if so, download it to the Nix store. */
CachedDownloadResult downloadCached(
ref<Store> store, const string & uri, bool unpack, string name = "",
const Hash & expectedHash = Hash(), string * effectiveUri = nullptr,
int ttl = settings.tarballTtl);
CachedDownloadResult downloadCached(ref<Store> store, const CachedDownloadRequest & request);
enum Error { NotFound, Forbidden, Misc, Transient, Interrupted };
};