Skip to content

The Free Software Media System - Server Backend & API

Merge branch 'master' into Plugins

BaronGreenback8439860b2aa3
diff --cc Emby.Server.Implementations/Updates/InstallationManager.cs
index 1fa71e6739,f121a34938..81cf18f8df
--- a/Emby.Server.Implementations/Updates/InstallationManager.cs
+++ b/Emby.Server.Implementations/Updates/InstallationManager.cs
@@@ -16,15 -15,12 +15,14 @@@ using MediaBrowser.Common.Configuration
using MediaBrowser.Common.Net;
using MediaBrowser.Common.Plugins;
using MediaBrowser.Common.Updates;
+using MediaBrowser.Common.System;
using MediaBrowser.Controller.Configuration;
- using MediaBrowser.Model.Events;
using MediaBrowser.Model.IO;
+ using MediaBrowser.Model.Net;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Updates;
- using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
+using MediaBrowser.Model.System;
namespace Emby.Server.Implementations.Updates
{
@@@ -359,51 -352,33 +354,43 @@@
// Always override the passed-in target (which is a file) and figure it out again
string targetDir = Path.Combine(_appPaths.PluginsPath, package.Name);
+ using var response = await _httpClientFactory.CreateClient(NamedClient.Default)
+ .GetAsync(package.SourceUrl, cancellationToken).ConfigureAwait(false);
+ await using var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
+
// CA5351: Do Not Use Broken Cryptographic Algorithms
#pragma warning disable CA5351
- using (var res = await _httpClient.SendAsync(
- new HttpRequestOptions
- {
- Url = package.SourceUrl,
- CancellationToken = cancellationToken,
- // We need it to be buffered for setting the position
- BufferContent = true
- },
- HttpMethod.Get).ConfigureAwait(false))
- using (var stream = res.Content)
- using (var md5 = MD5.Create())
+ using var md5 = MD5.Create();
+ cancellationToken.ThrowIfCancellationRequested();
+
+ var hash = Hex.Encode(md5.ComputeHash(stream));
+ if (!string.Equals(package.Checksum, hash, StringComparison.OrdinalIgnoreCase))
{
- cancellationToken.ThrowIfCancellationRequested();
+ _logger.LogError(
+ "The checksums didn't match while installing {Package}, expected: {Expected}, got: {Received}",
+ package.Name,
+ package.Checksum,
+ hash);
+ throw new InvalidDataException("The checksum of the received data doesn't match.");
+ }
+
++ // Version folder as they cannot be overwritten in Windows.
++ targetDir += "_" + package.Version.ToString();
+
- var hash = Hex.Encode(md5.ComputeHash(stream));
- if (!string.Equals(package.Checksum, hash, StringComparison.OrdinalIgnoreCase))
+ if (Directory.Exists(targetDir))
+ {
- Directory.Delete(targetDir, true);
++ try
+ {
- _logger.LogError(
- "The checksums didn't match while installing {Package}, expected: {Expected}, got: {Received}",
- package.Name,
- package.Checksum,
- hash);
- throw new InvalidDataException("The checksum of the received data doesn't match.");
++ Directory.Delete(targetDir, true);
+ }
-
- // Version folder as they cannot be overwritten in Windows.
- targetDir += "_" + package.Version.ToString();
-
- if (Directory.Exists(targetDir))
++ catch
+ {
- try
- {
- Directory.Delete(targetDir, true);
- }
- catch
- {
- // Ignore any exceptions.
- }
++ // Ignore any exceptions.
+ }
-
- stream.Position = 0;
- _zipClient.ExtractAllFromZip(stream, targetDir, true);
}
-
++
+ stream.Position = 0;
+ _zipClient.ExtractAllFromZip(stream, targetDir, true);
#pragma warning restore CA5351
}