From 071839fa8656c54f0da41c54805803242e5b1391 Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Tue, 27 Jan 2015 20:32:48 +0100 Subject: [PATCH] Removed InstallUpdate, instead manually triggering ApplicationUpdate. --- .../UpdateTests/UpdateServiceFixture.cs | 8 +++- src/NzbDrone.Core/NzbDrone.Core.csproj | 1 - .../Update/Commands/InstallUpdateCommand.cs | 17 ------- .../Update/InstallUpdateService.cs | 47 ++++++++----------- .../Update/UpdateCheckService.cs | 14 +----- src/UI/System/Update/UpdateItemView.js | 2 +- .../System/Update/UpdateItemViewTemplate.hbs | 7 ++- 7 files changed, 33 insertions(+), 63 deletions(-) delete mode 100644 src/NzbDrone.Core/Update/Commands/InstallUpdateCommand.cs diff --git a/src/NzbDrone.Core.Test/UpdateTests/UpdateServiceFixture.cs b/src/NzbDrone.Core.Test/UpdateTests/UpdateServiceFixture.cs index 981fc894b..3800751e7 100644 --- a/src/NzbDrone.Core.Test/UpdateTests/UpdateServiceFixture.cs +++ b/src/NzbDrone.Core.Test/UpdateTests/UpdateServiceFixture.cs @@ -61,6 +61,10 @@ namespace NzbDrone.Core.Test.UpdateTests Mocker.GetMock().Setup(c => c.GetCurrentProcess()).Returns(new ProcessInfo { Id = 12 }); Mocker.GetMock().Setup(c => c.ExecutingApplication).Returns(@"C:\Test\NzbDrone.exe"); + Mocker.GetMock() + .SetupGet(s => s.UpdateAutomatically) + .Returns(true); + Mocker.GetMock() .Setup(c => c.FolderWritable(It.IsAny())) .Returns(true); @@ -289,7 +293,7 @@ namespace NzbDrone.Core.Test.UpdateTests var updateArchive = Path.Combine(_sandboxFolder, _updatePackage.FileName); - Subject.Execute(new InstallUpdateCommand() { UpdatePackage = _updatePackage }); + Subject.Execute(new ApplicationUpdateCommand()); Mocker.GetMock().Verify(c => c.DownloadFile(_updatePackage.Url, updateArchive), Times.Never()); ExceptionVerification.ExpectedErrors(1); @@ -300,7 +304,7 @@ namespace NzbDrone.Core.Test.UpdateTests { _updatePackage.Branch = "fake"; - Subject.Execute(new InstallUpdateCommand() { UpdatePackage = _updatePackage }); + Subject.Execute(new ApplicationUpdateCommand()); Mocker.GetMock() .Verify(v => v.SaveConfigDictionary(It.Is>(d => d.ContainsKey("Branch") && (string)d["Branch"] == "fake")), Times.Once()); diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index ae7c50e7f..718d27848 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -852,7 +852,6 @@ - diff --git a/src/NzbDrone.Core/Update/Commands/InstallUpdateCommand.cs b/src/NzbDrone.Core/Update/Commands/InstallUpdateCommand.cs deleted file mode 100644 index 890a31199..000000000 --- a/src/NzbDrone.Core/Update/Commands/InstallUpdateCommand.cs +++ /dev/null @@ -1,17 +0,0 @@ -using NzbDrone.Core.Messaging.Commands; - -namespace NzbDrone.Core.Update.Commands -{ - public class InstallUpdateCommand : Command - { - public UpdatePackage UpdatePackage { get; set; } - - public override bool SendUpdatesToClient - { - get - { - return true; - } - } - } -} diff --git a/src/NzbDrone.Core/Update/InstallUpdateService.cs b/src/NzbDrone.Core/Update/InstallUpdateService.cs index 300eb6f48..2d0d1c491 100644 --- a/src/NzbDrone.Core/Update/InstallUpdateService.cs +++ b/src/NzbDrone.Core/Update/InstallUpdateService.cs @@ -17,7 +17,7 @@ using NzbDrone.Core.Update.Commands; namespace NzbDrone.Core.Update { - public class InstallUpdateService : IExecute, IExecute + public class InstallUpdateService : IExecute { private readonly ICheckUpdateService _checkUpdateService; private readonly Logger _logger; @@ -176,15 +176,31 @@ namespace NzbDrone.Core.Update if (_appFolderInfo.StartUpFolder.IsParentPath(_appFolderInfo.AppDataFolder) || _appFolderInfo.StartUpFolder.PathEquals(_appFolderInfo.AppDataFolder)) { - throw new UpdateFailedException("You Sonarr configuration ('{0}') is being stored in application folder ('{1}') which will cause data lost during the upgrade. Please remove any symlinks or redirects before trying again.", _appFolderInfo.AppDataFolder, _appFolderInfo.StartUpFolder); + throw new UpdateFailedException("Your Sonarr configuration '{0}' is being stored in application folder '{1}' which will cause data lost during the upgrade. Please remove any symlinks or redirects before trying again.", _appFolderInfo.AppDataFolder, _appFolderInfo.StartUpFolder); } } - private void ExecuteInstallUpdate(Command message, UpdatePackage package) + public void Execute(ApplicationUpdateCommand message) { + _logger.ProgressDebug("Checking for updates"); + + var latestAvailable = _checkUpdateService.AvailableUpdate(); + + if (latestAvailable == null) + { + _logger.ProgressDebug("No update available."); + return; + } + + if (OsInfo.IsNotWindows && !_configFileProvider.UpdateAutomatically && !message.Manual) + { + _logger.ProgressDebug("Auto-update not enabled, not installing available update."); + return; + } + try { - InstallUpdate(package); + InstallUpdate(latestAvailable); message.Completed("Restarting Sonarr to apply updates"); } @@ -204,28 +220,5 @@ namespace NzbDrone.Core.Update message.Failed(ex); } } - - public void Execute(ApplicationUpdateCommand message) - { - _logger.ProgressDebug("Checking for updates"); - var latestAvailable = _checkUpdateService.AvailableUpdate(); - - if (latestAvailable != null) - { - ExecuteInstallUpdate(message, latestAvailable); - } - } - - public void Execute(InstallUpdateCommand message) - { - var latestAvailable = _checkUpdateService.AvailableUpdate(); - - if (latestAvailable == null || latestAvailable.Hash != message.UpdatePackage.Hash) - { - throw new ApplicationException("Unknown or invalid update specified"); - } - - ExecuteInstallUpdate(message, latestAvailable); - } } } diff --git a/src/NzbDrone.Core/Update/UpdateCheckService.cs b/src/NzbDrone.Core/Update/UpdateCheckService.cs index f17b72dcc..ad8ffc247 100644 --- a/src/NzbDrone.Core/Update/UpdateCheckService.cs +++ b/src/NzbDrone.Core/Update/UpdateCheckService.cs @@ -31,19 +31,7 @@ namespace NzbDrone.Core.Update public UpdatePackage AvailableUpdate() { - var latestAvailable = _updatePackageProvider.GetLatestUpdate(_configFileProvider.Branch, BuildInfo.Version); - - if (OsInfo.IsNotWindows && !_configFileProvider.UpdateAutomatically) - { - return null; - } - - if (latestAvailable == null) - { - _logger.ProgressDebug("No update available."); - } - - return latestAvailable; + return _updatePackageProvider.GetLatestUpdate(_configFileProvider.Branch, BuildInfo.Version); } } } \ No newline at end of file diff --git a/src/UI/System/Update/UpdateItemView.js b/src/UI/System/Update/UpdateItemView.js index 48ee09de4..d21104de6 100644 --- a/src/UI/System/Update/UpdateItemView.js +++ b/src/UI/System/Update/UpdateItemView.js @@ -13,7 +13,7 @@ module.exports = Marionette.ItemView.extend({ } this.updating = true; var self = this; - var promise = CommandController.Execute('installUpdate', {updatePackage : this.model.toJSON()}); + var promise = CommandController.Execute('applicationUpdate'); promise.done(function(){ window.setTimeout(function(){ self.updating = false; diff --git a/src/UI/System/Update/UpdateItemViewTemplate.hbs b/src/UI/System/Update/UpdateItemViewTemplate.hbs index aecefacbd..f9a2dce19 100644 --- a/src/UI/System/Update/UpdateItemViewTemplate.hbs +++ b/src/UI/System/Update/UpdateItemViewTemplate.hbs @@ -5,14 +5,17 @@ - {{ShortDate releaseDate}} + {{#unless_eq branch compare="master"}} + {{branch}} + {{/unless_eq}} {{#if installed}} Installed {{else}} {{#if latest}} {{#if installable}} - Install + Install Latest {{else}} - Install + Install Latest {{/if}} {{/if}} {{/if}}