Make getDstStore() a virtual method in StoreCommand

This commit is contained in:
Eelco Dolstra 2024-10-08 15:36:21 +02:00
parent 76f75e7691
commit 43ad8c5eb2
6 changed files with 26 additions and 21 deletions

View File

@ -246,21 +246,17 @@ MixProfile::MixProfile()
}); });
} }
void MixProfile::updateProfile( void MixProfile::updateProfile(const StorePath & storePath)
const StorePath & storePath,
ref<Store> store_)
{ {
if (!profile) return; if (!profile) return;
auto store = store_.dynamic_pointer_cast<LocalFSStore>(); auto store = getDstStore().dynamic_pointer_cast<LocalFSStore>();
if (!store) throw Error("'--profile' is not supported for this Nix store"); if (!store) throw Error("'--profile' is not supported for this Nix store");
auto profile2 = absPath(*profile); auto profile2 = absPath(*profile);
switchLink(profile2, switchLink(profile2,
createGeneration(*store, profile2, storePath)); createGeneration(*store, profile2, storePath));
} }
void MixProfile::updateProfile( void MixProfile::updateProfile(const BuiltPaths & buildables)
const BuiltPaths & buildables,
ref<Store> store)
{ {
if (!profile) return; if (!profile) return;
@ -282,7 +278,7 @@ void MixProfile::updateProfile(
if (result.size() != 1) if (result.size() != 1)
throw UsageError("'--profile' requires that the arguments produce a single store path, but there are %d", result.size()); throw UsageError("'--profile' requires that the arguments produce a single store path, but there are %d", result.size());
updateProfile(result[0], store); updateProfile(result[0]);
} }
MixDefaultProfile::MixDefaultProfile() MixDefaultProfile::MixDefaultProfile()

View File

@ -45,7 +45,20 @@ struct StoreCommand : virtual Command
{ {
StoreCommand(); StoreCommand();
void run() override; void run() override;
/**
* Return the default Nix store.
*/
ref<Store> getStore(); ref<Store> getStore();
/**
* Return the destination Nix store.
*/
virtual ref<Store> getDstStore()
{
return getStore();
}
virtual ref<Store> createStore(); virtual ref<Store> createStore();
/** /**
* Main entry point, with a `Store` provided * Main entry point, with a `Store` provided
@ -68,7 +81,7 @@ struct CopyCommand : virtual StoreCommand
ref<Store> createStore() override; ref<Store> createStore() override;
ref<Store> getDstStore(); ref<Store> getDstStore() override;
}; };
/** /**
@ -301,15 +314,11 @@ struct MixProfile : virtual StoreCommand
MixProfile(); MixProfile();
/* If 'profile' is set, make it point at 'storePath'. */ /* If 'profile' is set, make it point at 'storePath'. */
void updateProfile( void updateProfile(const StorePath & storePath);
const StorePath & storePath,
ref<Store> store);
/* If 'profile' is set, make it point at the store path produced /* If 'profile' is set, make it point at the store path produced
by 'buildables'. */ by 'buildables'. */
void updateProfile( void updateProfile(const BuiltPaths & buildables);
const BuiltPaths & buildables,
ref<Store> store);
}; };
struct MixDefaultProfile : MixProfile struct MixDefaultProfile : MixProfile

View File

@ -161,7 +161,7 @@ struct CmdBuild : InstallablesCommand, MixDryRun, MixJSON, MixProfile
BuiltPaths buildables2; BuiltPaths buildables2;
for (auto & b : buildables) for (auto & b : buildables)
buildables2.push_back(b.path); buildables2.push_back(b.path);
updateProfile(buildables2, store); updateProfile(buildables2);
} }
}; };

View File

@ -57,7 +57,7 @@ struct CmdCopy : virtual CopyCommand, virtual BuiltPathsCommand, MixProfile
copyPaths( copyPaths(
*srcStore, *dstStore, stuffToCopy, NoRepair, checkSigs, substitute); *srcStore, *dstStore, stuffToCopy, NoRepair, checkSigs, substitute);
updateProfile(rootPaths, dstStore); updateProfile(rootPaths);
} }
}; };

View File

@ -502,7 +502,7 @@ struct Common : InstallableCommand, MixProfile
auto strPath = store->printStorePath(shellOutPath); auto strPath = store->printStorePath(shellOutPath);
updateProfile(shellOutPath, store); updateProfile(shellOutPath);
debug("reading environment file '%s'", strPath); debug("reading environment file '%s'", strPath);

View File

@ -424,7 +424,7 @@ struct CmdProfileInstall : InstallablesCommand, MixDefaultProfile
} }
try { try {
updateProfile(manifest.build(store), store); updateProfile(manifest.build(store));
} catch (BuildEnvFileConflictError & conflictError) { } catch (BuildEnvFileConflictError & conflictError) {
// FIXME use C++20 std::ranges once macOS has it // FIXME use C++20 std::ranges once macOS has it
// See https://github.com/NixOS/nix/compare/3efa476c5439f8f6c1968a6ba20a31d1239c2f04..1fe5d172ece51a619e879c4b86f603d9495cc102 // See https://github.com/NixOS/nix/compare/3efa476c5439f8f6c1968a6ba20a31d1239c2f04..1fe5d172ece51a619e879c4b86f603d9495cc102
@ -669,7 +669,7 @@ struct CmdProfileRemove : virtual EvalCommand, MixDefaultProfile, MixProfileElem
removedCount, removedCount,
newManifest.elements.size()); newManifest.elements.size());
updateProfile(newManifest.build(store), store); updateProfile(newManifest.build(store));
} }
}; };
@ -779,7 +779,7 @@ struct CmdProfileUpgrade : virtual SourceExprCommand, MixDefaultProfile, MixProf
builtPaths.find(&*installable)->second.first); builtPaths.find(&*installable)->second.first);
} }
updateProfile(manifest.build(store), store); updateProfile(manifest.build(store));
} }
}; };