libstore: asyncify LocalFSStore::addPermRoot

Change-Id: I0e19470e7fcc3d563b26c078c1dc831dbc5cf422
This commit is contained in:
eldritch horrors
2025-02-08 17:26:19 +00:00
parent 614a63b49a
commit 60f391ef3d
11 changed files with 34 additions and 18 deletions
+1 -1
View File
@@ -612,7 +612,7 @@ static void main_nix_build(AsyncIoRoot & aio, std::string programName, Strings a
if (auto store2 = store.dynamic_pointer_cast<LocalFSStore>()) {
std::string symlink = drvPrefix;
if (outputName != "out") symlink += "-" + outputName;
store2->addPermRoot(outputPath, absPath(symlink));
aio.blockOn(store2->addPermRoot(outputPath, absPath(symlink)));
}
outPaths.push_back(outputPath);
+1 -1
View File
@@ -80,7 +80,7 @@ void processExpr(EvalState & state, const Strings & attrPaths,
if (++rootNr > 1) rootName += "-" + std::to_string(rootNr);
auto store2 = state.ctx.store.dynamic_pointer_cast<LocalFSStore>();
if (store2)
drvPathS = store2->addPermRoot(drvPath, rootName);
drvPathS = state.aio.blockOn(store2->addPermRoot(drvPath, rootName));
}
std::cout << fmt("%s%s\n", drvPathS, (outputName != "out" ? "!" + outputName : ""));
}
+2 -2
View File
@@ -92,7 +92,7 @@ try {
Path rootName = gcRoot;
if (rootNr > 1) rootName += "-" + std::to_string(rootNr);
if (i->first != "out") rootName += "-" + i->first;
retPath = store2->addPermRoot(outPath, rootName);
retPath = TRY_AWAIT(store2->addPermRoot(outPath, rootName));
}
}
outputs.insert(retPath);
@@ -111,7 +111,7 @@ try {
Path rootName = gcRoot;
rootNr++;
if (rootNr > 1) rootName += "-" + std::to_string(rootNr);
co_return PathSet{store2->addPermRoot(path.path, rootName)};
co_return PathSet{TRY_AWAIT(store2->addPermRoot(path.path, rootName))};
}
}
co_return PathSet{store->printStorePath(path.path)};
+1 -1
View File
@@ -782,7 +782,7 @@ ProcessLineResult NixRepl::processLine(std::string line)
auto localStore = evaluator.store.dynamic_pointer_cast<LocalFSStore>();
if (localStore && command == ":bl") {
std::string symlink = "repl-result-" + outputName;
localStore->addPermRoot(outputPath, absPath(symlink));
state.aio.blockOn(localStore->addPermRoot(outputPath, absPath(symlink)));
logger->cout(" ./%s -> %s", symlink, evaluator.store->printStorePath(outputPath));
} else {
logger->cout(" %s -> %s", outputName, evaluator.store->printStorePath(outputPath));
+5 -2
View File
@@ -184,8 +184,11 @@ try {
);
auto storePath = downloadFile(store, path, "flake-registry.json", false).storePath;
if (auto store2 = store.dynamic_pointer_cast<LocalFSStore>())
store2->addPermRoot(storePath, getCacheDir() + "/nix/flake-registry.json");
if (auto store2 = store.dynamic_pointer_cast<LocalFSStore>()) {
TRY_AWAIT(
store2->addPermRoot(storePath, getCacheDir() + "/nix/flake-registry.json")
);
}
path = store->toRealPath(storePath);
}
+5 -3
View File
@@ -51,8 +51,8 @@ void LocalStore::addIndirectRoot(const Path & path)
}
Path IndirectRootStore::addPermRoot(const StorePath & storePath, const Path & _gcRoot)
{
kj::Promise<Result<Path>> IndirectRootStore::addPermRoot(const StorePath & storePath, const Path & _gcRoot)
try {
Path gcRoot(canonPath(_gcRoot));
if (isInStore(gcRoot))
@@ -73,7 +73,9 @@ Path IndirectRootStore::addPermRoot(const StorePath & storePath, const Path & _g
makeSymlink(gcRoot, printStorePath(storePath));
addIndirectRoot(gcRoot);
return gcRoot;
co_return gcRoot;
} catch (...) {
co_return result::current_exception();
}
+2 -1
View File
@@ -31,7 +31,8 @@ struct IndirectRootStore : public virtual LocalFSStore
* The implementation of this method is concrete, but it delegates
* to `addIndirectRoot()` which is abstract.
*/
Path addPermRoot(const StorePath & storePath, const Path & gcRoot) override final;
kj::Promise<Result<Path>>
addPermRoot(const StorePath & storePath, const Path & gcRoot) override final;
/**
* Add an indirect root, which is a weak reference to the
+2 -1
View File
@@ -59,7 +59,8 @@ public:
* How the permanent GC root corresponding to this symlink is
* managed is implementation-specific.
*/
virtual Path addPermRoot(const StorePath & storePath, const Path & gcRoot) = 0;
virtual kj::Promise<Result<Path>>
addPermRoot(const StorePath & storePath, const Path & gcRoot) = 0;
virtual Path getRealStoreDir() { return config().realStoreDir; }
+2 -1
View File
@@ -1,5 +1,6 @@
#include "lix/libstore/profiles.hh"
#include "lix/libstore/local-fs-store.hh"
#include "lix/libutil/async.hh"
#include "lix/libutil/users.hh"
#include "lix/libutil/strings.hh"
@@ -102,7 +103,7 @@ try {
view). If we didn't do it this way, the GC might remove the
user environment etc. we've just built. */
Path generation = makeName(profile, num + 1);
store.addPermRoot(outPath, generation);
TRY_AWAIT(store.addPermRoot(outPath, generation));
co_return generation;
} catch (...) {
+10 -4
View File
@@ -3,6 +3,7 @@
#include "lix/libmain/shared.hh"
#include "lix/libstore/store-api.hh"
#include "lix/libstore/local-fs-store.hh"
#include "lix/libutil/async.hh"
#include <nlohmann/json.hpp>
@@ -42,7 +43,12 @@ static nlohmann::json builtPathsWithResultToJSON(const std::vector<BuiltPathWith
}
// TODO deduplicate with other code also setting such out links.
static void createOutLinks(const Path& outLink, const std::vector<BuiltPathWithResult>& buildables, LocalFSStore& store2)
static void createOutLinks(
AsyncIoRoot & aio,
const Path & outLink,
const std::vector<BuiltPathWithResult> & buildables,
LocalFSStore & store2
)
{
for (const auto & [_i, buildable] : enumerate(buildables)) {
auto i = _i;
@@ -50,14 +56,14 @@ static void createOutLinks(const Path& outLink, const std::vector<BuiltPathWithR
[&](const BuiltPath::Opaque & bo) {
std::string symlink = outLink;
if (i) symlink += fmt("-%d", i);
store2.addPermRoot(bo.path, absPath(symlink));
aio.blockOn(store2.addPermRoot(bo.path, absPath(symlink)));
},
[&](const BuiltPath::Built & bfd) {
for (auto & output : bfd.outputs) {
std::string symlink = outLink;
if (i) symlink += fmt("-%d", i);
if (output.first != "out") symlink += fmt("-%s", output.first);
store2.addPermRoot(output.second, absPath(symlink));
aio.blockOn(store2.addPermRoot(output.second, absPath(symlink)));
}
},
}, buildable.path.raw());
@@ -141,7 +147,7 @@ struct CmdBuild : InstallablesCommand, MixDryRun, MixJSON, MixProfile
if (outLink != "")
if (auto store2 = store.dynamic_pointer_cast<LocalFSStore>())
createOutLinks(outLink, buildables, *store2);
createOutLinks(aio(), outLink, buildables, *store2);
if (printOutputPaths) {
logger->pause();
+3 -1
View File
@@ -125,7 +125,9 @@ struct CmdBundle : InstallableCommand
}
// TODO: will crash if not a localFSStore?
store.dynamic_pointer_cast<LocalFSStore>()->addPermRoot(outPath, absPath(*outLink));
aio().blockOn(
store.dynamic_pointer_cast<LocalFSStore>()->addPermRoot(outPath, absPath(*outLink))
);
}
};