diff --git a/src/NzbDrone.Core.Test/HealthCheck/Checks/UpdateCheckFixture.cs b/src/NzbDrone.Core.Test/HealthCheck/Checks/UpdateCheckFixture.cs index b8a52bea6..a937e4ed9 100644 --- a/src/NzbDrone.Core.Test/HealthCheck/Checks/UpdateCheckFixture.cs +++ b/src/NzbDrone.Core.Test/HealthCheck/Checks/UpdateCheckFixture.cs @@ -22,8 +22,8 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks .Setup(s => s.StartUpFolder) .Returns(@"C:\NzbDrone"); - Mocker.GetMock() - .Setup(c => c.FolderWritable(Moq.It.IsAny())) + Mocker.GetMock() + .Setup(c => c.FolderWritable(It.IsAny())) .Returns(false); Subject.Check().ShouldBeError(); @@ -34,16 +34,45 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks { MonoOnly(); + const string startupFolder = @"/opt/nzbdrone"; + Mocker.GetMock() .Setup(s => s.UpdateAutomatically) .Returns(true); Mocker.GetMock() .Setup(s => s.StartUpFolder) - .Returns(@"/opt/nzbdrone"); + .Returns(startupFolder); - Mocker.GetMock() - .Setup(c => c.FolderWritable(Moq.It.IsAny())) + Mocker.GetMock() + .Setup(c => c.FolderWritable(startupFolder)) + .Returns(false); + + Subject.Check().ShouldBeError(); + } + + [Test] + public void should_return_error_when_ui_folder_is_write_protected_and_update_automatically_is_enabled() + { + MonoOnly(); + + const string startupFolder = @"/opt/nzbdrone"; + const string uiFolder = @"/opt/nzbdrone/UI"; + + Mocker.GetMock() + .Setup(s => s.UpdateAutomatically) + .Returns(true); + + Mocker.GetMock() + .Setup(s => s.StartUpFolder) + .Returns(startupFolder); + + Mocker.GetMock() + .Setup(c => c.FolderWritable(startupFolder)) + .Returns(true); + + Mocker.GetMock() + .Setup(c => c.FolderWritable(uiFolder)) .Returns(false); Subject.Check().ShouldBeError(); @@ -66,8 +95,8 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks .Setup(s => s.StartUpFolder) .Returns(@"/opt/nzbdrone"); - Mocker.GetMock() - .Verify(c => c.FolderWritable(Moq.It.IsAny()), Times.Never()); + Mocker.GetMock() + .Verify(c => c.FolderWritable(It.IsAny()), Times.Never()); Subject.Check().ShouldBeOk(); } diff --git a/src/NzbDrone.Core/HealthCheck/Checks/UpdateCheck.cs b/src/NzbDrone.Core/HealthCheck/Checks/UpdateCheck.cs index e5a928d9d..c0e2d4f8e 100644 --- a/src/NzbDrone.Core/HealthCheck/Checks/UpdateCheck.cs +++ b/src/NzbDrone.Core/HealthCheck/Checks/UpdateCheck.cs @@ -27,15 +27,25 @@ namespace NzbDrone.Core.HealthCheck.Checks public override HealthCheck Check() { + var startupFolder = _appFolderInfo.StartUpFolder; + var uiFolder = Path.Combine(startupFolder, "UI"); + if ((OsInfo.IsWindows || _configFileProvider.UpdateAutomatically) && _configFileProvider.UpdateMechanism == UpdateMechanism.BuiltIn) { - if (!_diskProvider.FolderWritable(_appFolderInfo.StartUpFolder)) + if (!_diskProvider.FolderWritable(startupFolder)) { return new HealthCheck(GetType(), HealthCheckResult.Error, - string.Format("Cannot install update because startup folder '{0}' is not writable by the user '{1}'.", _appFolderInfo.StartUpFolder, Environment.UserName), + string.Format("Cannot install update because startup folder '{0}' is not writable by the user '{1}'.", startupFolder, Environment.UserName), "Cannot install update because startup folder is not writable by the user"); } + + if (!_diskProvider.FolderWritable(uiFolder)) + { + return new HealthCheck(GetType(), HealthCheckResult.Error, + string.Format("Cannot install update because UI folder '{0}' is not writable by the user '{1}'.", uiFolder, Environment.UserName), + "Cannot install update because UI folder is not writable by the user"); + } } if (BuildInfo.BuildDateTime < DateTime.UtcNow.AddDays(-14)) diff --git a/src/NzbDrone.Core/Update/InstallUpdateService.cs b/src/NzbDrone.Core/Update/InstallUpdateService.cs index 3303457b8..2e32e4bc3 100644 --- a/src/NzbDrone.Core/Update/InstallUpdateService.cs +++ b/src/NzbDrone.Core/Update/InstallUpdateService.cs @@ -73,9 +73,17 @@ namespace NzbDrone.Core.Update if (OsInfo.IsWindows || _configFileProvider.UpdateMechanism != UpdateMechanism.Script) { - if (!_diskProvider.FolderWritable(_appFolderInfo.StartUpFolder)) + var startupFolder = _appFolderInfo.StartUpFolder; + var uiFolder = Path.Combine(startupFolder, "UI"); + + if (!_diskProvider.FolderWritable(startupFolder)) { - throw new UpdateFolderNotWritableException("Cannot install update because startup folder '{0}' is not writable by the user '{1}'.", _appFolderInfo.StartUpFolder, Environment.UserName); + throw new UpdateFolderNotWritableException("Cannot install update because startup folder '{0}' is not writable by the user '{1}'.", startupFolder, Environment.UserName); + } + + if (!_diskProvider.FolderWritable(uiFolder)) + { + throw new UpdateFolderNotWritableException("Cannot install update because UI folder '{0}' is not writable by the user '{1}'.", uiFolder, Environment.UserName); } }