mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-24 14:56:15 +02:00
Remove Tree datatype
This commit is contained in:
parent
e7faf65784
commit
4f8f52ae58
7 changed files with 23 additions and 32 deletions
|
@ -93,7 +93,7 @@ SourcePath lookupFileArg(EvalState & state, std::string_view s)
|
||||||
{
|
{
|
||||||
if (isUri(s)) {
|
if (isUri(s)) {
|
||||||
auto storePath = fetchers::downloadTarball(
|
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)));
|
auto accessor = makeFSInputAccessor(CanonPath(state.store->toRealPath(storePath)));
|
||||||
state.registerAccessor(accessor);
|
state.registerAccessor(accessor);
|
||||||
return {accessor, CanonPath::root};
|
return {accessor, CanonPath::root};
|
||||||
|
|
|
@ -790,7 +790,7 @@ SourcePath EvalState::findFile(SearchPath & searchPath, const std::string_view p
|
||||||
if (isUri(elem.second)) {
|
if (isUri(elem.second)) {
|
||||||
try {
|
try {
|
||||||
auto storePath = fetchers::downloadTarball(
|
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)));
|
auto accessor = makeFSInputAccessor(CanonPath(store->toRealPath(storePath)));
|
||||||
registerAccessor(accessor);
|
registerAccessor(accessor);
|
||||||
res.emplace(SourcePath {accessor, CanonPath::root});
|
res.emplace(SourcePath {accessor, CanonPath::root});
|
||||||
|
|
|
@ -68,11 +68,11 @@ static void prim_fetchMercurial(EvalState & state, const PosIdx pos, Value * * a
|
||||||
auto input = fetchers::Input::fromAttrs(std::move(attrs));
|
auto input = fetchers::Input::fromAttrs(std::move(attrs));
|
||||||
|
|
||||||
// FIXME: use name
|
// FIXME: use name
|
||||||
auto [tree, input2] = input.fetch(state.store);
|
auto [storePath, input2] = input.fetch(state.store);
|
||||||
|
|
||||||
auto attrs2 = state.buildBindings(8);
|
auto attrs2 = state.buildBindings(8);
|
||||||
auto storePath = state.store->printStorePath(tree.storePath);
|
auto storePath2 = state.store->printStorePath(storePath);
|
||||||
attrs2.alloc(state.sOutPath).mkString(storePath, {storePath});
|
attrs2.alloc(state.sOutPath).mkString(storePath2, {storePath2});
|
||||||
if (input2.getRef())
|
if (input2.getRef())
|
||||||
attrs2.alloc("branch").mkString(*input2.getRef());
|
attrs2.alloc("branch").mkString(*input2.getRef());
|
||||||
// Backward compatibility: set 'rev' to
|
// 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);
|
attrs2.alloc("revCount").mkInt(*revCount);
|
||||||
v.mkAttrs(attrs2);
|
v.mkAttrs(attrs2);
|
||||||
|
|
||||||
state.allowPath(tree.storePath);
|
state.allowPath(storePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
static RegisterPrimOp r_fetchMercurial("fetchMercurial", 1, prim_fetchMercurial);
|
static RegisterPrimOp r_fetchMercurial("fetchMercurial", 1, prim_fetchMercurial);
|
||||||
|
|
|
@ -196,19 +196,19 @@ static void fetchTree(
|
||||||
params.emptyRevFallback,
|
params.emptyRevFallback,
|
||||||
false);
|
false);
|
||||||
} else {
|
} 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(
|
emitTreeAttrs(
|
||||||
state, input2, v,
|
state, input2, v,
|
||||||
[&](Value & vOutPath) {
|
[&](Value & vOutPath) {
|
||||||
vOutPath.mkString(storePath, {storePath});
|
vOutPath.mkString(storePath2, {storePath2});
|
||||||
},
|
},
|
||||||
params.emptyRevFallback,
|
params.emptyRevFallback,
|
||||||
false);
|
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
|
// https://github.com/NixOS/nix/issues/4313
|
||||||
auto storePath =
|
auto storePath =
|
||||||
unpack
|
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;
|
: fetchers::downloadFile(state.store, *url, name, (bool) expectedHash).storePath;
|
||||||
|
|
||||||
if (expectedHash) {
|
if (expectedHash) {
|
||||||
|
|
|
@ -112,7 +112,7 @@ bool Input::contains(const Input & other) const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<Tree, Input> Input::fetch(ref<Store> store) const
|
std::pair<StorePath, Input> Input::fetch(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()));
|
||||||
|
@ -129,7 +129,7 @@ std::pair<Tree, Input> Input::fetch(ref<Store> store) const
|
||||||
debug("using substituted/cached input '%s' in '%s'",
|
debug("using substituted/cached input '%s' in '%s'",
|
||||||
to_string(), store->printStorePath(storePath));
|
to_string(), store->printStorePath(storePath));
|
||||||
|
|
||||||
return {Tree { .actualPath = store->toRealPath(storePath), .storePath = std::move(storePath) }, *this};
|
return {std::move(storePath), *this};
|
||||||
} catch (Error & e) {
|
} catch (Error & e) {
|
||||||
debug("substitution of input '%s' failed: %s", to_string(), e.what());
|
debug("substitution of input '%s' failed: %s", to_string(), e.what());
|
||||||
}
|
}
|
||||||
|
@ -144,14 +144,9 @@ std::pair<Tree, Input> Input::fetch(ref<Store> store) const
|
||||||
}
|
}
|
||||||
}();
|
}();
|
||||||
|
|
||||||
Tree tree {
|
|
||||||
.actualPath = store->toRealPath(storePath),
|
|
||||||
.storePath = storePath,
|
|
||||||
};
|
|
||||||
|
|
||||||
checkLocked(*store, storePath, input);
|
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
|
void Input::checkLocked(Store & store, const StorePath & storePath, Input & input) const
|
||||||
|
|
|
@ -13,12 +13,6 @@ namespace nix { class Store; }
|
||||||
|
|
||||||
namespace nix::fetchers {
|
namespace nix::fetchers {
|
||||||
|
|
||||||
struct Tree
|
|
||||||
{
|
|
||||||
Path actualPath;
|
|
||||||
StorePath storePath;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct InputScheme;
|
struct InputScheme;
|
||||||
|
|
||||||
/* The Input object is generated by a specific fetcher, based on the
|
/* 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
|
/* Fetch the input into the Nix store, returning the location in
|
||||||
the Nix store and the locked input. */
|
the Nix store and the locked input. */
|
||||||
std::pair<Tree, Input> fetch(ref<Store> store) const;
|
std::pair<StorePath, Input> fetch(ref<Store> store) const;
|
||||||
|
|
||||||
/* 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
|
||||||
|
@ -178,7 +172,7 @@ DownloadFileResult downloadFile(
|
||||||
bool locked,
|
bool locked,
|
||||||
const Headers & headers = {});
|
const Headers & headers = {});
|
||||||
|
|
||||||
std::pair<Tree, time_t> downloadTarball(
|
std::pair<StorePath, time_t> downloadTarball(
|
||||||
ref<Store> store,
|
ref<Store> store,
|
||||||
const std::string & url,
|
const std::string & url,
|
||||||
const std::string & name,
|
const std::string & name,
|
||||||
|
|
|
@ -110,7 +110,7 @@ DownloadFileResult downloadFile(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<Tree, time_t> downloadTarball(
|
std::pair<StorePath, time_t> downloadTarball(
|
||||||
ref<Store> store,
|
ref<Store> store,
|
||||||
const std::string & url,
|
const std::string & url,
|
||||||
const std::string & name,
|
const std::string & name,
|
||||||
|
@ -127,7 +127,7 @@ std::pair<Tree, time_t> downloadTarball(
|
||||||
|
|
||||||
if (cached && !cached->expired)
|
if (cached && !cached->expired)
|
||||||
return {
|
return {
|
||||||
Tree { .actualPath = store->toRealPath(cached->storePath), .storePath = std::move(cached->storePath) },
|
std::move(cached->storePath),
|
||||||
getIntAttr(cached->infoAttrs, "lastModified")
|
getIntAttr(cached->infoAttrs, "lastModified")
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -164,7 +164,7 @@ std::pair<Tree, time_t> downloadTarball(
|
||||||
locked);
|
locked);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
Tree { .actualPath = store->toRealPath(*unpackedStorePath), .storePath = std::move(*unpackedStorePath) },
|
std::move(*unpackedStorePath),
|
||||||
lastModified,
|
lastModified,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -273,8 +273,10 @@ struct TarballInputScheme : CurlInputScheme
|
||||||
|
|
||||||
std::pair<StorePath, 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 {
|
||||||
return {std::move(tree.storePath), input};
|
downloadTarball(store, getStrAttr(input.attrs, "url"), input.getName(), false).first,
|
||||||
|
input
|
||||||
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue