2020-01-21 17:27:53 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "types.hh"
|
|
|
|
#include "hash.hh"
|
|
|
|
#include "path.hh"
|
2020-02-01 17:41:54 +02:00
|
|
|
#include "tree-info.hh"
|
2020-03-17 21:54:36 +02:00
|
|
|
#include "attrs.hh"
|
2020-01-21 17:27:53 +02:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
namespace nix { class Store; }
|
|
|
|
|
|
|
|
namespace nix::fetchers {
|
|
|
|
|
|
|
|
struct Input;
|
|
|
|
|
|
|
|
struct Tree
|
|
|
|
{
|
|
|
|
Path actualPath;
|
|
|
|
StorePath storePath;
|
2020-02-01 17:41:54 +02:00
|
|
|
TreeInfo info;
|
2020-01-21 17:27:53 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Input : std::enable_shared_from_this<Input>
|
|
|
|
{
|
2020-01-28 14:11:02 +02:00
|
|
|
std::optional<Hash> narHash; // FIXME: implement
|
2020-01-21 17:27:53 +02:00
|
|
|
|
2020-01-31 20:16:40 +02:00
|
|
|
virtual std::string type() const = 0;
|
|
|
|
|
2020-01-22 22:26:19 +02:00
|
|
|
virtual ~Input() { }
|
|
|
|
|
2020-01-21 17:27:53 +02:00
|
|
|
virtual bool operator ==(const Input & other) const { return false; }
|
|
|
|
|
2020-02-02 12:31:58 +02:00
|
|
|
/* Check whether this is a "direct" input, that is, not
|
|
|
|
one that goes through a registry. */
|
2020-01-21 17:27:53 +02:00
|
|
|
virtual bool isDirect() const { return true; }
|
|
|
|
|
2020-02-02 12:31:58 +02:00
|
|
|
/* Check whether this is an "immutable" input, that is,
|
|
|
|
one that contains a commit hash or content hash. */
|
2020-01-21 17:27:53 +02:00
|
|
|
virtual bool isImmutable() const { return (bool) narHash; }
|
|
|
|
|
|
|
|
virtual bool contains(const Input & other) const { return false; }
|
|
|
|
|
|
|
|
virtual std::optional<std::string> getRef() const { return {}; }
|
|
|
|
|
|
|
|
virtual std::optional<Hash> getRev() const { return {}; }
|
|
|
|
|
|
|
|
virtual std::string to_string() const = 0;
|
|
|
|
|
2020-01-31 20:16:40 +02:00
|
|
|
Attrs toAttrs() const;
|
|
|
|
|
2020-01-21 17:27:53 +02:00
|
|
|
std::pair<Tree, std::shared_ptr<const Input>> fetchTree(ref<Store> store) const;
|
|
|
|
|
|
|
|
virtual std::shared_ptr<const Input> applyOverrides(
|
|
|
|
std::optional<std::string> ref,
|
|
|
|
std::optional<Hash> rev) const;
|
|
|
|
|
|
|
|
virtual std::optional<Path> getSourcePath() const { return {}; }
|
|
|
|
|
2020-02-05 15:48:49 +02:00
|
|
|
virtual void markChangedFile(
|
|
|
|
std::string_view file,
|
|
|
|
std::optional<std::string> commitMsg) const
|
|
|
|
{ assert(false); }
|
2020-02-02 17:32:46 +02:00
|
|
|
|
2020-01-21 17:27:53 +02:00
|
|
|
virtual void clone(const Path & destDir) const
|
|
|
|
{
|
|
|
|
throw Error("do not know how to clone input '%s'", to_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
virtual std::pair<Tree, std::shared_ptr<const Input>> fetchTreeInternal(ref<Store> store) const = 0;
|
2020-01-31 20:16:40 +02:00
|
|
|
|
|
|
|
virtual Attrs toAttrsInternal() const = 0;
|
2020-01-21 17:27:53 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ParsedURL;
|
|
|
|
|
|
|
|
struct InputScheme
|
|
|
|
{
|
2020-01-22 22:26:19 +02:00
|
|
|
virtual ~InputScheme() { }
|
|
|
|
|
2020-01-21 17:27:53 +02:00
|
|
|
virtual std::unique_ptr<Input> inputFromURL(const ParsedURL & url) = 0;
|
2020-01-31 20:16:40 +02:00
|
|
|
|
2020-03-17 21:54:36 +02:00
|
|
|
virtual std::unique_ptr<Input> inputFromAttrs(const Attrs & attrs) = 0;
|
2020-01-21 17:27:53 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
std::unique_ptr<Input> inputFromURL(const ParsedURL & url);
|
|
|
|
|
|
|
|
std::unique_ptr<Input> inputFromURL(const std::string & url);
|
|
|
|
|
2020-03-17 21:54:36 +02:00
|
|
|
std::unique_ptr<Input> inputFromAttrs(const Attrs & attrs);
|
2020-01-31 20:16:40 +02:00
|
|
|
|
2020-01-21 17:27:53 +02:00
|
|
|
void registerInputScheme(std::unique_ptr<InputScheme> && fetcher);
|
|
|
|
|
2020-03-18 16:14:23 +02:00
|
|
|
struct DownloadFileResult
|
|
|
|
{
|
|
|
|
StorePath storePath;
|
|
|
|
std::string etag;
|
2020-03-18 18:23:56 +02:00
|
|
|
std::string effectiveUrl;
|
2020-03-18 16:14:23 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
DownloadFileResult downloadFile(
|
2020-03-18 15:08:25 +02:00
|
|
|
ref<Store> store,
|
|
|
|
const std::string & url,
|
|
|
|
const std::string & name,
|
|
|
|
bool immutable);
|
|
|
|
|
|
|
|
Tree downloadTarball(
|
|
|
|
ref<Store> store,
|
|
|
|
const std::string & url,
|
|
|
|
const std::string & name,
|
|
|
|
bool immutable);
|
|
|
|
|
2020-01-21 17:27:53 +02:00
|
|
|
}
|