1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00

Fixed: mono version check will check running mono version instead running another version

This commit is contained in:
Mark McDowall 2014-07-24 23:37:32 -07:00
parent 41583a8c67
commit a4500606a9
6 changed files with 72 additions and 42 deletions

View File

@ -112,6 +112,7 @@
<Compile Include="Messaging\IEvent.cs" />
<Compile Include="Messaging\IMessage.cs" />
<Compile Include="PathEqualityComparer.cs" />
<Compile Include="Processes\IRuntimeProvider.cs" />
<Compile Include="Processes\PidFileProvider.cs" />
<Compile Include="Processes\ProcessOutput.cs" />
<Compile Include="RateGate.cs" />

View File

@ -0,0 +1,9 @@
using System;
namespace NzbDrone.Common.Processes
{
public interface IRuntimeProvider
{
String GetVersion();
}
}

View File

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using NUnit.Framework;
using NzbDrone.Common.Processes;
using NzbDrone.Core.HealthCheck.Checks;
@ -18,16 +17,9 @@ public void Setup()
private void GivenOutput(string version)
{
Mocker.GetMock<IProcessProvider>()
.Setup(s => s.StartAndCapture("mono", "--version"))
.Returns(new ProcessOutput
{
Standard = new List<string>
{
String.Format("Mono JIT compiler version {0} (Debian {0}-8)", version),
"Copyright (C) 2002-2011 Novell, Inc, Xamarin, Inc and Contributors. www.mono-project.com"
}
});
Mocker.GetMock<IRuntimeProvider>()
.Setup(s => s.GetVersion())
.Returns(String.Format("{0} (tarball Wed Sep 25 16:35:44 CDT 2013)", version));
}
[Test]
@ -46,6 +38,14 @@ public void should_return_warning_when_mono_2_10_8()
Subject.Check().ShouldBeWarning();
}
[Test]
public void should_return_warning_when_mono_2_10_2()
{
GivenOutput("2.10.2");
Subject.Check().ShouldBeWarning();
}
[Test]
public void should_return_ok_when_mono_3_2()
{
@ -85,22 +85,5 @@ public void should_return_ok_when_mono_3_6_1()
Subject.Check().ShouldBeOk();
}
[Test]
public void should_return_ok_when_mono_3_6_1_with_custom_output()
{
Mocker.GetMock<IProcessProvider>()
.Setup(s => s.StartAndCapture("mono", "--version"))
.Returns(new ProcessOutput
{
Standard = new List<string>
{
"Mono JIT compiler version 3.6.1 (master/fce3972 Fri Jul 4 01:12:43 CEST 2014)",
"Copyright (C) 2002-2011 Novell, Inc, Xamarin, Inc and Contributors. www.mono-project.com"
}
});
Subject.Check().ShouldBeOk();
}
}
}

View File

@ -8,13 +8,13 @@ namespace NzbDrone.Core.HealthCheck.Checks
{
public class MonoVersionCheck : HealthCheckBase
{
private readonly IProcessProvider _processProvider;
private readonly IRuntimeProvider _runtimeProvider;
private readonly Logger _logger;
private static readonly Regex VersionRegex = new Regex(@"(?<=\W)(?<version>\d+\.\d+\.\d+(\.\d+)?)(?=\W)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
public MonoVersionCheck(IProcessProvider processProvider, Logger logger)
public MonoVersionCheck(IRuntimeProvider runtimeProvider, Logger logger)
{
_processProvider = processProvider;
_runtimeProvider = runtimeProvider;
_logger = logger;
}
@ -25,21 +25,16 @@ public override HealthCheck Check()
return new HealthCheck(GetType());
}
var output = _processProvider.StartAndCapture("mono", "--version");
var versionMatch = VersionRegex.Match(_runtimeProvider.GetVersion());
foreach (var line in output.Standard)
if (versionMatch.Success)
{
var versionMatch = VersionRegex.Match(line);
var version = new Version(versionMatch.Groups["version"].Value);
if (versionMatch.Success)
if (version >= new Version(3, 2))
{
var version = new Version(versionMatch.Groups["version"].Value);
if (version >= new Version(3, 2))
{
_logger.Debug("mono version is 3.2 or better: {0}", version.ToString());
return new HealthCheck(GetType());
}
_logger.Debug("mono version is 3.2 or better: {0}", version.ToString());
return new HealthCheck(GetType());
}
}

View File

@ -0,0 +1,41 @@
using System;
using System.Reflection;
using NLog;
using NzbDrone.Common.Processes;
namespace NzbDrone.Mono
{
public class MonoRuntimeProvider : IRuntimeProvider
{
private readonly Logger _logger;
public MonoRuntimeProvider(Logger logger)
{
_logger = logger;
}
public String GetVersion()
{
try
{
var type = Type.GetType("Mono.Runtime");
if (type != null)
{
var displayName = type.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static);
if (displayName != null)
{
return displayName.Invoke(null, null).ToString();
}
}
}
catch (Exception ex)
{
_logger.ErrorException("Unable to get mono version: " + ex.Message, ex);
}
return String.Empty;
}
}
}

View File

@ -70,6 +70,7 @@
<ItemGroup>
<Compile Include="DiskProvider.cs" />
<Compile Include="LinuxPermissionsException.cs" />
<Compile Include="MonoRuntimeProvider.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>