1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-04 15:31:47 +02:00

Refactor downloadCached() interface

This commit is contained in:
Eelco Dolstra 2019-05-22 23:36:29 +02:00
parent 66f1d7ee95
commit df3f5a78d5
7 changed files with 73 additions and 54 deletions

View file

@ -36,11 +36,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
@ -48,6 +60,7 @@ struct CachedDownloadResult
Path storePath;
Path path;
std::optional<std::string> etag;
std::string effectiveUri;
};
class Store;
@ -73,10 +86,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 };
};