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

Skip duplicate repo URLs during update #3786

Merged
merged 2 commits into from
Feb 21, 2023
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
10 changes: 9 additions & 1 deletion Core/Extensions/EnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public static TimeSpan Sum(this IEnumerable<TimeSpan> source)
=> source.Aggregate(TimeSpan.Zero,
(a, b) => a + b);


/// <summary>
/// Select : SelectMany :: Zip : ZipMany
/// </summary>
Expand All @@ -79,6 +78,15 @@ public static TimeSpan Sum(this IEnumerable<TimeSpan> source)
public static IEnumerable<V> ZipMany<T, U, V>(this IEnumerable<T> seq1, IEnumerable<U> seq2, Func<T, U, IEnumerable<V>> func)
=> seq1.Zip(seq2, func).SelectMany(seqs => seqs);

/// <summary>
/// Eliminate duplicate elements based on the value returned by a callback
/// </summary>
/// <param name="seq">Sequence of elements to check</param>
/// <param name="func">Function to return unique value per element</param>
/// <returns>Sequence where each element has a unique return value</returns>
public static IEnumerable<T> DistinctBy<T, U>(this IEnumerable<T> seq, Func<T, U> func)
=> seq.GroupBy(func).Select(grp => grp.First());

}

/// <summary>
Expand Down
16 changes: 11 additions & 5 deletions Core/Net/Repo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public static class Repo
/// </summary>
public static RepoUpdateResult UpdateAllRepositories(RegistryManager registry_manager, GameInstance ksp, NetAsyncDownloader downloader, NetModuleCache cache, IUser user)
{
var repos = registry_manager.registry.Repositories.Values.ToArray();
var repos = registry_manager.registry.Repositories.Values
.DistinctBy(r => r.uri)
.ToArray();

// Get latest copy of the game versions data (remote build map)
user.RaiseMessage(Properties.Resources.NetRepoUpdatingBuildMap);
Expand Down Expand Up @@ -139,7 +141,7 @@ private static List<CkanModule> ModulesFromTarGz(Repository repo, string path, r
// Create a handle for the tar stream
using (TarInputStream tarStream = new TarInputStream(gzipStream, Encoding.UTF8))
{
user.RaiseMessage("Loading modules from {0} repository...", repo.name);
user.RaiseMessage(Properties.Resources.NetRepoLoadingModulesFromRepo, repo.name);
TarEntry entry;
int prevPercent = 0;
while ((entry = tarStream.GetNextEntry()) != null)
Expand All @@ -150,15 +152,17 @@ private static List<CkanModule> ModulesFromTarGz(Repository repo, string path, r
{
downloadCounts = JsonConvert.DeserializeObject<SortedDictionary<string, int>>(
tarStreamString(tarStream, entry));
user.RaiseMessage("Loaded download counts from {0} repository", repo.name);
user.RaiseMessage(Properties.Resources.NetRepoLoadedDownloadCounts, repo.name);
}
else if (filename.EndsWith(".ckan"))
{
log.DebugFormat("Reading CKAN data from {0}", filename);
var percent = (int)(100 * inputStream.Position / inputStream.Length);
if (percent > prevPercent)
{
user.RaiseProgress($"Loading modules from {repo.name} repository", percent);
user.RaiseProgress(
string.Format(Properties.Resources.NetRepoLoadingModulesFromRepo, repo.name),
percent);
prevPercent = percent;
}

Expand Down Expand Up @@ -227,7 +231,9 @@ private static List<CkanModule> ModulesFromZip(Repository repo, string path, IUs
var percent = (int)(100 * index / zipfile.Count);
if (percent > prevPercent)
{
user.RaiseProgress($"Loading modules from {repo.name} repository", percent);
user.RaiseProgress(
string.Format(Properties.Resources.NetRepoLoadingModulesFromRepo, repo.name),
percent);
}

// Read each file into a string.
Expand Down
6 changes: 6 additions & 0 deletions Core/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Core/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ You should reinstall them in order to preserve consistency with the repository.

Do you wish to reinstall now?</value></data>
<data name="NetRepoInconsistenciesHeader" xml:space="preserve"><value>The following inconsistencies were found:</value></data>
<data name="NetRepoLoadingModulesFromRepo" xml:space="preserve"><value>Loading modules from {0} repository...</value></data>
<data name="NetRepoLoadedDownloadCounts" xml:space="preserve"><value>Loaded download counts from {0} repository</value></data>
<data name="JsonRelationshipConverterAnyOfCombined" xml:space="preserve"><value>`any_of` should not be combined with `{0}`</value></data>
<data name="RegistryFileConflict" xml:space="preserve"><value>{0} wishes to install {1}, but this file is registered to {2}</value></data>
<data name="RegistryFileNotRemoved" xml:space="preserve"><value>{0} is registered to {1} but has not been removed!</value></data>
Expand Down