Skip to content

Commit

Permalink
Make getDstStore() a virtual method in StoreCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
edolstra committed Oct 8, 2024
1 parent 76f75e7 commit 43ad8c5
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 21 deletions.
12 changes: 4 additions & 8 deletions src/libcmd/command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -246,21 +246,17 @@ MixProfile::MixProfile()
});
}

void MixProfile::updateProfile(
const StorePath & storePath,
ref<Store> store_)
void MixProfile::updateProfile(const StorePath & storePath)
{
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");
auto profile2 = absPath(*profile);
switchLink(profile2,
createGeneration(*store, profile2, storePath));
}

void MixProfile::updateProfile(
const BuiltPaths & buildables,
ref<Store> store)
void MixProfile::updateProfile(const BuiltPaths & buildables)
{
if (!profile) return;

Expand All @@ -282,7 +278,7 @@ void MixProfile::updateProfile(
if (result.size() != 1)
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()
Expand Down
23 changes: 16 additions & 7 deletions src/libcmd/command.hh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,20 @@ struct StoreCommand : virtual Command
{
StoreCommand();
void run() override;

/**
* Return the default Nix store.
*/
ref<Store> getStore();

/**
* Return the destination Nix store.
*/
virtual ref<Store> getDstStore()
{
return getStore();
}

virtual ref<Store> createStore();
/**
* Main entry point, with a `Store` provided
Expand All @@ -68,7 +81,7 @@ struct CopyCommand : virtual StoreCommand

ref<Store> createStore() override;

ref<Store> getDstStore();
ref<Store> getDstStore() override;
};

/**
Expand Down Expand Up @@ -301,15 +314,11 @@ struct MixProfile : virtual StoreCommand
MixProfile();

/* If 'profile' is set, make it point at 'storePath'. */
void updateProfile(
const StorePath & storePath,
ref<Store> store);
void updateProfile(const StorePath & storePath);

/* If 'profile' is set, make it point at the store path produced
by 'buildables'. */
void updateProfile(
const BuiltPaths & buildables,
ref<Store> store);
void updateProfile(const BuiltPaths & buildables);
};

struct MixDefaultProfile : MixProfile
Expand Down
2 changes: 1 addition & 1 deletion src/nix/build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ struct CmdBuild : InstallablesCommand, MixDryRun, MixJSON, MixProfile
BuiltPaths buildables2;
for (auto & b : buildables)
buildables2.push_back(b.path);
updateProfile(buildables2, store);
updateProfile(buildables2);
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/nix/copy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct CmdCopy : virtual CopyCommand, virtual BuiltPathsCommand, MixProfile
copyPaths(
*srcStore, *dstStore, stuffToCopy, NoRepair, checkSigs, substitute);

updateProfile(rootPaths, dstStore);
updateProfile(rootPaths);
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/nix/develop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ struct Common : InstallableCommand, MixProfile

auto strPath = store->printStorePath(shellOutPath);

updateProfile(shellOutPath, store);
updateProfile(shellOutPath);

debug("reading environment file '%s'", strPath);

Expand Down
6 changes: 3 additions & 3 deletions src/nix/profile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ struct CmdProfileInstall : InstallablesCommand, MixDefaultProfile
}

try {
updateProfile(manifest.build(store), store);
updateProfile(manifest.build(store));
} catch (BuildEnvFileConflictError & conflictError) {
// FIXME use C++20 std::ranges once macOS has it
// See https://github.com/NixOS/nix/compare/3efa476c5439f8f6c1968a6ba20a31d1239c2f04..1fe5d172ece51a619e879c4b86f603d9495cc102
Expand Down Expand Up @@ -669,7 +669,7 @@ struct CmdProfileRemove : virtual EvalCommand, MixDefaultProfile, MixProfileElem
removedCount,
newManifest.elements.size());

updateProfile(newManifest.build(store), store);
updateProfile(newManifest.build(store));
}
};

Expand Down Expand Up @@ -779,7 +779,7 @@ struct CmdProfileUpgrade : virtual SourceExprCommand, MixDefaultProfile, MixProf
builtPaths.find(&*installable)->second.first);
}

updateProfile(manifest.build(store), store);
updateProfile(manifest.build(store));
}
};

Expand Down

0 comments on commit 43ad8c5

Please sign in to comment.