Skip to content

Commit

Permalink
Inflation error for multi-hosted mods with mismatched versions
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Sep 8, 2024
1 parent bc7b390 commit e1d251f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
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

0 comments on commit e1d251f

Please sign in to comment.