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

Don't crash if download_hash isn't set #2313

Merged
merged 1 commit into from
Feb 25, 2018
Merged

Conversation

HebaruSan
Copy link
Member

@HebaruSan HebaruSan commented Feb 25, 2018

Problem

If you try to install a mod that doesn't have a download_hash defined in its metadata, you might encounter this exception:

System.NullReferenceException: Object reference not set to an instance of an object.
   at CKAN.CkanModule.get_InternetArchiveDownload()
   at CKAN.NetAsyncModulesDownloader.<>c.<DownloadModules>b__8_4(KeyValuePair`2 item)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at CKAN.NetAsyncModulesDownloader.DownloadModules(NetModuleCache cache, IEnumerable`1 modules)
   at CKAN.ModuleInstaller.DownloadModules(IEnumerable`1 mods, IDownloader downloader)
   at CKAN.ModuleInstaller.Upgrade(IEnumerable`1 modules, IDownloader netAsyncDownloader, Boolean enforceConsistency)
   at CKAN.Main.InstallMods(Object sender, DoWorkEventArgs e)
   at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)
   at System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument)

Cause

We currently assume download_hash won't be null when checking for fallback URLs:

public Uri InternetArchiveDownload
{
get
{
string verStr = version.ToString().Replace(':', '-');
return license.All(l => l.Redistributable)
? new Uri(
$"https://archive.org/download/{identifier}-{verStr}/{download_hash.sha1.Substring(0, 8)}-{identifier}-{verStr}.zip")
: null;
}
}

https://ksp.sarbian.com/ckan/MechJeb2-ci.tar.gz contains metadata for bleeding edge versions of MechJeb2, and it does not include the download_hash properties. This makes these modules uninstallable until this bug is fixed.

Changes

Now we check that download_hash?.sha1 is not null before using it to provide a fallback URL.

This allows such modules to download and install normally.

Fixes https://forum.kerbalspaceprogram.com/index.php?/topic/154922-ckan-the-comprehensive-kerbal-archive-network-v1240-bruce/&do=findComment&comment=3303984

@HebaruSan HebaruSan added Bug Something is not working as intended Pull request Network Issues affecting internet connections of CKAN and removed Bug Something is not working as intended Network Issues affecting internet connections of CKAN labels Feb 25, 2018
@politas politas merged commit 424b0c2 into KSP-CKAN:master Feb 25, 2018
politas added a commit that referenced this pull request Feb 25, 2018
@politas politas removed Bug Something is not working as intended Network Issues affecting internet connections of CKAN Pull request labels Feb 25, 2018
@HebaruSan HebaruSan deleted the fix/ia-nre branch February 25, 2018 16:30
@HebaruSan HebaruSan mentioned this pull request Apr 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants