From 1f67431991dfaa1e5ab2f41a0ed0b03af5c5260b Mon Sep 17 00:00:00 2001 From: Paul Hebble Date: Thu, 28 Sep 2023 09:17:12 -0500 Subject: [PATCH] Obey suppress_recommendations for CmdLine installs --- Core/Relationships/RelationshipResolver.cs | 37 +++++++++++++++++++--- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/Core/Relationships/RelationshipResolver.cs b/Core/Relationships/RelationshipResolver.cs index e5aed0b118..7ffc3ff598 100644 --- a/Core/Relationships/RelationshipResolver.cs +++ b/Core/Relationships/RelationshipResolver.cs @@ -193,8 +193,7 @@ private void Resolve(CkanModule module, // Even though we may resolve top-level suggests for our module, // we don't install suggestions all the way down unless with_all_suggests // is true. - var sub_options = (RelationshipResolverOptions) options.Clone(); - sub_options.with_suggests = false; + var sub_options = options.WithoutSuggestions(); old_stanza = old_stanza?.Memoize(); @@ -239,13 +238,14 @@ private void ResolveStanza(List stanza, SelectionReason reason, RelationshipResolverOptions options, bool soft_resolve = false, - IEnumerable old_stanza = null) + IEnumerable old_stanza = null) { if (stanza == null) { return; } + var orig_options = options; foreach (RelationshipDescriptor descriptor in stanza) { log.DebugFormat("Considering {0}", descriptor.ToString()); @@ -255,6 +255,7 @@ private void ResolveStanza(List stanza, log.DebugFormat("Skipping {0} because get_recommenders option is set"); continue; } + options = orig_options.OptionsFor(descriptor); // If we already have this dependency covered, // resolve its relationships if we haven't already. @@ -667,7 +668,7 @@ private void AddReason(CkanModule module, SelectionReason reason) // TODO: It would be lovely to get rid of the `without` fields, // and replace them with `with` fields. Humans suck at inverting // cases in their heads. - public class RelationshipResolverOptions : ICloneable + public class RelationshipResolverOptions { /// /// If true, add recommended mods, and their recommendations. @@ -723,7 +724,33 @@ public class RelationshipResolverOptions : ICloneable /// public bool get_recommenders = false; - public object Clone() => MemberwiseClone(); + public RelationshipResolverOptions OptionsFor(RelationshipDescriptor descr) + => descr.suppress_recommendations ? WithoutRecommendations() : this; + + private RelationshipResolverOptions WithoutRecommendations() + { + if (with_recommends || with_all_suggests || with_suggests) + { + var newOptions = (RelationshipResolverOptions)MemberwiseClone(); + newOptions.with_recommends = false; + newOptions.with_all_suggests = false; + newOptions.with_suggests = false; + return newOptions; + } + return this; + } + + public RelationshipResolverOptions WithoutSuggestions() + { + if (with_suggests) + { + var newOptions = (RelationshipResolverOptions)MemberwiseClone(); + newOptions.with_suggests = false; + return newOptions; + } + return this; + } + } ///