Skip to content

Commit

Permalink
Improve handling of repo update failures
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Feb 9, 2018
1 parent 990e923 commit 17cbcac
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 20 deletions.
36 changes: 25 additions & 11 deletions Core/Net/Repo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,42 @@ public static int UpdateAllRepositories(RegistryManager registry_manager, KSP ks
{
log.InfoFormat("About to update {0}", repository.Value.name);
List<CkanModule> avail = UpdateRegistry(repository.Value.uri, ksp, user);
log.InfoFormat("Updated {0}", repository.Value.name);
// Merge all the lists
allAvail.AddRange(avail);
if (avail == null)
{
// Report failure if any repo fails, rather than losing half the list.
// UpdateRegistry will have alerted the user to specific errors already.
return 0;
}
else
{
log.InfoFormat("Updated {0}", repository.Value.name);
// Merge all the lists
allAvail.AddRange(avail);
}
}
// Save allAvail to the registry if we found anything
if (allAvail.Count > 0)
{
registry_manager.registry.SetAllAvailable(allAvail);
// Save our changes.
registry_manager.Save(enforce_consistency: false);
}

ShowUserInconsistencies(registry_manager.registry, user);
ShowUserInconsistencies(registry_manager.registry, user);

List<CkanModule> metadataChanges = GetChangedInstalledModules(registry_manager.registry);
if (metadataChanges.Count > 0)
List<CkanModule> metadataChanges = GetChangedInstalledModules(registry_manager.registry);
if (metadataChanges.Count > 0)
{
HandleModuleChanges(metadataChanges, user, ksp);
}

// Return how many we got!
return registry_manager.registry.Available(ksp.VersionCriteria()).Count;
}
else
{
HandleModuleChanges(metadataChanges, user, ksp);
// Return failure
return 0;
}

// Return how many we got!
return registry_manager.registry.Available(ksp.VersionCriteria()).Count;
}

/// <summary>
Expand Down
20 changes: 13 additions & 7 deletions GUI/MainRepo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ private void UpdateRepo(object sender, DoWorkEventArgs e)
{
try
{
KSP current_instance1 = CurrentInstance;
Repo.UpdateAllRepositories(RegistryManager.Instance(CurrentInstance), current_instance1, GUI.user);
AddStatusMessage("Updating repositories...");
e.Result = Repo.UpdateAllRepositories(RegistryManager.Instance(CurrentInstance), CurrentInstance, GUI.user);
}
catch (UriFormatException ex)
{
Expand All @@ -89,11 +89,17 @@ private void UpdateRepo(object sender, DoWorkEventArgs e)

private void PostUpdateRepo(object sender, RunWorkerCompletedEventArgs e)
{
UpdateModsList(repo_updated: true);

HideWaitDialog(true);
AddStatusMessage("Repository successfully updated");
ShowRefreshQuestion();
if ((e.Result as int? ?? 0) > 0)
{
UpdateModsList(repo_updated: true);
AddStatusMessage("Repositories successfully updated.");
ShowRefreshQuestion();
HideWaitDialog(true);
}
else
{
AddStatusMessage("Repository update failed!");
}

Util.Invoke(this, SwitchEnabledState);
Util.Invoke(this, RecreateDialogs);
Expand Down
4 changes: 2 additions & 2 deletions GUI/MainWait.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ private void CancelCurrentActionButton_Click(object sender, EventArgs e)
if (cancelCallback != null)
{
cancelCallback();
CancelCurrentActionButton.Enabled = false;
HideWaitDialog(true);
}
CancelCurrentActionButton.Enabled = false;
HideWaitDialog(true);
}

}
Expand Down

0 comments on commit 17cbcac

Please sign in to comment.