From 6a6bfa6da9ac4b2c54d0eba88e3d30c4147a2379 Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Sun, 24 Nov 2019 17:08:28 +0100 Subject: [PATCH] Fix possible nullref when updating packages --- .../Emby.Server.Implementations.csproj | 1 + .../ScheduledTasks/Tasks/PluginUpdateTask.cs | 4 +++- .../Updates/InstallationManager.cs | 18 +++++++++++------- .../Updates/IInstallationManager.cs | 2 +- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Emby.Server.Implementations/Emby.Server.Implementations.csproj b/Emby.Server.Implementations/Emby.Server.Implementations.csproj index 214ea5aff..385664737 100644 --- a/Emby.Server.Implementations/Emby.Server.Implementations.csproj +++ b/Emby.Server.Implementations/Emby.Server.Implementations.csproj @@ -36,6 +36,7 @@ + diff --git a/Emby.Server.Implementations/ScheduledTasks/Tasks/PluginUpdateTask.cs b/Emby.Server.Implementations/ScheduledTasks/Tasks/PluginUpdateTask.cs index fe8deae59..909fffb1f 100644 --- a/Emby.Server.Implementations/ScheduledTasks/Tasks/PluginUpdateTask.cs +++ b/Emby.Server.Implementations/ScheduledTasks/Tasks/PluginUpdateTask.cs @@ -52,7 +52,9 @@ namespace Emby.Server.Implementations.ScheduledTasks { progress.Report(0); - var packagesToInstall = (await _installationManager.GetAvailablePluginUpdates(cancellationToken).ConfigureAwait(false)).ToList(); + var packagesToInstall = await _installationManager.GetAvailablePluginUpdates(cancellationToken) + .ToListAsync(cancellationToken) + .ConfigureAwait(false); progress.Report(10); diff --git a/Emby.Server.Implementations/Updates/InstallationManager.cs b/Emby.Server.Implementations/Updates/InstallationManager.cs index 1c5402268..09a5a0dca 100644 --- a/Emby.Server.Implementations/Updates/InstallationManager.cs +++ b/Emby.Server.Implementations/Updates/InstallationManager.cs @@ -180,7 +180,7 @@ namespace Emby.Server.Implementations.Updates // Package not found. if (package == null) { - return null; + return Enumerable.Empty(); } return GetCompatibleVersions( @@ -190,19 +190,23 @@ namespace Emby.Server.Implementations.Updates } /// - public async Task> GetAvailablePluginUpdates(CancellationToken cancellationToken = default) + public async IAsyncEnumerable GetAvailablePluginUpdates(CancellationToken cancellationToken = default) { var catalog = await GetAvailablePackages(cancellationToken).ConfigureAwait(false); var systemUpdateLevel = _applicationHost.SystemUpdateLevel; // Figure out what needs to be installed - return _applicationHost.Plugins.Select(x => + foreach (var plugin in _applicationHost.Plugins) { - var compatibleversions = GetCompatibleVersions(catalog, x.Name, x.Id, x.Version, systemUpdateLevel); - return compatibleversions.FirstOrDefault(y => y.Version > x.Version); - }).Where(x => x != null) - .Where(x => !CompletedInstallations.Any(y => string.Equals(y.AssemblyGuid, x.guid, StringComparison.OrdinalIgnoreCase))); + var compatibleversions = GetCompatibleVersions(catalog, plugin.Name, plugin.Id, plugin.Version, systemUpdateLevel); + var version = compatibleversions.FirstOrDefault(y => y.Version > plugin.Version); + if (version != null + && !CompletedInstallations.Any(x => string.Equals(x.AssemblyGuid, version.guid, StringComparison.OrdinalIgnoreCase))) + { + yield return version; + } + } } /// diff --git a/MediaBrowser.Common/Updates/IInstallationManager.cs b/MediaBrowser.Common/Updates/IInstallationManager.cs index 524d8f3c6..e49812f15 100644 --- a/MediaBrowser.Common/Updates/IInstallationManager.cs +++ b/MediaBrowser.Common/Updates/IInstallationManager.cs @@ -92,7 +92,7 @@ namespace MediaBrowser.Common.Updates /// /// The cancellation token. /// The available plugin updates. - Task> GetAvailablePluginUpdates(CancellationToken cancellationToken = default); + IAsyncEnumerable GetAvailablePluginUpdates(CancellationToken cancellationToken = default); /// /// Installs the package.