diff --git a/src/NzbDrone.Common/ArchiveProvider.cs b/src/NzbDrone.Common/ArchiveProvider.cs index 629d3c6bb..f15cc6899 100644 --- a/src/NzbDrone.Common/ArchiveProvider.cs +++ b/src/NzbDrone.Common/ArchiveProvider.cs @@ -1,8 +1,11 @@ using System; using System.IO; using ICSharpCode.SharpZipLib.Core; +using ICSharpCode.SharpZipLib.GZip; +using ICSharpCode.SharpZipLib.Tar; using ICSharpCode.SharpZipLib.Zip; using NLog; +using NzbDrone.Common.EnvironmentInfo; namespace NzbDrone.Common { @@ -24,6 +27,21 @@ namespace NzbDrone.Common { _logger.Trace("Extracting archive [{0}] to [{1}]", compressedFile, destination); + if (OsInfo.IsWindows) + { + ExtractZip(compressedFile, destination); + } + + else + { + ExtractTgz(compressedFile, destination); + } + + _logger.Trace("Extraction complete."); + } + + private void ExtractZip(string compressedFile, string destination) + { using (var fileStream = File.OpenRead(compressedFile)) { var zipFile = new ZipFile(fileStream); @@ -64,8 +82,19 @@ namespace NzbDrone.Common } } } + } - _logger.Trace("Extraction complete."); + private void ExtractTgz(string compressedFile, string destination) + { + Stream inStream = File.OpenRead(compressedFile); + Stream gzipStream = new GZipInputStream(inStream); + + TarArchive tarArchive = TarArchive.CreateInputTarArchive(gzipStream); + tarArchive.ExtractContents(destination); + tarArchive.Close(); + + gzipStream.Close(); + inStream.Close(); } private void OnZipError(TestStatus status, string message) diff --git a/src/NzbDrone.Core.Test/UpdateTests/UpdateServiceFixture.cs b/src/NzbDrone.Core.Test/UpdateTests/UpdateServiceFixture.cs index f02a8368d..db7f7c530 100644 --- a/src/NzbDrone.Core.Test/UpdateTests/UpdateServiceFixture.cs +++ b/src/NzbDrone.Core.Test/UpdateTests/UpdateServiceFixture.cs @@ -21,17 +21,30 @@ namespace NzbDrone.Core.Test.UpdateTests { private string _sandboxFolder; - private readonly UpdatePackage _updatePackage = new UpdatePackage - { - FileName = "NzbDrone.develop.2.0.0.zip", - Url = "http://update.nzbdrone.com/v2/develop/windows/NzbDrone.develop.zip", - Version = new Version("2.0.0") - }; + private UpdatePackage _updatePackage; [SetUp] public void Setup() { - WindowsOnly(); + if (OsInfo.IsLinux) + { + _updatePackage = new UpdatePackage + { + FileName = "NzbDrone.develop.2.0.0.0.tar.gz", + Url = "http://update.nzbdrone.com/v2/develop/mono/NzbDrone.develop.tar.gz", + Version = new Version("2.0.0.0") + }; + } + + else + { + _updatePackage = new UpdatePackage + { + FileName = "NzbDrone.develop.2.0.0.0.zip", + Url = "http://update.nzbdrone.com/v2/develop/windows/NzbDrone.develop.zip", + Version = new Version("2.0.0.0") + }; + } Mocker.GetMock().SetupGet(c => c.TempFolder).Returns(TempFolder); Mocker.GetMock().Setup(c => c.AvailableUpdate()).Returns(_updatePackage); @@ -42,7 +55,6 @@ namespace NzbDrone.Core.Test.UpdateTests } - [Test] public void should_delete_sandbox_before_update_if_folder_exists() {