mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-25 15:26:17 +02:00
Merge pull request #10090 from bobvanderlinden/profile-error-install-twice
profile install: warn on installing package twice
This commit is contained in:
commit
b1586a6799
2 changed files with 34 additions and 7 deletions
|
@ -101,6 +101,15 @@ struct ProfileElement
|
|||
}
|
||||
};
|
||||
|
||||
std::string getNameFromElement(const ProfileElement & element)
|
||||
{
|
||||
std::optional<std::string> result = std::nullopt;
|
||||
if (element.source) {
|
||||
result = getNameFromURL(parseURL(element.source->to_string()));
|
||||
}
|
||||
return result.value_or(element.identifier());
|
||||
}
|
||||
|
||||
struct ProfileManifest
|
||||
{
|
||||
using ProfileElementName = std::string;
|
||||
|
@ -189,12 +198,8 @@ struct ProfileManifest
|
|||
|
||||
void addElement(ProfileElement element)
|
||||
{
|
||||
auto name =
|
||||
element.source
|
||||
? getNameFromURL(parseURL(element.source->to_string()))
|
||||
: std::nullopt;
|
||||
auto name2 = name ? *name : element.identifier();
|
||||
addElement(name2, std::move(element));
|
||||
auto name = getNameFromElement(element);
|
||||
addElement(name, std::move(element));
|
||||
}
|
||||
|
||||
nlohmann::json toJSON(Store & store) const
|
||||
|
@ -390,7 +395,26 @@ struct CmdProfileInstall : InstallablesCommand, MixDefaultProfile
|
|||
|
||||
element.updateStorePaths(getEvalStore(), store, res);
|
||||
|
||||
manifest.addElement(std::move(element));
|
||||
auto elementName = getNameFromElement(element);
|
||||
|
||||
// Check if the element already exists.
|
||||
auto existingPair = manifest.elements.find(elementName);
|
||||
if (existingPair != manifest.elements.end()) {
|
||||
auto existingElement = existingPair->second;
|
||||
auto existingSource = existingElement.source;
|
||||
auto elementSource = element.source;
|
||||
if (existingSource
|
||||
&& elementSource
|
||||
&& existingElement.priority == element.priority
|
||||
&& existingSource->originalRef == elementSource->originalRef
|
||||
&& existingSource->attrPath == elementSource->attrPath
|
||||
) {
|
||||
warn("'%s' is already installed", elementName);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
manifest.addElement(elementName, std::move(element));
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
|
@ -64,6 +64,9 @@ nix profile install $flake1Dir
|
|||
[[ $($TEST_HOME/.local/state/nix/profile/bin/hello) = "Hello World" ]]
|
||||
unset NIX_CONFIG
|
||||
|
||||
# Test conflicting package install.
|
||||
nix profile install $flake1Dir 2>&1 | grep "warning: 'flake1' is already installed"
|
||||
|
||||
# Test upgrading a package.
|
||||
printf NixOS > $flake1Dir/who
|
||||
printf 2.0 > $flake1Dir/version
|
||||
|
|
Loading…
Reference in a new issue