libstore: asyncify LocalFSStore::addPermRoot
Change-Id: I0e19470e7fcc3d563b26c078c1dc831dbc5cf422
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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 : ""));
|
||||
}
|
||||
|
||||
@@ -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
@@ -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));
|
||||
|
||||
@@ -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
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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; }
|
||||
|
||||
|
||||
@@ -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
@@ -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
@@ -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))
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user