New: Prevent automatic update if UI folder is not writable

pull/1095/head
Mark McDowall 9 years ago
parent f38d5de946
commit 9f523bb167

@ -22,8 +22,8 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks
.Setup(s => s.StartUpFolder) .Setup(s => s.StartUpFolder)
.Returns(@"C:\NzbDrone"); .Returns(@"C:\NzbDrone");
Mocker.GetMock<NzbDrone.Common.Disk.IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Setup(c => c.FolderWritable(Moq.It.IsAny<string>())) .Setup(c => c.FolderWritable(It.IsAny<string>()))
.Returns(false); .Returns(false);
Subject.Check().ShouldBeError(); Subject.Check().ShouldBeError();
@ -34,16 +34,45 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks
{ {
MonoOnly(); MonoOnly();
const string startupFolder = @"/opt/nzbdrone";
Mocker.GetMock<IConfigFileProvider>() Mocker.GetMock<IConfigFileProvider>()
.Setup(s => s.UpdateAutomatically) .Setup(s => s.UpdateAutomatically)
.Returns(true); .Returns(true);
Mocker.GetMock<IAppFolderInfo>() Mocker.GetMock<IAppFolderInfo>()
.Setup(s => s.StartUpFolder) .Setup(s => s.StartUpFolder)
.Returns(@"/opt/nzbdrone"); .Returns(startupFolder);
Mocker.GetMock<IDiskProvider>()
.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<IConfigFileProvider>()
.Setup(s => s.UpdateAutomatically)
.Returns(true);
Mocker.GetMock<IAppFolderInfo>()
.Setup(s => s.StartUpFolder)
.Returns(startupFolder);
Mocker.GetMock<IDiskProvider>()
.Setup(c => c.FolderWritable(startupFolder))
.Returns(true);
Mocker.GetMock<NzbDrone.Common.Disk.IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Setup(c => c.FolderWritable(Moq.It.IsAny<string>())) .Setup(c => c.FolderWritable(uiFolder))
.Returns(false); .Returns(false);
Subject.Check().ShouldBeError(); Subject.Check().ShouldBeError();
@ -66,8 +95,8 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks
.Setup(s => s.StartUpFolder) .Setup(s => s.StartUpFolder)
.Returns(@"/opt/nzbdrone"); .Returns(@"/opt/nzbdrone");
Mocker.GetMock<NzbDrone.Common.Disk.IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Verify(c => c.FolderWritable(Moq.It.IsAny<string>()), Times.Never()); .Verify(c => c.FolderWritable(It.IsAny<string>()), Times.Never());
Subject.Check().ShouldBeOk(); Subject.Check().ShouldBeOk();
} }

@ -27,15 +27,25 @@ namespace NzbDrone.Core.HealthCheck.Checks
public override HealthCheck Check() public override HealthCheck Check()
{ {
var startupFolder = _appFolderInfo.StartUpFolder;
var uiFolder = Path.Combine(startupFolder, "UI");
if ((OsInfo.IsWindows || _configFileProvider.UpdateAutomatically) && if ((OsInfo.IsWindows || _configFileProvider.UpdateAutomatically) &&
_configFileProvider.UpdateMechanism == UpdateMechanism.BuiltIn) _configFileProvider.UpdateMechanism == UpdateMechanism.BuiltIn)
{ {
if (!_diskProvider.FolderWritable(_appFolderInfo.StartUpFolder)) if (!_diskProvider.FolderWritable(startupFolder))
{ {
return new HealthCheck(GetType(), HealthCheckResult.Error, 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"); "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)) if (BuildInfo.BuildDateTime < DateTime.UtcNow.AddDays(-14))

@ -73,9 +73,17 @@ namespace NzbDrone.Core.Update
if (OsInfo.IsWindows || _configFileProvider.UpdateMechanism != UpdateMechanism.Script) 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}'.", startupFolder, Environment.UserName);
}
if (!_diskProvider.FolderWritable(uiFolder))
{ {
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 UI folder '{0}' is not writable by the user '{1}'.", uiFolder, Environment.UserName);
} }
} }

Loading…
Cancel
Save