about summary refs log tree commit diff
path: root/src/libstore/download.hh
blob: 08618ba1c95d6f055066463538d9e21163c5d6ce (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#pragma once

#include "types.hh"
#include "hash.hh"

#include <string>

namespace nix {

struct DownloadOptions
{
    std::string expectedETag;
    bool verifyTLS = true;
    enum { yes, no, automatic } showProgress = yes;
    bool head = false;
    size_t tries = 1;
};

struct DownloadResult
{
    bool cached;
    string etag;
    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, string name = "",
        const Hash & expectedHash = Hash());

    enum Error { NotFound, Forbidden, Misc, Transient };
};

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);

}