diff options
author | Carlo Nucera <carlo.nucera@protonmail.com> | 2020-07-28 15:36:45 -0400 |
---|---|---|
committer | Carlo Nucera <carlo.nucera@protonmail.com> | 2020-07-28 15:36:45 -0400 |
commit | cfe96bd7ce06c3153b036447f9a933f2231a2029 (patch) | |
tree | 991e0e5b2adda907a9305e622fa54f7a401969d5 /src/libfetchers/fetchers.hh | |
parent | d9fb9e9f26e29d9d9001af700deada32ca740cf6 (diff) | |
parent | b8eea7e81af53905be7845dffc6d0a83ea8edc97 (diff) |
Merge branch 'master' of github.com:NixOS/nix into ca-drv
Diffstat (limited to 'src/libfetchers/fetchers.hh')
-rw-r--r-- | src/libfetchers/fetchers.hh | 93 |
1 files changed, 60 insertions, 33 deletions
diff --git a/src/libfetchers/fetchers.hh b/src/libfetchers/fetchers.hh index 59a58ae67..be71b786b 100644 --- a/src/libfetchers/fetchers.hh +++ b/src/libfetchers/fetchers.hh @@ -3,7 +3,6 @@ #include "types.hh" #include "hash.hh" #include "path.hh" -#include "tree-info.hh" #include "attrs.hh" #include "url.hh" @@ -13,73 +12,101 @@ namespace nix { class Store; } namespace nix::fetchers { -struct Input; - struct Tree { Path actualPath; StorePath storePath; - TreeInfo info; + Tree(Path && actualPath, StorePath && storePath) : actualPath(actualPath), storePath(std::move(storePath)) {} }; -struct Input : std::enable_shared_from_this<Input> +struct InputScheme; + +struct Input { - std::optional<Hash> narHash; // FIXME: implement + friend class InputScheme; + + std::shared_ptr<InputScheme> scheme; // note: can be null + Attrs attrs; + bool immutable = false; + bool direct = true; + +public: + static Input fromURL(const std::string & url); - virtual std::string type() const = 0; + static Input fromURL(const ParsedURL & url); - virtual ~Input() { } + static Input fromAttrs(Attrs && attrs); - virtual bool operator ==(const Input & other) const { return false; } + ParsedURL toURL() const; + + std::string to_string() const; + + Attrs toAttrs() const; /* Check whether this is a "direct" input, that is, not one that goes through a registry. */ - virtual bool isDirect() const { return true; } + bool isDirect() const { return direct; } /* 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; } + bool isImmutable() const { return immutable; } - virtual bool contains(const Input & other) const { return false; } + bool hasAllInfo() const; - virtual std::optional<std::string> getRef() const { return {}; } + bool operator ==(const Input & other) const; - virtual std::optional<Hash> getRev() const { return {}; } + bool contains(const Input & other) const; - virtual ParsedURL toURL() const = 0; + std::pair<Tree, Input> fetch(ref<Store> store) const; - std::string to_string() const - { - return toURL().to_string(); - } + Input applyOverrides( + std::optional<std::string> ref, + std::optional<Hash> rev) const; - Attrs toAttrs() const; + void clone(const Path & destDir) const; - std::pair<Tree, std::shared_ptr<const Input>> fetchTree(ref<Store> store) const; + std::optional<Path> getSourcePath() const; -private: + void markChangedFile( + std::string_view file, + std::optional<std::string> commitMsg) const; - virtual std::pair<Tree, std::shared_ptr<const Input>> fetchTreeInternal(ref<Store> store) const = 0; + StorePath computeStorePath(Store & store) const; - virtual Attrs toAttrsInternal() const = 0; + // Convience functions for common attributes. + std::string getType() const; + std::optional<Hash> getNarHash() const; + std::optional<std::string> getRef() const; + std::optional<Hash> getRev() const; + std::optional<uint64_t> getRevCount() const; + std::optional<time_t> getLastModified() const; }; struct InputScheme { - virtual ~InputScheme() { } + virtual std::optional<Input> inputFromURL(const ParsedURL & url) = 0; - virtual std::unique_ptr<Input> inputFromURL(const ParsedURL & url) = 0; + virtual std::optional<Input> inputFromAttrs(const Attrs & attrs) = 0; - virtual std::unique_ptr<Input> inputFromAttrs(const Attrs & attrs) = 0; -}; + virtual ParsedURL toURL(const Input & input); + + virtual bool hasAllInfo(const Input & input) = 0; -std::unique_ptr<Input> inputFromURL(const ParsedURL & url); + virtual Input applyOverrides( + const Input & input, + std::optional<std::string> ref, + std::optional<Hash> rev); -std::unique_ptr<Input> inputFromURL(const std::string & url); + virtual void clone(const Input & input, const Path & destDir); -std::unique_ptr<Input> inputFromAttrs(const Attrs & attrs); + virtual std::optional<Path> getSourcePath(const Input & input); + + virtual void markChangedFile(const Input & input, std::string_view file, std::optional<std::string> commitMsg); + + virtual std::pair<Tree, Input> fetch(ref<Store> store, const Input & input) = 0; +}; -void registerInputScheme(std::unique_ptr<InputScheme> && fetcher); +void registerInputScheme(std::shared_ptr<InputScheme> && fetcher); struct DownloadFileResult { @@ -94,7 +121,7 @@ DownloadFileResult downloadFile( const std::string & name, bool immutable); -Tree downloadTarball( +std::pair<Tree, time_t> downloadTarball( ref<Store> store, const std::string & url, const std::string & name, |