Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inflation error for multi-hosted mods with mismatched versions #4178

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Netkan/Model/Metadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ internal sealed class Metadata
public bool Staged { get; private set; }
public string? StagingReason { get; private set; }

public string[] Hosts
=> (_json.TryGetValue(DownloadPropertyName, out JToken? downloadToken)
? downloadToken.Type == JTokenType.String
&& (string?)downloadToken is string url
? Enumerable.Repeat(url, 1)
: downloadToken.Children()
.Select(ch => (string?)ch)
.OfType<string>()
: Enumerable.Empty<string>())
.Select(u => new Uri(u).Host)
.ToArray();

public Metadata(JObject? json)
{
if (json == null)
Expand Down
24 changes: 17 additions & 7 deletions Netkan/Processors/Inflator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,22 @@ internal IEnumerable<Metadata> Inflate(string filename, Metadata[] netkans, Tran
}
log.Debug("Input successfully passed pre-validation");

var ckans = netkans
.SelectMany(netkan => transformer.Transform(netkan, opts))
.GroupBy(module => module.Version)
.Select(grp => Metadata.Merge(grp.ToArray()))
.SelectMany(merged => specVersionTransformer.Transform(merged, opts))
.SelectMany(withSpecVersion => sortTransformer.Transform(withSpecVersion, opts))
.ToList();
var ckans = netkans.SelectMany(netkan => transformer.Transform(netkan, opts))
.GroupBy(module => module.Version)
.Select(grp => Metadata.Merge(grp.ToArray()))
.SelectMany(merged => specVersionTransformer.Transform(merged, opts))
.SelectMany(withSpecVersion => sortTransformer.Transform(withSpecVersion, opts))
.ToList();
log.Debug("Finished transformation");

if (ckans.Count > (opts?.Releases ?? 1))
{
throw new Kraken(string.Format("Generated {0} modules but only {1} requested: {2}",
ckans.Count,
opts?.Releases ?? 1,
string.Join("; ", ckans.Select(DescribeHosting))));
}

foreach (Metadata ckan in ckans)
{
ckanValidator.ValidateCkan(ckan, netkans.First());
Expand Down Expand Up @@ -123,6 +130,9 @@ private static void PurgeDownloads(IHttpService http, NetFileCache cache)
}
}

private string DescribeHosting(Metadata metadata)
=> $"{metadata.Version} on {string.Join(", ", metadata.Hosts)}";

private readonly NetFileCache cache;
private readonly IHttpService http;

Expand Down