aboutsummaryrefslogtreecommitdiff
path: root/src/libfetchers/fetchers.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/libfetchers/fetchers.hh')
-rw-r--r--src/libfetchers/fetchers.hh104
1 files changed, 57 insertions, 47 deletions
diff --git a/src/libfetchers/fetchers.hh b/src/libfetchers/fetchers.hh
index b75dcffa5..c43cfe50c 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,89 +12,100 @@ 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>
+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);
+
+ static Input fromURL(const ParsedURL & url);
- virtual std::string type() const = 0;
+ static Input fromAttrs(Attrs && attrs);
- virtual ~Input() { }
+ ParsedURL toURL() const;
- virtual bool operator ==(const Input & other) const { return false; }
+ 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; }
-
- virtual bool contains(const Input & other) const { return false; }
-
- virtual std::optional<std::string> getRef() const { return {}; }
-
- virtual std::optional<Hash> getRev() const { return {}; }
+ bool isImmutable() const { return immutable; }
- virtual ParsedURL toURL() const = 0;
+ bool hasAllInfo() const;
- std::string to_string() const
- {
- return toURL().to_string();
- }
+ bool operator ==(const Input & other) const;
- Attrs toAttrs() const;
+ bool contains(const Input & other) const;
- std::pair<Tree, std::shared_ptr<const Input>> fetchTree(ref<Store> store) const;
+ std::pair<Tree, Input> fetch(ref<Store> store) const;
- virtual std::shared_ptr<const Input> applyOverrides(
+ 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); }
+ void clone(const Path & destDir) const;
- virtual void clone(const Path & destDir) const
- {
- throw Error("do not know how to clone input '%s'", to_string());
- }
+ 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);
-std::unique_ptr<Input> inputFromURL(const ParsedURL & url);
+ virtual bool hasAllInfo(const Input & input) = 0;
-std::unique_ptr<Input> inputFromURL(const std::string & url);
+ virtual Input applyOverrides(
+ const Input & input,
+ std::optional<std::string> ref,
+ std::optional<Hash> rev);
+
+ virtual void clone(const Input & input, const Path & destDir);
+
+ virtual std::optional<Path> getSourcePath(const Input & input);
-std::unique_ptr<Input> inputFromAttrs(const Attrs & attrs);
+ 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
{
@@ -110,7 +120,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,