1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-07 01:51:47 +02:00

profile: extract getNameFromElement

This commit is contained in:
Bob van der Linden 2024-02-26 21:06:07 +01:00
parent d83008c3a7
commit d28a240aa6
No known key found for this signature in database

View file

@ -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 struct ProfileManifest
{ {
using ProfileElementName = std::string; using ProfileElementName = std::string;
@ -189,12 +198,8 @@ struct ProfileManifest
void addElement(ProfileElement element) void addElement(ProfileElement element)
{ {
auto name = auto name = getNameFromElement(element);
element.source addElement(name, std::move(element));
? getNameFromURL(parseURL(element.source->to_string()))
: std::nullopt;
auto name2 = name ? *name : element.identifier();
addElement(name2, std::move(element));
} }
nlohmann::json toJSON(Store & store) const nlohmann::json toJSON(Store & store) const