diff --git a/src/libcmd/common-eval-args.cc b/src/libcmd/common-eval-args.cc index 263792ec9..0a4b7d114 100644 --- a/src/libcmd/common-eval-args.cc +++ b/src/libcmd/common-eval-args.cc @@ -93,7 +93,7 @@ SourcePath lookupFileArg(EvalState & state, std::string_view s) { if (isUri(s)) { auto storePath = fetchers::downloadTarball( - state.store, resolveUri(s), "source", false).first.storePath; + state.store, resolveUri(s), "source", false).first; auto accessor = makeFSInputAccessor(CanonPath(state.store->toRealPath(storePath))); state.registerAccessor(accessor); return {accessor, CanonPath::root}; diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y index 96ee42528..71228743b 100644 --- a/src/libexpr/parser.y +++ b/src/libexpr/parser.y @@ -790,7 +790,7 @@ SourcePath EvalState::findFile(SearchPath & searchPath, const std::string_view p if (isUri(elem.second)) { try { auto storePath = fetchers::downloadTarball( - store, resolveUri(elem.second), "source", false).first.storePath; + store, resolveUri(elem.second), "source", false).first; auto accessor = makeFSInputAccessor(CanonPath(store->toRealPath(storePath))); registerAccessor(accessor); res.emplace(SourcePath {accessor, CanonPath::root}); diff --git a/src/libexpr/primops/fetchMercurial.cc b/src/libexpr/primops/fetchMercurial.cc index 249c0934e..e8111298a 100644 --- a/src/libexpr/primops/fetchMercurial.cc +++ b/src/libexpr/primops/fetchMercurial.cc @@ -68,11 +68,11 @@ static void prim_fetchMercurial(EvalState & state, const PosIdx pos, Value * * a auto input = fetchers::Input::fromAttrs(std::move(attrs)); // FIXME: use name - auto [tree, input2] = input.fetch(state.store); + auto [storePath, input2] = input.fetch(state.store); auto attrs2 = state.buildBindings(8); - auto storePath = state.store->printStorePath(tree.storePath); - attrs2.alloc(state.sOutPath).mkString(storePath, {storePath}); + auto storePath2 = state.store->printStorePath(storePath); + attrs2.alloc(state.sOutPath).mkString(storePath2, {storePath2}); if (input2.getRef()) attrs2.alloc("branch").mkString(*input2.getRef()); // Backward compatibility: set 'rev' to @@ -84,7 +84,7 @@ static void prim_fetchMercurial(EvalState & state, const PosIdx pos, Value * * a attrs2.alloc("revCount").mkInt(*revCount); v.mkAttrs(attrs2); - state.allowPath(tree.storePath); + state.allowPath(storePath); } static RegisterPrimOp r_fetchMercurial("fetchMercurial", 1, prim_fetchMercurial); diff --git a/src/libexpr/primops/fetchTree.cc b/src/libexpr/primops/fetchTree.cc index 0fc3a809c..be0fa7425 100644 --- a/src/libexpr/primops/fetchTree.cc +++ b/src/libexpr/primops/fetchTree.cc @@ -196,19 +196,19 @@ static void fetchTree( params.emptyRevFallback, false); } else { - auto [tree, input2] = input.fetch(state.store); + auto [storePath, input2] = input.fetch(state.store); - auto storePath = state.store->printStorePath(tree.storePath); + auto storePath2 = state.store->printStorePath(storePath); emitTreeAttrs( state, input2, v, [&](Value & vOutPath) { - vOutPath.mkString(storePath, {storePath}); + vOutPath.mkString(storePath2, {storePath2}); }, params.emptyRevFallback, false); - state.allowPath(tree.storePath); + state.allowPath(storePath); } } @@ -283,7 +283,7 @@ static void fetch(EvalState & state, const PosIdx pos, Value * * args, Value & v // https://github.com/NixOS/nix/issues/4313 auto storePath = unpack - ? fetchers::downloadTarball(state.store, *url, name, (bool) expectedHash).first.storePath + ? fetchers::downloadTarball(state.store, *url, name, (bool) expectedHash).first : fetchers::downloadFile(state.store, *url, name, (bool) expectedHash).storePath; if (expectedHash) { diff --git a/src/libfetchers/fetchers.cc b/src/libfetchers/fetchers.cc index f1d64c992..951864314 100644 --- a/src/libfetchers/fetchers.cc +++ b/src/libfetchers/fetchers.cc @@ -112,7 +112,7 @@ bool Input::contains(const Input & other) const return false; } -std::pair Input::fetch(ref store) const +std::pair Input::fetch(ref store) const { if (!scheme) throw Error("cannot fetch unsupported input '%s'", attrsToJSON(toAttrs())); @@ -129,7 +129,7 @@ std::pair Input::fetch(ref store) const debug("using substituted/cached input '%s' in '%s'", to_string(), store->printStorePath(storePath)); - return {Tree { .actualPath = store->toRealPath(storePath), .storePath = std::move(storePath) }, *this}; + return {std::move(storePath), *this}; } catch (Error & e) { debug("substitution of input '%s' failed: %s", to_string(), e.what()); } @@ -144,14 +144,9 @@ std::pair Input::fetch(ref store) const } }(); - Tree tree { - .actualPath = store->toRealPath(storePath), - .storePath = storePath, - }; - checkLocked(*store, storePath, input); - return {std::move(tree), input}; + return {std::move(storePath), input}; } void Input::checkLocked(Store & store, const StorePath & storePath, Input & input) const diff --git a/src/libfetchers/fetchers.hh b/src/libfetchers/fetchers.hh index e6792d81d..1affe8f5e 100644 --- a/src/libfetchers/fetchers.hh +++ b/src/libfetchers/fetchers.hh @@ -13,12 +13,6 @@ namespace nix { class Store; } namespace nix::fetchers { -struct Tree -{ - Path actualPath; - StorePath storePath; -}; - struct InputScheme; /* The Input object is generated by a specific fetcher, based on the @@ -70,7 +64,7 @@ public: /* Fetch the input into the Nix store, returning the location in the Nix store and the locked input. */ - std::pair fetch(ref store) const; + std::pair fetch(ref store) const; /* Return an InputAccessor that allows access to files in the input without copying it to the store. Also return a possibly @@ -178,7 +172,7 @@ DownloadFileResult downloadFile( bool locked, const Headers & headers = {}); -std::pair downloadTarball( +std::pair downloadTarball( ref store, const std::string & url, const std::string & name, diff --git a/src/libfetchers/tarball.cc b/src/libfetchers/tarball.cc index 9489b9ca9..e96de316e 100644 --- a/src/libfetchers/tarball.cc +++ b/src/libfetchers/tarball.cc @@ -110,7 +110,7 @@ DownloadFileResult downloadFile( }; } -std::pair downloadTarball( +std::pair downloadTarball( ref store, const std::string & url, const std::string & name, @@ -127,7 +127,7 @@ std::pair downloadTarball( if (cached && !cached->expired) return { - Tree { .actualPath = store->toRealPath(cached->storePath), .storePath = std::move(cached->storePath) }, + std::move(cached->storePath), getIntAttr(cached->infoAttrs, "lastModified") }; @@ -164,7 +164,7 @@ std::pair downloadTarball( locked); return { - Tree { .actualPath = store->toRealPath(*unpackedStorePath), .storePath = std::move(*unpackedStorePath) }, + std::move(*unpackedStorePath), lastModified, }; } @@ -273,8 +273,10 @@ struct TarballInputScheme : CurlInputScheme std::pair fetch(ref store, const Input & input) override { - auto tree = downloadTarball(store, getStrAttr(input.attrs, "url"), input.getName(), false).first; - return {std::move(tree.storePath), input}; + return { + downloadTarball(store, getStrAttr(input.attrs, "url"), input.getName(), false).first, + input + }; } };