From 614a63b49abc5eff988bc95658160ddd6ab867e5 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Wed, 5 Feb 2025 14:47:25 +0100 Subject: [PATCH] libstore: asyncify createGeneration Change-Id: Iae47a0f732b2f0fe54525917c091169f4be2214e --- lix/legacy/nix-env.cc | 4 ++-- lix/legacy/user-env.cc | 2 +- lix/libcmd/command.cc | 2 +- lix/libstore/profiles.cc | 10 ++++++---- lix/libstore/profiles.hh | 2 +- lix/nix/upgrade-nix.cc | 3 ++- 6 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lix/legacy/nix-env.cc b/lix/legacy/nix-env.cc index 48bdf98ca..77dba64c6 100644 --- a/lix/legacy/nix-env.cc +++ b/lix/legacy/nix-env.cc @@ -795,10 +795,10 @@ static void opSet(Globals & globals, Strings opFlags, Strings opArgs) ); debug("switching to new user environment"); - Path generation = createGeneration( + Path generation = globals.aio.blockOn(createGeneration( *store2, globals.profile, - drv.queryOutPath(*state)); + drv.queryOutPath(*state))); switchLink(globals.profile, generation); } diff --git a/lix/legacy/user-env.cc b/lix/legacy/user-env.cc index 88cfec6fe..17e47ad99 100644 --- a/lix/legacy/user-env.cc +++ b/lix/legacy/user-env.cc @@ -142,7 +142,7 @@ bool createUserEnv(EvalState & state, DrvInfos & elems, } debug("switching to new user environment"); - Path generation = createGeneration(*store2, profile, topLevelOut); + Path generation = state.aio.blockOn(createGeneration(*store2, profile, topLevelOut)); switchLink(profile, generation); } diff --git a/lix/libcmd/command.cc b/lix/libcmd/command.cc index 9a5cba6c8..4cdb5517a 100644 --- a/lix/libcmd/command.cc +++ b/lix/libcmd/command.cc @@ -231,7 +231,7 @@ void MixProfile::updateProfile(const StorePath & storePath) if (!store) throw Error("'--profile' is not supported for this Nix store"); auto profile2 = absPath(*profile); switchLink(profile2, - createGeneration(*store, profile2, storePath)); + aio().blockOn(createGeneration(*store, profile2, storePath))); } void MixProfile::updateProfile(const BuiltPaths & buildables) diff --git a/lix/libstore/profiles.cc b/lix/libstore/profiles.cc index 95f146a4a..675b46bbf 100644 --- a/lix/libstore/profiles.cc +++ b/lix/libstore/profiles.cc @@ -70,8 +70,8 @@ static Path makeName(const Path & profile, GenerationNumber num) } -Path createGeneration(LocalFSStore & store, Path profile, StorePath outPath) -{ +kj::Promise> createGeneration(LocalFSStore & store, Path profile, StorePath outPath) +try { /* The new generation number should be higher than old the previous ones. */ auto [gens, dummy] = findGenerations(profile); @@ -87,7 +87,7 @@ Path createGeneration(LocalFSStore & store, Path profile, StorePath outPath) This helps keeping gratuitous installs/rebuilds from piling up uncontrolled numbers of generations, cluttering up the UI like grub. */ - return last.path; + co_return last.path; } num = last.number; @@ -104,7 +104,9 @@ Path createGeneration(LocalFSStore & store, Path profile, StorePath outPath) Path generation = makeName(profile, num + 1); store.addPermRoot(outPath, generation); - return generation; + co_return generation; +} catch (...) { + co_return result::current_exception(); } diff --git a/lix/libstore/profiles.hh b/lix/libstore/profiles.hh index bdf6d3b70..0dbe92fad 100644 --- a/lix/libstore/profiles.hh +++ b/lix/libstore/profiles.hh @@ -96,7 +96,7 @@ class LocalFSStore; * The behavior of reusing existing generations like this makes this * procedure idempotent. It also avoids clutter. */ -Path createGeneration(LocalFSStore & store, Path profile, StorePath outPath); +kj::Promise> createGeneration(LocalFSStore & store, Path profile, StorePath outPath); /** * Unconditionally delete a generation diff --git a/lix/nix/upgrade-nix.cc b/lix/nix/upgrade-nix.cc index ae01a50db..8875061f0 100644 --- a/lix/nix/upgrade-nix.cc +++ b/lix/nix/upgrade-nix.cc @@ -257,7 +257,8 @@ struct CmdUpgradeNix : MixDryRun, EvalCommand // Build the new profile, and switch to it. StorePath const newProfile = manifest.build(store); printTalkative("built new profile '%s'", store->printStorePath(newProfile)); - auto const newGeneration = createGeneration(*fsStore, this->profileDir, newProfile); + auto const newGeneration = + aio().blockOn(createGeneration(*fsStore, this->profileDir, newProfile)); printTalkative( "switching '%s' to newly created generation '%s'", this->profileDir,