From 7ce8036cabfa03a36c4231be43cdb9623379fef6 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Sat, 14 Oct 2017 23:30:24 +0100 Subject: [PATCH] Fixes the issue with non windows systems unable to unzip the tarball #1460 --- src/Ombi.DependencyInjection/IocExtensions.cs | 1 - src/Ombi.Schedule/JobSetup.cs | 2 +- .../Jobs/Ombi/IOmbiAutomaticUpdater.cs | 2 +- .../Jobs/Ombi/OmbiAutomaticUpdater.cs | 60 ++++++++++++------- src/Ombi.Schedule/Ombi.Schedule.csproj | 1 + src/Ombi/Controllers/JobController.cs | 2 +- 6 files changed, 44 insertions(+), 24 deletions(-) diff --git a/src/Ombi.DependencyInjection/IocExtensions.cs b/src/Ombi.DependencyInjection/IocExtensions.cs index b4b54d4dd..324369680 100644 --- a/src/Ombi.DependencyInjection/IocExtensions.cs +++ b/src/Ombi.DependencyInjection/IocExtensions.cs @@ -42,7 +42,6 @@ using Ombi.Schedule.Jobs.Emby; using Ombi.Schedule.Jobs.Ombi; using Ombi.Schedule.Jobs.Plex; using Ombi.Schedule.Jobs.Sonarr; -using Ombi.Schedule.Ombi; using Ombi.Store.Repository.Requests; using PlexContentCacher = Ombi.Schedule.Jobs.Plex.PlexContentCacher; diff --git a/src/Ombi.Schedule/JobSetup.cs b/src/Ombi.Schedule/JobSetup.cs index 8049afac5..7e39f60ea 100644 --- a/src/Ombi.Schedule/JobSetup.cs +++ b/src/Ombi.Schedule/JobSetup.cs @@ -1,10 +1,10 @@ using Hangfire; using Ombi.Schedule.Jobs; using Ombi.Schedule.Jobs.Emby; +using Ombi.Schedule.Jobs.Ombi; using Ombi.Schedule.Jobs.Plex; using Ombi.Schedule.Jobs.Radarr; using Ombi.Schedule.Jobs.Sonarr; -using Ombi.Schedule.Ombi; namespace Ombi.Schedule { diff --git a/src/Ombi.Schedule/Jobs/Ombi/IOmbiAutomaticUpdater.cs b/src/Ombi.Schedule/Jobs/Ombi/IOmbiAutomaticUpdater.cs index dea7bb121..f40df76eb 100644 --- a/src/Ombi.Schedule/Jobs/Ombi/IOmbiAutomaticUpdater.cs +++ b/src/Ombi.Schedule/Jobs/Ombi/IOmbiAutomaticUpdater.cs @@ -1,7 +1,7 @@ using System.Threading.Tasks; using Hangfire.Server; -namespace Ombi.Schedule.Ombi +namespace Ombi.Schedule.Jobs.Ombi { public interface IOmbiAutomaticUpdater { diff --git a/src/Ombi.Schedule/Jobs/Ombi/OmbiAutomaticUpdater.cs b/src/Ombi.Schedule/Jobs/Ombi/OmbiAutomaticUpdater.cs index 7e2cedb06..ca53e08b4 100644 --- a/src/Ombi.Schedule/Jobs/Ombi/OmbiAutomaticUpdater.cs +++ b/src/Ombi.Schedule/Jobs/Ombi/OmbiAutomaticUpdater.cs @@ -16,8 +16,9 @@ using Ombi.Api.Service; using Ombi.Api.Service.Models; using Ombi.Core.Settings; using Ombi.Helpers; -using Ombi.Schedule.Ombi; using Ombi.Settings.Settings.Models; +using SharpCompress.Readers; +using SharpCompress.Readers.Tar; namespace Ombi.Schedule.Jobs.Ombi { @@ -44,11 +45,11 @@ namespace Ombi.Schedule.Jobs.Ombi } public async Task UpdateAvailable(string branch, string currentVersion) { - - var updates = await OmbiService.GetUpdates(branch); - var serverVersion = updates.UpdateVersionString; - return !serverVersion.Equals(currentVersion, StringComparison.CurrentCultureIgnoreCase); - + + var updates = await OmbiService.GetUpdates(branch); + var serverVersion = updates.UpdateVersionString; + return !serverVersion.Equals(currentVersion, StringComparison.CurrentCultureIgnoreCase); + } public async Task Update(PerformContext c) @@ -153,21 +154,8 @@ namespace Ombi.Schedule.Jobs.Ombi } // Extract it Ctx.WriteLine("Extracting ZIP"); - using (var files = ZipFile.OpenRead(zipDir)) - { - // Temp Path - Directory.CreateDirectory(tempPath); - foreach (var entry in files.Entries) - { - if (entry.FullName.Contains("/")) - { - var path = Path.GetDirectoryName(Path.Combine(tempPath, entry.FullName)); - Directory.CreateDirectory(path); - } + Extract(zipDir, tempPath, extension); - entry.ExtractToFile(Path.Combine(tempPath, entry.FullName)); - } - } Ctx.WriteLine("Finished Extracting files"); Ctx.WriteLine("Starting the Ombi.Updater process"); var updaterExtension = string.Empty; @@ -197,6 +185,38 @@ namespace Ombi.Schedule.Jobs.Ombi } } + private void Extract(string zipDir, string tempPath, string osPlat) + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + using (var files = ZipFile.OpenRead(zipDir)) + { + // Temp Path + Directory.CreateDirectory(tempPath); + foreach (var entry in files.Entries) + { + if (entry.FullName.Contains("/")) + { + var path = Path.GetDirectoryName(Path.Combine(tempPath, entry.FullName)); + Directory.CreateDirectory(path); + } + + entry.ExtractToFile(Path.Combine(tempPath, entry.FullName)); + } + } + } + else + { + // Something else! + using (var stream = File.Open(zipDir, FileMode.Open)) + using (var files = TarReader.Open(stream)) + { + Directory.CreateDirectory(tempPath); + files.WriteAllToDirectory(tempPath, new ExtractionOptions { Overwrite = true }); + } + } + } + public static async Task DownloadAsync(string requestUri, string filename, PerformContext ctx) { using (var client = new WebClient()) diff --git a/src/Ombi.Schedule/Ombi.Schedule.csproj b/src/Ombi.Schedule/Ombi.Schedule.csproj index 91bcfb595..ed6db8bbd 100644 --- a/src/Ombi.Schedule/Ombi.Schedule.csproj +++ b/src/Ombi.Schedule/Ombi.Schedule.csproj @@ -17,6 +17,7 @@ + diff --git a/src/Ombi/Controllers/JobController.cs b/src/Ombi/Controllers/JobController.cs index 51339344c..fc25a0ae2 100644 --- a/src/Ombi/Controllers/JobController.cs +++ b/src/Ombi/Controllers/JobController.cs @@ -7,8 +7,8 @@ using Ombi.Api.Service; using Ombi.Attributes; using Ombi.Helpers; using Ombi.Schedule.Jobs.Emby; +using Ombi.Schedule.Jobs.Ombi; using Ombi.Schedule.Jobs.Plex; -using Ombi.Schedule.Ombi; namespace Ombi.Controllers {