Rename fetch() -> fetchToStore(), lazyFetch() -> getAccessor()

This commit is contained in:
Eelco Dolstra 2022-07-25 16:30:50 +02:00
parent 7a64bb7f1c
commit 1790698a74
11 changed files with 25 additions and 58 deletions

View file

@ -231,7 +231,7 @@ FlakeRef FlakeRef::fromAttrs(const fetchers::Attrs & attrs)
std::pair<ref<InputAccessor>, FlakeRef> FlakeRef::lazyFetch(ref<Store> store) const std::pair<ref<InputAccessor>, FlakeRef> FlakeRef::lazyFetch(ref<Store> store) const
{ {
auto [accessor, lockedInput] = input.lazyFetch(store); auto [accessor, lockedInput] = input.getAccessor(store);
return {accessor, FlakeRef(std::move(lockedInput), subdir)}; return {accessor, FlakeRef(std::move(lockedInput), subdir)};
} }

View file

@ -184,7 +184,7 @@ static void fetchTree(
state.debugThrowLastTrace(EvalError("in pure evaluation mode, 'fetchTree' requires a locked input, at %s", state.positions[pos])); state.debugThrowLastTrace(EvalError("in pure evaluation mode, 'fetchTree' requires a locked input, at %s", state.positions[pos]));
if (params.returnPath) { if (params.returnPath) {
auto [accessor, input2] = input.lazyFetch(state.store); auto [accessor, input2] = input.getAccessor(state.store);
state.registerAccessor(accessor); state.registerAccessor(accessor);

View file

@ -119,7 +119,7 @@ std::pair<StorePath, Input> Input::fetchToStore(ref<Store> store) const
auto [storePath, input] = [&]() -> std::pair<StorePath, Input> { auto [storePath, input] = [&]() -> std::pair<StorePath, Input> {
try { try {
return scheme->fetch(store, *this); return scheme->fetchToStore(store, *this);
} catch (Error & e) { } catch (Error & e) {
e.addTrace({}, "while fetching the input '%s'", to_string()); e.addTrace({}, "while fetching the input '%s'", to_string());
throw; throw;
@ -159,13 +159,13 @@ void Input::checkLocked(Store & store, const StorePath & storePath, Input & inpu
assert(input.hasAllInfo()); assert(input.hasAllInfo());
} }
std::pair<ref<InputAccessor>, Input> Input::lazyFetch(ref<Store> store) const std::pair<ref<InputAccessor>, Input> Input::getAccessor(ref<Store> store) const
{ {
if (!scheme) if (!scheme)
throw Error("cannot fetch unsupported input '%s'", attrsToJSON(toAttrs())); throw Error("cannot fetch unsupported input '%s'", attrsToJSON(toAttrs()));
try { try {
return scheme->lazyFetch(store, *this); return scheme->getAccessor(store, *this);
} catch (Error & e) { } catch (Error & e) {
e.addTrace({}, "while fetching the input '%s'", to_string()); e.addTrace({}, "while fetching the input '%s'", to_string());
throw; 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()); throw Error("do not know how to clone input '%s'", input.to_string());
} }
std::pair<StorePath, Input> InputScheme::fetch(ref<Store> store, const Input & input) std::pair<StorePath, Input> InputScheme::fetchToStore(ref<Store> store, const Input & input)
{ {
auto [accessor, input2] = lazyFetch(store, input); auto [accessor, input2] = getAccessor(store, input);
auto source = sinkToSource([&, accessor{accessor}](Sink & sink) { auto source = sinkToSource([&, accessor{accessor}](Sink & sink) {
accessor->dumpPath(CanonPath::root, sink); accessor->dumpPath(CanonPath::root, sink);
@ -311,9 +311,9 @@ std::pair<StorePath, Input> InputScheme::fetch(ref<Store> store, const Input & i
return {storePath, input2}; return {storePath, input2};
} }
std::pair<ref<InputAccessor>, Input> InputScheme::lazyFetch(ref<Store> store, const Input & input) std::pair<ref<InputAccessor>, Input> InputScheme::getAccessor(ref<Store> store, const Input & input)
{ {
auto [storePath, input2] = fetch(store, input); auto [storePath, input2] = fetchToStore(store, input);
input.checkLocked(*store, storePath, input2); input.checkLocked(*store, storePath, input2);

View file

@ -69,7 +69,7 @@ public:
/* Return an InputAccessor that allows access to files in the /* Return an InputAccessor that allows access to files in the
input without copying it to the store. Also return a possibly input without copying it to the store. Also return a possibly
unlocked input. */ unlocked input. */
std::pair<ref<InputAccessor>, Input> lazyFetch(ref<Store> store) const; std::pair<ref<InputAccessor>, Input> getAccessor(ref<Store> store) const;
Input applyOverrides( Input applyOverrides(
std::optional<std::string> ref, std::optional<std::string> ref,
@ -134,18 +134,13 @@ struct InputScheme
virtual void markChangedFile(const Input & input, std::string_view file, std::optional<std::string> commitMsg); virtual void markChangedFile(const Input & input, std::string_view file, std::optional<std::string> commitMsg);
/* Note: the default implementations of fetch() and lazyFetch() /* Note: the default implementations of fetchToStore() and
are defined using the other, so implementations have to getAccessor() are defined using the other, so implementations
override at least one. */ have to override at least one. */
virtual std::pair<StorePath, Input> fetch(ref<Store> store, const Input & input); virtual std::pair<StorePath, Input> fetchToStore(ref<Store> store, const Input & input);
virtual std::pair<ref<InputAccessor>, Input> lazyFetch(ref<Store> store, const Input & input); virtual std::pair<ref<InputAccessor>, Input> getAccessor(ref<Store> store, const Input & input);
virtual ref<InputAccessor> getAccessor()
{
throw UnimplementedError("getAccessor");
}
virtual bool isRelative(const Input & input) const virtual bool isRelative(const Input & input) const
{ return false; } { return false; }

View file

@ -447,7 +447,7 @@ struct GitInputScheme : InputScheme
return *head; return *head;
} }
std::pair<StorePath, Input> fetch(ref<Store> store, const Input & _input) override std::pair<StorePath, Input> fetchToStore(ref<Store> store, const Input & _input) override
{ {
Input input(_input); Input input(_input);
@ -718,7 +718,7 @@ struct GitInputScheme : InputScheme
return {std::move(storePath), input}; return {std::move(storePath), input};
} }
std::pair<ref<InputAccessor>, Input> lazyFetch(ref<Store> store, const Input & _input) override std::pair<ref<InputAccessor>, Input> getAccessor(ref<Store> store, const Input & _input) override
{ {
Input input(_input); Input input(_input);
@ -728,7 +728,7 @@ struct GitInputScheme : InputScheme
Nix store. TODO: We could have an accessor for fetching Nix store. TODO: We could have an accessor for fetching
files from the Git repository directly. */ files from the Git repository directly. */
if (input.getRef() || input.getRev() || !repoInfo.isLocal) if (input.getRef() || input.getRev() || !repoInfo.isLocal)
return InputScheme::lazyFetch(store, input); return InputScheme::getAccessor(store, input);
repoInfo.checkDirty(); repoInfo.checkDirty();

View file

@ -228,7 +228,7 @@ struct GitArchiveInputScheme : InputScheme
return {res.storePath, input}; return {res.storePath, input};
} }
std::pair<ref<InputAccessor>, Input> lazyFetch(ref<Store> store, const Input & input) override std::pair<ref<InputAccessor>, Input> getAccessor(ref<Store> store, const Input & input) override
{ {
auto [storePath, input2] = downloadArchive(store, input); auto [storePath, input2] = downloadArchive(store, input);

View file

@ -94,9 +94,8 @@ struct IndirectInputScheme : InputScheme
return input; return input;
} }
std::pair<StorePath, Input> fetch(ref<Store> store, const Input & input) override std::pair<StorePath, Input> fetchToStore(ref<Store> store, const Input & input) override
{ {
abort();
throw Error("indirect input '%s' cannot be fetched directly", input.to_string()); throw Error("indirect input '%s' cannot be fetched directly", input.to_string());
} }
}; };

View file

@ -145,7 +145,7 @@ struct MercurialInputScheme : InputScheme
return {isLocal, isLocal ? url.path : url.base}; return {isLocal, isLocal ? url.path : url.base};
} }
std::pair<StorePath, Input> fetch(ref<Store> store, const Input & _input) override std::pair<StorePath, Input> fetchToStore(ref<Store> store, const Input & _input) override
{ {
Input input(_input); Input input(_input);

View file

@ -96,34 +96,7 @@ struct PathInputScheme : InputScheme
throw Error("cannot fetch input '%s' because it uses a relative path", input.to_string()); throw Error("cannot fetch input '%s' because it uses a relative path", input.to_string());
} }
std::pair<StorePath, Input> fetch(ref<Store> store, const Input & _input) override std::pair<ref<InputAccessor>, Input> getAccessor(ref<Store> 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<ref<InputAccessor>, Input> lazyFetch(ref<Store> store, const Input & input) override
{ {
auto absPath = getAbsPath(store, input); auto absPath = getAbsPath(store, input);
auto input2(input); auto input2(input);

View file

@ -250,7 +250,7 @@ struct FileInputScheme : CurlInputScheme
: !hasTarballExtension(url.path)); : !hasTarballExtension(url.path));
} }
std::pair<StorePath, Input> fetch(ref<Store> store, const Input & input) override std::pair<StorePath, Input> fetchToStore(ref<Store> store, const Input & input) override
{ {
auto file = downloadFile(store, getStrAttr(input.attrs, "url"), input.getName(), false); auto file = downloadFile(store, getStrAttr(input.attrs, "url"), input.getName(), false);
return {std::move(file.storePath), input}; return {std::move(file.storePath), input};
@ -271,7 +271,7 @@ struct TarballInputScheme : CurlInputScheme
: hasTarballExtension(url.path)); : hasTarballExtension(url.path));
} }
std::pair<StorePath, Input> fetch(ref<Store> store, const Input & input) override std::pair<StorePath, Input> fetchToStore(ref<Store> store, const Input & input) override
{ {
return { return {
downloadTarball(store, getStrAttr(input.attrs, "url"), input.getName(), false).first, downloadTarball(store, getStrAttr(input.attrs, "url"), input.getName(), false).first,

View file

@ -188,7 +188,7 @@ struct CmdRegistryPin : RegistryCommand, EvalCommand
auto ref = parseFlakeRef(url); auto ref = parseFlakeRef(url);
auto lockedRef = parseFlakeRef(locked); auto lockedRef = parseFlakeRef(locked);
registry->remove(ref.input); 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()) if (!resolved.isLocked())
warn("flake '%s' is not locked", resolved.to_string()); warn("flake '%s' is not locked", resolved.to_string());
fetchers::Attrs extraAttrs; fetchers::Attrs extraAttrs;