diff options
-rw-r--r-- | src/libfetchers/fetchers.cc | 12 | ||||
-rw-r--r-- | src/libfetchers/fetchers.hh | 3 | ||||
-rw-r--r-- | src/libfetchers/git.cc | 14 | ||||
-rw-r--r-- | src/libfetchers/github.cc | 9 | ||||
-rw-r--r-- | src/libfetchers/indirect.cc | 2 | ||||
-rw-r--r-- | src/libfetchers/mercurial.cc | 14 | ||||
-rw-r--r-- | src/libfetchers/path.cc | 7 | ||||
-rw-r--r-- | src/libfetchers/tarball.cc | 8 |
8 files changed, 25 insertions, 44 deletions
diff --git a/src/libfetchers/fetchers.cc b/src/libfetchers/fetchers.cc index e158d914b..c06ccb929 100644 --- a/src/libfetchers/fetchers.cc +++ b/src/libfetchers/fetchers.cc @@ -124,15 +124,13 @@ std::pair<Tree, Input> Input::fetch(ref<Store> store) const debug("using substituted/cached input '%s' in '%s'", to_string(), store->printStorePath(storePath)); - auto actualPath = store->toRealPath(storePath); - - return {fetchers::Tree(std::move(actualPath), std::move(storePath)), *this}; + return {Tree { .actualPath = store->toRealPath(storePath), .storePath = std::move(storePath) }, *this}; } catch (Error & e) { debug("substitution of input '%s' failed: %s", to_string(), e.what()); } } - auto [tree, input] = [&]() -> std::pair<Tree, Input> { + auto [storePath, input] = [&]() -> std::pair<StorePath, Input> { try { return scheme->fetch(store, *this); } catch (Error & e) { @@ -141,8 +139,10 @@ std::pair<Tree, Input> Input::fetch(ref<Store> store) const } }(); - if (tree.actualPath == "") - tree.actualPath = store->toRealPath(tree.storePath); + Tree tree { + .actualPath = store->toRealPath(storePath), + .storePath = storePath, + }; auto narHash = store->queryPathInfo(tree.storePath)->narHash; input.attrs.insert_or_assign("narHash", narHash.to_string(SRI, true)); diff --git a/src/libfetchers/fetchers.hh b/src/libfetchers/fetchers.hh index c43b047a7..2836af5fa 100644 --- a/src/libfetchers/fetchers.hh +++ b/src/libfetchers/fetchers.hh @@ -16,7 +16,6 @@ struct Tree { Path actualPath; StorePath storePath; - Tree(Path && actualPath, StorePath && storePath) : actualPath(actualPath), storePath(std::move(storePath)) {} }; struct InputScheme; @@ -131,7 +130,7 @@ struct InputScheme 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; + virtual std::pair<StorePath, Input> fetch(ref<Store> store, const Input & input) = 0; }; void registerInputScheme(std::shared_ptr<InputScheme> && fetcher); diff --git a/src/libfetchers/git.cc b/src/libfetchers/git.cc index 544d2ffbf..c3f0f8c8f 100644 --- a/src/libfetchers/git.cc +++ b/src/libfetchers/git.cc @@ -172,7 +172,7 @@ struct GitInputScheme : InputScheme return {isLocal, isLocal ? url.path : url.base}; } - std::pair<Tree, Input> fetch(ref<Store> store, const Input & _input) override + std::pair<StorePath, Input> fetch(ref<Store> store, const Input & _input) override { Input input(_input); @@ -197,17 +197,14 @@ struct GitInputScheme : InputScheme }; auto makeResult = [&](const Attrs & infoAttrs, StorePath && storePath) - -> std::pair<Tree, Input> + -> std::pair<StorePath, Input> { assert(input.getRev()); assert(!_input.getRev() || _input.getRev() == input.getRev()); if (!shallow) input.attrs.insert_or_assign("revCount", getIntAttr(infoAttrs, "revCount")); input.attrs.insert_or_assign("lastModified", getIntAttr(infoAttrs, "lastModified")); - return { - Tree(store->toRealPath(storePath), std::move(storePath)), - input - }; + return {std::move(storePath), input}; }; if (input.getRev()) { @@ -285,10 +282,7 @@ struct GitInputScheme : InputScheme "lastModified", haveCommits ? std::stoull(runProgram("git", true, { "-C", actualUrl, "log", "-1", "--format=%ct", "--no-show-signature", "HEAD" })) : 0); - return { - Tree(store->toRealPath(storePath), std::move(storePath)), - input - }; + return {std::move(storePath), input}; } } diff --git a/src/libfetchers/github.cc b/src/libfetchers/github.cc index 1c539b80e..8ba6935f9 100644 --- a/src/libfetchers/github.cc +++ b/src/libfetchers/github.cc @@ -180,7 +180,7 @@ struct GitArchiveInputScheme : InputScheme virtual DownloadUrl getDownloadUrl(const Input & input) const = 0; - std::pair<Tree, Input> fetch(ref<Store> store, const Input & _input) override + std::pair<StorePath, Input> fetch(ref<Store> store, const Input & _input) override { Input input(_input); @@ -199,10 +199,7 @@ struct GitArchiveInputScheme : InputScheme if (auto res = getCache()->lookup(store, immutableAttrs)) { input.attrs.insert_or_assign("lastModified", getIntAttr(res->first, "lastModified")); - return { - Tree(store->toRealPath(res->second), std::move(res->second)), - input - }; + return {std::move(res->second), input}; } auto url = getDownloadUrl(input); @@ -221,7 +218,7 @@ struct GitArchiveInputScheme : InputScheme tree.storePath, true); - return {std::move(tree), input}; + return {std::move(tree.storePath), input}; } }; diff --git a/src/libfetchers/indirect.cc b/src/libfetchers/indirect.cc index 10e59919a..9288fc6cf 100644 --- a/src/libfetchers/indirect.cc +++ b/src/libfetchers/indirect.cc @@ -94,7 +94,7 @@ struct IndirectInputScheme : InputScheme return input; } - std::pair<Tree, Input> fetch(ref<Store> store, const Input & input) override + std::pair<StorePath, Input> fetch(ref<Store> store, const Input & input) override { 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 d52d4641b..5123bcda4 100644 --- a/src/libfetchers/mercurial.cc +++ b/src/libfetchers/mercurial.cc @@ -143,7 +143,7 @@ struct MercurialInputScheme : InputScheme return {isLocal, isLocal ? url.path : url.base}; } - std::pair<Tree, Input> fetch(ref<Store> store, const Input & _input) override + std::pair<StorePath, Input> fetch(ref<Store> store, const Input & _input) override { Input input(_input); @@ -193,10 +193,7 @@ struct MercurialInputScheme : InputScheme auto storePath = store->addToStore(input.getName(), actualUrl, FileIngestionMethod::Recursive, htSHA256, filter); - return { - Tree(store->toRealPath(storePath), std::move(storePath)), - input - }; + return {std::move(storePath), input}; } } @@ -212,15 +209,12 @@ struct MercurialInputScheme : InputScheme }; auto makeResult = [&](const Attrs & infoAttrs, StorePath && storePath) - -> std::pair<Tree, Input> + -> std::pair<StorePath, Input> { assert(input.getRev()); assert(!_input.getRev() || _input.getRev() == input.getRev()); input.attrs.insert_or_assign("revCount", getIntAttr(infoAttrs, "revCount")); - return { - Tree(store->toRealPath(storePath), std::move(storePath)), - input - }; + return {std::move(storePath), input}; }; if (input.getRev()) { diff --git a/src/libfetchers/path.cc b/src/libfetchers/path.cc index 07e543c53..59e228e97 100644 --- a/src/libfetchers/path.cc +++ b/src/libfetchers/path.cc @@ -80,7 +80,7 @@ struct PathInputScheme : InputScheme // nothing to do } - std::pair<Tree, Input> fetch(ref<Store> store, const Input & input) override + std::pair<StorePath, Input> fetch(ref<Store> store, const Input & input) override { std::string absPath; auto path = getStrAttr(input.attrs, "path"); @@ -115,10 +115,7 @@ struct PathInputScheme : InputScheme // FIXME: try to substitute storePath. storePath = store->addToStore("source", absPath); - return { - Tree(store->toRealPath(*storePath), std::move(*storePath)), - input - }; + return {std::move(*storePath), input}; } }; diff --git a/src/libfetchers/tarball.cc b/src/libfetchers/tarball.cc index c933475ca..74c8097ff 100644 --- a/src/libfetchers/tarball.cc +++ b/src/libfetchers/tarball.cc @@ -126,7 +126,7 @@ std::pair<Tree, time_t> downloadTarball( if (cached && !cached->expired) return { - Tree(store->toRealPath(cached->storePath), std::move(cached->storePath)), + Tree { .actualPath = store->toRealPath(cached->storePath), .storePath = std::move(cached->storePath) }, getIntAttr(cached->infoAttrs, "lastModified") }; @@ -163,7 +163,7 @@ std::pair<Tree, time_t> downloadTarball( immutable); return { - Tree(store->toRealPath(*unpackedStorePath), std::move(*unpackedStorePath)), + Tree { .actualPath = store->toRealPath(*unpackedStorePath), .storePath = std::move(*unpackedStorePath) }, lastModified, }; } @@ -225,10 +225,10 @@ struct TarballInputScheme : InputScheme return true; } - std::pair<Tree, Input> fetch(ref<Store> store, const Input & input) override + std::pair<StorePath, Input> fetch(ref<Store> store, const Input & input) override { auto tree = downloadTarball(store, getStrAttr(input.attrs, "url"), input.getName(), false).first; - return {std::move(tree), input}; + return {std::move(tree.storePath), input}; } }; |