From 4f8b253ea75f69ba955d14dda9b7e3007d684042 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 10 Aug 2022 16:39:25 +0200 Subject: [PATCH] Remove Input::direct --- src/libfetchers/fetchers.cc | 6 ++++++ src/libfetchers/fetchers.hh | 6 ++++-- src/libfetchers/indirect.cc | 5 +++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/libfetchers/fetchers.cc b/src/libfetchers/fetchers.cc index 33e088f1a..8e7999157 100644 --- a/src/libfetchers/fetchers.cc +++ b/src/libfetchers/fetchers.cc @@ -88,6 +88,12 @@ Attrs Input::toAttrs() const return attrs; } +bool Input::isDirect() const +{ + assert(scheme); + return !scheme || scheme->isDirect(*this); +} + std::optional Input::isRelative() const { assert(scheme); diff --git a/src/libfetchers/fetchers.hh b/src/libfetchers/fetchers.hh index abf78f6d5..bb7fa04e6 100644 --- a/src/libfetchers/fetchers.hh +++ b/src/libfetchers/fetchers.hh @@ -28,7 +28,6 @@ struct Input std::shared_ptr scheme; // note: can be null Attrs attrs; bool locked = false; - bool direct = true; public: static Input fromURL(const std::string & url); @@ -47,7 +46,7 @@ public: /* Check whether this is a "direct" input, that is, not one that goes through a registry. */ - bool isDirect() const { return direct; } + bool isDirect() const; /* Check whether this is a "locked" input, that is, one that contains a commit hash or content hash. */ @@ -138,6 +137,9 @@ struct InputScheme virtual std::pair, Input> getAccessor(ref store, const Input & input) const = 0; + virtual bool isDirect(const Input & input) const + { return true; } + virtual std::optional isRelative(const Input & input) const { return std::nullopt; } diff --git a/src/libfetchers/indirect.cc b/src/libfetchers/indirect.cc index bd4ecf320..d0d0f4af8 100644 --- a/src/libfetchers/indirect.cc +++ b/src/libfetchers/indirect.cc @@ -41,7 +41,6 @@ struct IndirectInputScheme : InputScheme // FIXME: forbid query params? Input input; - input.direct = false; input.attrs.insert_or_assign("type", "indirect"); input.attrs.insert_or_assign("id", id); if (rev) input.attrs.insert_or_assign("rev", rev->gitRev()); @@ -63,7 +62,6 @@ struct IndirectInputScheme : InputScheme throw BadURL("'%s' is not a valid flake ID", id); Input input; - input.direct = false; input.attrs = attrs; return input; } @@ -98,6 +96,9 @@ struct IndirectInputScheme : InputScheme { throw Error("indirect input '%s' cannot be fetched directly", input.to_string()); } + + bool isDirect(const Input & input) const override + { return false; } }; static auto rIndirectInputScheme = OnStartup([] { registerInputScheme(std::make_unique()); });