nix-gh/src/libstore/download.hh
2016-08-11 11:34:43 -04:00

57 lines
1.1 KiB
C++

#pragma once
#include "types.hh"
#include "hash.hh"
#include <string>
namespace nix {
struct DownloadOptions
{
string expectedETag;
bool verifyTLS{true};
enum { yes, no, automatic } showProgress{yes};
bool head{false};
};
struct DownloadResult
{
bool cached;
string etag;
string effectiveUrl;
std::shared_ptr<std::string> data;
};
class Store;
struct Downloader
{
virtual DownloadResult download(string url, const DownloadOptions & options) = 0;
Path downloadCached(ref<Store> store, const string & url, bool unpack,
const Hash & expectedHash = Hash());
/* Need to overload because can't have an rvalue default value for non-const reference */
Path downloadCached(ref<Store> store, const string & url, bool unpack,
string & effectiveUrl, const Hash & expectedHash = Hash());
enum Error { NotFound, Forbidden, Misc };
};
ref<Downloader> makeDownloader();
class DownloadError : public Error
{
public:
Downloader::Error error;
DownloadError(Downloader::Error error, const FormatOrString & fs)
: Error(fs), error(error)
{ }
};
bool isUri(const string & s);
}