diff --git a/src/libexpr/flake/flakeref.cc b/src/libexpr/flake/flakeref.cc index 0a53037fa..0d2c7f414 100644 --- a/src/libexpr/flake/flakeref.cc +++ b/src/libexpr/flake/flakeref.cc @@ -231,7 +231,7 @@ FlakeRef FlakeRef::fromAttrs(const fetchers::Attrs & attrs) std::pair, FlakeRef> FlakeRef::lazyFetch(ref store) const { - auto [accessor, lockedInput] = input.lazyFetch(store); + auto [accessor, lockedInput] = input.getAccessor(store); return {accessor, FlakeRef(std::move(lockedInput), subdir)}; } diff --git a/src/libexpr/primops/fetchTree.cc b/src/libexpr/primops/fetchTree.cc index 1bbb0f507..34316c3a5 100644 --- a/src/libexpr/primops/fetchTree.cc +++ b/src/libexpr/primops/fetchTree.cc @@ -184,7 +184,7 @@ static void fetchTree( state.debugThrowLastTrace(EvalError("in pure evaluation mode, 'fetchTree' requires a locked input, at %s", state.positions[pos])); if (params.returnPath) { - auto [accessor, input2] = input.lazyFetch(state.store); + auto [accessor, input2] = input.getAccessor(state.store); state.registerAccessor(accessor); diff --git a/src/libfetchers/fetchers.cc b/src/libfetchers/fetchers.cc index f17e4e85a..4ddc86982 100644 --- a/src/libfetchers/fetchers.cc +++ b/src/libfetchers/fetchers.cc @@ -119,7 +119,7 @@ std::pair Input::fetchToStore(ref store) const auto [storePath, input] = [&]() -> std::pair { try { - return scheme->fetch(store, *this); + return scheme->fetchToStore(store, *this); } catch (Error & e) { e.addTrace({}, "while fetching the input '%s'", to_string()); throw; @@ -159,13 +159,13 @@ void Input::checkLocked(Store & store, const StorePath & storePath, Input & inpu assert(input.hasAllInfo()); } -std::pair, Input> Input::lazyFetch(ref store) const +std::pair, Input> Input::getAccessor(ref store) const { if (!scheme) throw Error("cannot fetch unsupported input '%s'", attrsToJSON(toAttrs())); try { - return scheme->lazyFetch(store, *this); + return scheme->getAccessor(store, *this); } catch (Error & e) { e.addTrace({}, "while fetching the input '%s'", to_string()); throw; @@ -298,9 +298,9 @@ void InputScheme::clone(const Input & input, const Path & destDir) throw Error("do not know how to clone input '%s'", input.to_string()); } -std::pair InputScheme::fetch(ref store, const Input & input) +std::pair InputScheme::fetchToStore(ref store, const Input & input) { - auto [accessor, input2] = lazyFetch(store, input); + auto [accessor, input2] = getAccessor(store, input); auto source = sinkToSource([&, accessor{accessor}](Sink & sink) { accessor->dumpPath(CanonPath::root, sink); @@ -311,9 +311,9 @@ std::pair InputScheme::fetch(ref store, const Input & i return {storePath, input2}; } -std::pair, Input> InputScheme::lazyFetch(ref store, const Input & input) +std::pair, Input> InputScheme::getAccessor(ref store, const Input & input) { - auto [storePath, input2] = fetch(store, input); + auto [storePath, input2] = fetchToStore(store, input); input.checkLocked(*store, storePath, input2); diff --git a/src/libfetchers/fetchers.hh b/src/libfetchers/fetchers.hh index 94135512b..1984c4712 100644 --- a/src/libfetchers/fetchers.hh +++ b/src/libfetchers/fetchers.hh @@ -69,7 +69,7 @@ public: /* Return an InputAccessor that allows access to files in the input without copying it to the store. Also return a possibly unlocked input. */ - std::pair, Input> lazyFetch(ref store) const; + std::pair, Input> getAccessor(ref store) const; Input applyOverrides( std::optional ref, @@ -134,18 +134,13 @@ struct InputScheme virtual void markChangedFile(const Input & input, std::string_view file, std::optional commitMsg); - /* Note: the default implementations of fetch() and lazyFetch() - are defined using the other, so implementations have to - override at least one. */ + /* Note: the default implementations of fetchToStore() and + getAccessor() are defined using the other, so implementations + have to override at least one. */ - virtual std::pair fetch(ref store, const Input & input); + virtual std::pair fetchToStore(ref store, const Input & input); - virtual std::pair, Input> lazyFetch(ref store, const Input & input); - - virtual ref getAccessor() - { - throw UnimplementedError("getAccessor"); - } + virtual std::pair, Input> getAccessor(ref store, const Input & input); virtual bool isRelative(const Input & input) const { return false; } diff --git a/src/libfetchers/git.cc b/src/libfetchers/git.cc index ed6e1e7f5..9cbac1c29 100644 --- a/src/libfetchers/git.cc +++ b/src/libfetchers/git.cc @@ -447,7 +447,7 @@ struct GitInputScheme : InputScheme return *head; } - std::pair fetch(ref store, const Input & _input) override + std::pair fetchToStore(ref store, const Input & _input) override { Input input(_input); @@ -718,7 +718,7 @@ struct GitInputScheme : InputScheme return {std::move(storePath), input}; } - std::pair, Input> lazyFetch(ref store, const Input & _input) override + std::pair, Input> getAccessor(ref store, const Input & _input) override { Input input(_input); @@ -728,7 +728,7 @@ struct GitInputScheme : InputScheme Nix store. TODO: We could have an accessor for fetching files from the Git repository directly. */ if (input.getRef() || input.getRev() || !repoInfo.isLocal) - return InputScheme::lazyFetch(store, input); + return InputScheme::getAccessor(store, input); repoInfo.checkDirty(); diff --git a/src/libfetchers/github.cc b/src/libfetchers/github.cc index 8756b1937..5409594f7 100644 --- a/src/libfetchers/github.cc +++ b/src/libfetchers/github.cc @@ -228,7 +228,7 @@ struct GitArchiveInputScheme : InputScheme return {res.storePath, input}; } - std::pair, Input> lazyFetch(ref store, const Input & input) override + std::pair, Input> getAccessor(ref store, const Input & input) override { auto [storePath, input2] = downloadArchive(store, input); diff --git a/src/libfetchers/indirect.cc b/src/libfetchers/indirect.cc index 64f96b141..32ee6719d 100644 --- a/src/libfetchers/indirect.cc +++ b/src/libfetchers/indirect.cc @@ -94,9 +94,8 @@ struct IndirectInputScheme : InputScheme return input; } - std::pair fetch(ref store, const Input & input) override + std::pair fetchToStore(ref store, const Input & input) override { - abort(); throw Error("indirect input '%s' cannot be fetched directly", input.to_string()); } }; diff --git a/src/libfetchers/mercurial.cc b/src/libfetchers/mercurial.cc index 5c5671681..4938324c0 100644 --- a/src/libfetchers/mercurial.cc +++ b/src/libfetchers/mercurial.cc @@ -145,7 +145,7 @@ struct MercurialInputScheme : InputScheme return {isLocal, isLocal ? url.path : url.base}; } - std::pair fetch(ref store, const Input & _input) override + std::pair fetchToStore(ref store, const Input & _input) override { Input input(_input); diff --git a/src/libfetchers/path.cc b/src/libfetchers/path.cc index ff95fad7d..20cb934bf 100644 --- a/src/libfetchers/path.cc +++ b/src/libfetchers/path.cc @@ -96,34 +96,7 @@ struct PathInputScheme : InputScheme throw Error("cannot fetch input '%s' because it uses a relative path", input.to_string()); } - std::pair fetch(ref store, const Input & _input) override - { - Input input(_input); - - auto absPath = getAbsPath(store, input); - - Activity act(*logger, lvlTalkative, actUnknown, fmt("copying '%s'", absPath)); - - // FIXME: check whether access to 'path' is allowed. - auto storePath = store->maybeParseStorePath(absPath.abs()); - - if (storePath) - store->addTempRoot(*storePath); - - time_t mtime = 0; - if (!storePath || storePath->name() != "source" || !store->isValidPath(*storePath)) { - // FIXME: try to substitute storePath. - auto src = sinkToSource([&](Sink & sink) { - mtime = dumpPathAndGetMtime(absPath.abs(), sink, defaultPathFilter); - }); - storePath = store->addToStoreFromDump(*src, "source"); - } - input.attrs.insert_or_assign("lastModified", uint64_t(mtime)); - - return {std::move(*storePath), input}; - } - - std::pair, Input> lazyFetch(ref store, const Input & input) override + std::pair, Input> getAccessor(ref store, const Input & input) override { auto absPath = getAbsPath(store, input); auto input2(input); diff --git a/src/libfetchers/tarball.cc b/src/libfetchers/tarball.cc index e96de316e..ab8f847dd 100644 --- a/src/libfetchers/tarball.cc +++ b/src/libfetchers/tarball.cc @@ -250,7 +250,7 @@ struct FileInputScheme : CurlInputScheme : !hasTarballExtension(url.path)); } - std::pair fetch(ref store, const Input & input) override + std::pair fetchToStore(ref store, const Input & input) override { auto file = downloadFile(store, getStrAttr(input.attrs, "url"), input.getName(), false); return {std::move(file.storePath), input}; @@ -271,7 +271,7 @@ struct TarballInputScheme : CurlInputScheme : hasTarballExtension(url.path)); } - std::pair fetch(ref store, const Input & input) override + std::pair fetchToStore(ref store, const Input & input) override { return { downloadTarball(store, getStrAttr(input.attrs, "url"), input.getName(), false).first, diff --git a/src/nix/registry.cc b/src/nix/registry.cc index 44eaf89bc..9afa2fb57 100644 --- a/src/nix/registry.cc +++ b/src/nix/registry.cc @@ -188,7 +188,7 @@ struct CmdRegistryPin : RegistryCommand, EvalCommand auto ref = parseFlakeRef(url); auto lockedRef = parseFlakeRef(locked); registry->remove(ref.input); - auto [accessor, resolved] = lockedRef.resolve(store).input.lazyFetch(store); + auto resolved = lockedRef.resolve(store).input.getAccessor(store).second; if (!resolved.isLocked()) warn("flake '%s' is not locked", resolved.to_string()); fetchers::Attrs extraAttrs;