Skip to content

Commit

Permalink
Obey suppress_recommendations for CmdLine installs
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Sep 29, 2023
1 parent dc56a57 commit 1f67431
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions Core/Relationships/RelationshipResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -239,13 +238,14 @@ private void ResolveStanza(List<RelationshipDescriptor> stanza,
SelectionReason reason,
RelationshipResolverOptions options,
bool soft_resolve = false,
IEnumerable<RelationshipDescriptor> old_stanza = null)
IEnumerable<RelationshipDescriptor> old_stanza = null)
{
if (stanza == null)
{
return;
}

var orig_options = options;
foreach (RelationshipDescriptor descriptor in stanza)
{
log.DebugFormat("Considering {0}", descriptor.ToString());
Expand All @@ -255,6 +255,7 @@ private void ResolveStanza(List<RelationshipDescriptor> 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.
Expand Down Expand Up @@ -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
{
/// <summary>
/// If true, add recommended mods, and their recommendations.
Expand Down Expand Up @@ -723,7 +724,33 @@ public class RelationshipResolverOptions : ICloneable
/// </summary>
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;
}

}

/// <summary>
Expand Down

0 comments on commit 1f67431

Please sign in to comment.