From a4565da4a998cfaa5bb8ff9d96d3d62b25574a90 Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Sat, 18 Dec 2021 17:49:33 +0100 Subject: [PATCH] Use System.IO.Compression instead of SharpCompress for zips Also removes unused methods from ZipClient --- .../Archiving/ZipClient.cs | 116 ------------------ .../Updates/InstallationManager.cs | 8 +- MediaBrowser.Model/IO/IZipClient.cs | 56 --------- .../Updates/InstallationManagerTests.cs | 1 - 4 files changed, 3 insertions(+), 178 deletions(-) diff --git a/Emby.Server.Implementations/Archiving/ZipClient.cs b/Emby.Server.Implementations/Archiving/ZipClient.cs index 9e1d550ebc..6a3b250d25 100644 --- a/Emby.Server.Implementations/Archiving/ZipClient.cs +++ b/Emby.Server.Implementations/Archiving/ZipClient.cs @@ -1,11 +1,8 @@ using System.IO; using MediaBrowser.Model.IO; -using SharpCompress.Archives.SevenZip; -using SharpCompress.Archives.Tar; using SharpCompress.Common; using SharpCompress.Readers; using SharpCompress.Readers.GZip; -using SharpCompress.Readers.Zip; namespace Emby.Server.Implementations.Archiving { @@ -14,55 +11,6 @@ namespace Emby.Server.Implementations.Archiving /// public class ZipClient : IZipClient { - /// - /// Extracts all. - /// - /// The source file. - /// The target path. - /// if set to true [overwrite existing files]. - public void ExtractAll(string sourceFile, string targetPath, bool overwriteExistingFiles) - { - using var fileStream = File.OpenRead(sourceFile); - ExtractAll(fileStream, targetPath, overwriteExistingFiles); - } - - /// - /// Extracts all. - /// - /// The source. - /// The target path. - /// if set to true [overwrite existing files]. - public void ExtractAll(Stream source, string targetPath, bool overwriteExistingFiles) - { - using var reader = ReaderFactory.Open(source); - var options = new ExtractionOptions - { - ExtractFullPath = true - }; - - if (overwriteExistingFiles) - { - options.Overwrite = true; - } - - Directory.CreateDirectory(targetPath); - reader.WriteAllToDirectory(targetPath, options); - } - - /// - public void ExtractAllFromZip(Stream source, string targetPath, bool overwriteExistingFiles) - { - using var reader = ZipReader.Open(source); - var options = new ExtractionOptions - { - ExtractFullPath = true, - Overwrite = overwriteExistingFiles - }; - - Directory.CreateDirectory(targetPath); - reader.WriteAllToDirectory(targetPath, options); - } - /// public void ExtractAllFromGz(Stream source, string targetPath, bool overwriteExistingFiles) { @@ -94,69 +42,5 @@ namespace Emby.Server.Implementations.Archiving reader.WriteEntryToFile(Path.Combine(targetPath, filename)); } } - - /// - /// Extracts all from7z. - /// - /// The source file. - /// The target path. - /// if set to true [overwrite existing files]. - public void ExtractAllFrom7z(string sourceFile, string targetPath, bool overwriteExistingFiles) - { - using var fileStream = File.OpenRead(sourceFile); - ExtractAllFrom7z(fileStream, targetPath, overwriteExistingFiles); - } - - /// - /// Extracts all from7z. - /// - /// The source. - /// The target path. - /// if set to true [overwrite existing files]. - public void ExtractAllFrom7z(Stream source, string targetPath, bool overwriteExistingFiles) - { - using var archive = SevenZipArchive.Open(source); - using var reader = archive.ExtractAllEntries(); - var options = new ExtractionOptions - { - ExtractFullPath = true, - Overwrite = overwriteExistingFiles - }; - - Directory.CreateDirectory(targetPath); - reader.WriteAllToDirectory(targetPath, options); - } - - /// - /// Extracts all from tar. - /// - /// The source file. - /// The target path. - /// if set to true [overwrite existing files]. - public void ExtractAllFromTar(string sourceFile, string targetPath, bool overwriteExistingFiles) - { - using var fileStream = File.OpenRead(sourceFile); - ExtractAllFromTar(fileStream, targetPath, overwriteExistingFiles); - } - - /// - /// Extracts all from tar. - /// - /// The source. - /// The target path. - /// if set to true [overwrite existing files]. - public void ExtractAllFromTar(Stream source, string targetPath, bool overwriteExistingFiles) - { - using var archive = TarArchive.Open(source); - using var reader = archive.ExtractAllEntries(); - var options = new ExtractionOptions - { - ExtractFullPath = true, - Overwrite = overwriteExistingFiles - }; - - Directory.CreateDirectory(targetPath); - reader.WriteAllToDirectory(targetPath, options); - } } } diff --git a/Emby.Server.Implementations/Updates/InstallationManager.cs b/Emby.Server.Implementations/Updates/InstallationManager.cs index ef95ebf943..7f7eec7d93 100644 --- a/Emby.Server.Implementations/Updates/InstallationManager.cs +++ b/Emby.Server.Implementations/Updates/InstallationManager.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; +using System.IO.Compression; using System.Linq; using System.Net.Http; using System.Net.Http.Json; @@ -47,7 +48,6 @@ namespace Emby.Server.Implementations.Updates /// /// The application host. private readonly IServerApplicationHost _applicationHost; - private readonly IZipClient _zipClient; private readonly object _currentInstallationsLock = new object(); /// @@ -69,7 +69,6 @@ namespace Emby.Server.Implementations.Updates /// The . /// The . /// The . - /// The . /// The . public InstallationManager( ILogger logger, @@ -78,7 +77,6 @@ namespace Emby.Server.Implementations.Updates IEventManager eventManager, IHttpClientFactory httpClientFactory, IServerConfigurationManager config, - IZipClient zipClient, IPluginManager pluginManager) { _currentInstallations = new List<(InstallationInfo, CancellationTokenSource)>(); @@ -90,7 +88,6 @@ namespace Emby.Server.Implementations.Updates _eventManager = eventManager; _httpClientFactory = httpClientFactory; _config = config; - _zipClient = zipClient; _jsonSerializerOptions = JsonDefaults.Options; _pluginManager = pluginManager; } @@ -560,7 +557,8 @@ namespace Emby.Server.Implementations.Updates } stream.Position = 0; - _zipClient.ExtractAllFromZip(stream, targetDir, true); + using var reader = new ZipArchive(stream); + reader.ExtractToDirectory(targetDir, true); await _pluginManager.GenerateManifest(package.PackageInfo, package.Version, targetDir, status).ConfigureAwait(false); _pluginManager.ImportPluginFrom(targetDir); } diff --git a/MediaBrowser.Model/IO/IZipClient.cs b/MediaBrowser.Model/IO/IZipClient.cs index fca52ebae6..2448575d19 100644 --- a/MediaBrowser.Model/IO/IZipClient.cs +++ b/MediaBrowser.Model/IO/IZipClient.cs @@ -9,64 +9,8 @@ namespace MediaBrowser.Model.IO /// public interface IZipClient { - /// - /// Extracts all. - /// - /// The source file. - /// The target path. - /// if set to true [overwrite existing files]. - void ExtractAll(string sourceFile, string targetPath, bool overwriteExistingFiles); - - /// - /// Extracts all. - /// - /// The source. - /// The target path. - /// if set to true [overwrite existing files]. - void ExtractAll(Stream source, string targetPath, bool overwriteExistingFiles); - void ExtractAllFromGz(Stream source, string targetPath, bool overwriteExistingFiles); void ExtractFirstFileFromGz(Stream source, string targetPath, string defaultFileName); - - /// - /// Extracts all from zip. - /// - /// The source. - /// The target path. - /// if set to true [overwrite existing files]. - void ExtractAllFromZip(Stream source, string targetPath, bool overwriteExistingFiles); - - /// - /// Extracts all from7z. - /// - /// The source file. - /// The target path. - /// if set to true [overwrite existing files]. - void ExtractAllFrom7z(string sourceFile, string targetPath, bool overwriteExistingFiles); - - /// - /// Extracts all from7z. - /// - /// The source. - /// The target path. - /// if set to true [overwrite existing files]. - void ExtractAllFrom7z(Stream source, string targetPath, bool overwriteExistingFiles); - - /// - /// Extracts all from tar. - /// - /// The source file. - /// The target path. - /// if set to true [overwrite existing files]. - void ExtractAllFromTar(string sourceFile, string targetPath, bool overwriteExistingFiles); - - /// - /// Extracts all from tar. - /// - /// The source. - /// The target path. - /// if set to true [overwrite existing files]. - void ExtractAllFromTar(Stream source, string targetPath, bool overwriteExistingFiles); } } diff --git a/tests/Jellyfin.Server.Implementations.Tests/Updates/InstallationManagerTests.cs b/tests/Jellyfin.Server.Implementations.Tests/Updates/InstallationManagerTests.cs index 09c4bd1004..d18441ac01 100644 --- a/tests/Jellyfin.Server.Implementations.Tests/Updates/InstallationManagerTests.cs +++ b/tests/Jellyfin.Server.Implementations.Tests/Updates/InstallationManagerTests.cs @@ -44,7 +44,6 @@ namespace Jellyfin.Server.Implementations.Tests.Updates ConfigureMembers = true }); _fixture.Inject(http); - _fixture.Inject(new ZipClient()); _installationManager = _fixture.Create(); }