Skip to content

Commit

Permalink
Merge #2238 Don't clear available modules till after the new list is …
Browse files Browse the repository at this point in the history
…ready
  • Loading branch information
politas committed Jan 2, 2018
2 parents 17ae4cd + 8d73776 commit c54020b
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 174 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ All notable changes to this project will be documented in this file.
- [Build] Check version of PowerShell in build script (#2235 by: HebaruSan; reviewed: Olympic1)
- [Multiple] Add and change logging to make INFO readable (#2236 by: HebaruSan; reviewed: politas)
- [Multiple] Use shared installer code in GUI and fix reinstall problems (#2233 by: HebaruSan; reviewed: Olympic1, politas)
- [Multiple] Don't clear available modules till after the new list is ready (#2238 by: HebaruSan; reviewed: politas)

### Internal

Expand Down
2 changes: 1 addition & 1 deletion Cmdline/Action/Update.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private void UpdateRepository(CKAN.KSP ksp, string repository = null)

var updated = repository == null
? CKAN.Repo.UpdateAllRepositories(registry_manager, ksp, user)
: CKAN.Repo.Update(registry_manager, ksp, user, true, repository);
: CKAN.Repo.Update(registry_manager, ksp, user, repository);

user.RaiseMessage("Updated information on {0} available modules", updated);
}
Expand Down
340 changes: 191 additions & 149 deletions Core/Net/Repo.cs

Large diffs are not rendered by default.

13 changes: 8 additions & 5 deletions Core/Registry/Registry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,16 @@ private void SealionTransaction()

#endregion

/// <summary>
/// Clears all available modules from the registry.
/// </summary>
public void ClearAvailable()
public void SetAllAvailable(IEnumerable<CkanModule> newAvail)
{
SealionTransaction();
// Clear current modules
available_modules = new Dictionary<string, AvailableModule>();
// Add the new modules
foreach (CkanModule module in newAvail)
{
AddAvailable(module);
}
}

/// <summary>
Expand All @@ -365,7 +368,7 @@ public void AddAvailable(CkanModule module)

var identifier = module.identifier;
// If we've never seen this module before, create an entry for it.
if (! available_modules.ContainsKey(identifier))
if (!available_modules.ContainsKey(identifier))
{
log.DebugFormat("Adding new available module {0}", identifier);
available_modules[identifier] = new AvailableModule(identifier);
Expand Down
9 changes: 4 additions & 5 deletions Tests/Core/Net/NetAsyncModulesDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace Tests.Core.Net
public class NetAsyncModulesDownloader
{

private CKAN.RegistryManager manager;
private CKAN.Registry registry;
private DisposableKSP ksp;
private CKAN.IDownloader async;
Expand All @@ -29,13 +30,12 @@ public void Setup()

// Give us a registry to play with.
ksp = new DisposableKSP();
registry = CKAN.RegistryManager.Instance(ksp.KSP).registry;
registry.ClearAvailable();
manager = CKAN.RegistryManager.Instance(ksp.KSP);
registry = manager.registry;
registry.ClearDlls();
registry.Installed().Clear();

// Make sure we have a registry we can use.
CKAN.Repo.UpdateRegistry(TestData.TestKANZip(), registry, ksp.KSP, new NullUser());
CKAN.Repo.Update(manager, ksp.KSP, new NullUser(), TestData.TestKANZip());

// Ready our downloader.
async = new CKAN.NetAsyncModulesDownloader(new NullUser());
Expand Down Expand Up @@ -128,4 +128,3 @@ public void RandSdownload()

}
}

19 changes: 10 additions & 9 deletions Tests/Core/Net/Repo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ namespace Tests.Core.Net
[TestFixture]
public class Repo
{
private CKAN.RegistryManager manager;
private CKAN.Registry registry;
private DisposableKSP ksp;

[SetUp]
public void Setup()
{
ksp = new DisposableKSP();
registry = CKAN.RegistryManager.Instance(ksp.KSP).registry;
registry.ClearAvailable();
manager = CKAN.RegistryManager.Instance(ksp.KSP);
registry = manager.registry;
registry.ClearDlls();
registry.Installed().Clear();
}
Expand All @@ -30,7 +31,7 @@ public void TearDown()
[Test]
public void UpdateRegistryTarGz()
{
CKAN.Repo.UpdateRegistry(TestData.TestKANTarGz(), registry, ksp.KSP, new NullUser());
CKAN.Repo.Update(manager, ksp.KSP, new NullUser(), TestData.TestKANTarGz());

// Test we've got an expected module.
CkanModule far = registry.LatestAvailable("FerramAerospaceResearch", new KspVersionCriteria(KspVersion.Parse("0.25.0")));
Expand All @@ -41,10 +42,10 @@ public void UpdateRegistryTarGz()
[Test]
public void UpdateRegistryZip()
{
CKAN.Repo.UpdateRegistry(TestData.TestKANZip(), registry, ksp.KSP, new NullUser());
CKAN.Repo.Update(manager, ksp.KSP, new NullUser(), TestData.TestKANZip());

// Test we've got an expected module.
CkanModule far = registry.LatestAvailable("FerramAerospaceResearch", new KspVersionCriteria (KspVersion.Parse("0.25.0")));
CkanModule far = registry.LatestAvailable("FerramAerospaceResearch", new KspVersionCriteria(KspVersion.Parse("0.25.0")));

Assert.AreEqual("v0.14.3.2", far.version.ToString());
}
Expand All @@ -54,17 +55,17 @@ public void BadKanTarGz()
{
Assert.DoesNotThrow(delegate
{
CKAN.Repo.UpdateRegistry(TestData.BadKANTarGz(), registry, ksp.KSP, new NullUser());
CKAN.Repo.Update(manager, ksp.KSP, new NullUser(), TestData.BadKANTarGz());
});
}

[Test]
public void BadKanZip()
{
Assert.DoesNotThrow(delegate
{
CKAN.Repo.UpdateRegistry(TestData.BadKANZip(), registry, ksp.KSP, new NullUser());
});
{
CKAN.Repo.Update(manager, ksp.KSP, new NullUser(), TestData.BadKANZip());
});
}
}
}
9 changes: 4 additions & 5 deletions Tests/Core/Relationships/SanityChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace Tests.Core.Relationships
[TestFixture]
public class SanityChecker
{
private CKAN.RegistryManager manager;
private CKAN.Registry registry;
private DisposableKSP ksp;

Expand All @@ -21,12 +22,11 @@ public void Setup()
{
ksp = new DisposableKSP();

registry = CKAN.RegistryManager.Instance(ksp.KSP).registry;
registry.ClearAvailable();
manager = CKAN.RegistryManager.Instance(ksp.KSP);
registry = manager.registry;
registry.ClearDlls();
registry.Installed().Clear();

Repo.UpdateRegistry(TestData.TestKANZip(), registry, ksp.KSP, new NullUser());
CKAN.Repo.Update(manager, ksp.KSP, new NullUser(), TestData.TestKANZip());
}

[Test]
Expand Down Expand Up @@ -191,4 +191,3 @@ private static void TestDepends(List<string> to_remove, List<CkanModule> mods, L
}
}
}

0 comments on commit c54020b

Please sign in to comment.