diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2020-03-30 14:03:28 +0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2020-03-30 14:04:53 +0200 |
commit | e0a0ae0467fa8cdcc542f593b9d94283f04508ff (patch) | |
tree | 9ee49c40c301f51c4f20a0d9ad2031c7de001100 /src/libfetchers/fetchers.hh | |
parent | 4ba4c7ff66c95319d98fa859428f60f30f94edd4 (diff) |
Move fetchers from libstore to libfetchers
Diffstat (limited to 'src/libfetchers/fetchers.hh')
-rw-r--r-- | src/libfetchers/fetchers.hh | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/src/libfetchers/fetchers.hh b/src/libfetchers/fetchers.hh new file mode 100644 index 000000000..b75dcffa5 --- /dev/null +++ b/src/libfetchers/fetchers.hh @@ -0,0 +1,119 @@ +#pragma once + +#include "types.hh" +#include "hash.hh" +#include "path.hh" +#include "tree-info.hh" +#include "attrs.hh" +#include "url.hh" + +#include <memory> + +namespace nix { class Store; } + +namespace nix::fetchers { + +struct Input; + +struct Tree +{ + Path actualPath; + StorePath storePath; + TreeInfo info; +}; + +struct Input : std::enable_shared_from_this<Input> +{ + std::optional<Hash> narHash; // FIXME: implement + + virtual std::string type() const = 0; + + virtual ~Input() { } + + virtual bool operator ==(const Input & other) const { return false; } + + /* Check whether this is a "direct" input, that is, not + one that goes through a registry. */ + virtual bool isDirect() const { return true; } + + /* Check whether this is an "immutable" input, that is, + one that contains a commit hash or content hash. */ + 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 ParsedURL toURL() const = 0; + + std::string to_string() const + { + return toURL().to_string(); + } + + Attrs toAttrs() const; + + 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 {}; } + + virtual void markChangedFile( + std::string_view file, + std::optional<std::string> commitMsg) const + { assert(false); } + + 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; + + virtual Attrs toAttrsInternal() const = 0; +}; + +struct InputScheme +{ + virtual ~InputScheme() { } + + virtual std::unique_ptr<Input> inputFromURL(const ParsedURL & url) = 0; + + virtual std::unique_ptr<Input> inputFromAttrs(const Attrs & attrs) = 0; +}; + +std::unique_ptr<Input> inputFromURL(const ParsedURL & url); + +std::unique_ptr<Input> inputFromURL(const std::string & url); + +std::unique_ptr<Input> inputFromAttrs(const Attrs & attrs); + +void registerInputScheme(std::unique_ptr<InputScheme> && fetcher); + +struct DownloadFileResult +{ + StorePath storePath; + std::string etag; + std::string effectiveUrl; +}; + +DownloadFileResult downloadFile( + 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); + +} |