mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-20 21:43:33 -07:00
Cleanup dual target and mono code
This commit is contained in:
parent
64d15e3e94
commit
117436b199
13 changed files with 24 additions and 55 deletions
|
@ -70,7 +70,7 @@ namespace Lidarr.Api.V1.System
|
||||||
AppData = _appFolderInfo.GetAppDataPath(),
|
AppData = _appFolderInfo.GetAppDataPath(),
|
||||||
OsName = _osInfo.Name,
|
OsName = _osInfo.Name,
|
||||||
OsVersion = _osInfo.Version,
|
OsVersion = _osInfo.Version,
|
||||||
IsNetCore = PlatformInfo.IsNetCore,
|
IsNetCore = true,
|
||||||
IsLinux = OsInfo.IsLinux,
|
IsLinux = OsInfo.IsLinux,
|
||||||
IsOsx = OsInfo.IsOsx,
|
IsOsx = OsInfo.IsOsx,
|
||||||
IsWindows = OsInfo.IsWindows,
|
IsWindows = OsInfo.IsWindows,
|
||||||
|
@ -82,7 +82,7 @@ namespace Lidarr.Api.V1.System
|
||||||
MigrationVersion = _database.Migration,
|
MigrationVersion = _database.Migration,
|
||||||
UrlBase = _configFileProvider.UrlBase,
|
UrlBase = _configFileProvider.UrlBase,
|
||||||
RuntimeVersion = _platformInfo.Version,
|
RuntimeVersion = _platformInfo.Version,
|
||||||
RuntimeName = PlatformInfo.Platform,
|
RuntimeName = "netcore",
|
||||||
StartTime = _runtimeInfo.StartTime,
|
StartTime = _runtimeInfo.StartTime,
|
||||||
PackageVersion = _deploymentInfoProvider.PackageVersion,
|
PackageVersion = _deploymentInfoProvider.PackageVersion,
|
||||||
PackageAuthor = _deploymentInfoProvider.PackageAuthor,
|
PackageAuthor = _deploymentInfoProvider.PackageAuthor,
|
||||||
|
|
|
@ -279,7 +279,7 @@ namespace NzbDrone.Common.Test
|
||||||
[Test]
|
[Test]
|
||||||
public void GetUpdateClientExePath()
|
public void GetUpdateClientExePath()
|
||||||
{
|
{
|
||||||
GetIAppDirectoryInfo().GetUpdateClientExePath(PlatformType.DotNet).Should().BeEquivalentTo(@"C:\Temp\lidarr_update\Lidarr.Update.exe".AsOsAgnostic());
|
GetIAppDirectoryInfo().GetUpdateClientExePath().Should().BeEquivalentTo(@"C:\Temp\lidarr_update\Lidarr.Update".AsOsAgnostic().ProcessNameToExe());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
|
|
@ -2,13 +2,6 @@ using System;
|
||||||
|
|
||||||
namespace NzbDrone.Common.EnvironmentInfo
|
namespace NzbDrone.Common.EnvironmentInfo
|
||||||
{
|
{
|
||||||
public enum PlatformType
|
|
||||||
{
|
|
||||||
DotNet = 0,
|
|
||||||
Mono = 1,
|
|
||||||
NetCore = 2
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface IPlatformInfo
|
public interface IPlatformInfo
|
||||||
{
|
{
|
||||||
Version Version { get; }
|
Version Version { get; }
|
||||||
|
@ -16,31 +9,18 @@ namespace NzbDrone.Common.EnvironmentInfo
|
||||||
|
|
||||||
public class PlatformInfo : IPlatformInfo
|
public class PlatformInfo : IPlatformInfo
|
||||||
{
|
{
|
||||||
private static PlatformType _platform;
|
|
||||||
private static Version _version;
|
private static Version _version;
|
||||||
|
|
||||||
static PlatformInfo()
|
static PlatformInfo()
|
||||||
{
|
{
|
||||||
_platform = PlatformType.NetCore;
|
|
||||||
_version = Environment.Version;
|
_version = Environment.Version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PlatformType Platform => _platform;
|
|
||||||
public static bool IsDotNet => Platform == PlatformType.DotNet;
|
|
||||||
public static bool IsNetCore => Platform == PlatformType.NetCore;
|
|
||||||
|
|
||||||
public static string PlatformName
|
public static string PlatformName
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (IsDotNet)
|
return ".NET";
|
||||||
{
|
|
||||||
return ".NET";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return ".NET Core";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -266,9 +266,9 @@ namespace NzbDrone.Common.Extensions
|
||||||
return substring.Substring(0, lastSeparatorIndex);
|
return substring.Substring(0, lastSeparatorIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string ProcessNameToExe(this string processName, PlatformType runtime)
|
public static string ProcessNameToExe(this string processName)
|
||||||
{
|
{
|
||||||
if (OsInfo.IsWindows || runtime != PlatformType.NetCore)
|
if (OsInfo.IsWindows)
|
||||||
{
|
{
|
||||||
processName += ".exe";
|
processName += ".exe";
|
||||||
}
|
}
|
||||||
|
@ -276,11 +276,6 @@ namespace NzbDrone.Common.Extensions
|
||||||
return processName;
|
return processName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string ProcessNameToExe(this string processName)
|
|
||||||
{
|
|
||||||
return processName.ProcessNameToExe(PlatformInfo.Platform);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string GetAppDataPath(this IAppFolderInfo appFolderInfo)
|
public static string GetAppDataPath(this IAppFolderInfo appFolderInfo)
|
||||||
{
|
{
|
||||||
return appFolderInfo.AppDataFolder;
|
return appFolderInfo.AppDataFolder;
|
||||||
|
@ -346,9 +341,9 @@ namespace NzbDrone.Common.Extensions
|
||||||
return Path.Combine(GetUpdatePackageFolder(appFolderInfo), UPDATE_CLIENT_FOLDER_NAME);
|
return Path.Combine(GetUpdatePackageFolder(appFolderInfo), UPDATE_CLIENT_FOLDER_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetUpdateClientExePath(this IAppFolderInfo appFolderInfo, PlatformType runtime)
|
public static string GetUpdateClientExePath(this IAppFolderInfo appFolderInfo)
|
||||||
{
|
{
|
||||||
return Path.Combine(GetUpdateSandboxFolder(appFolderInfo), UPDATE_CLIENT_EXE_NAME).ProcessNameToExe(runtime);
|
return Path.Combine(GetUpdateSandboxFolder(appFolderInfo), UPDATE_CLIENT_EXE_NAME).ProcessNameToExe();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetDatabase(this IAppFolderInfo appFolderInfo)
|
public static string GetDatabase(this IAppFolderInfo appFolderInfo)
|
||||||
|
|
|
@ -69,7 +69,7 @@ namespace NzbDrone.Core.Test.UpdateTests
|
||||||
.Returns(true);
|
.Returns(true);
|
||||||
|
|
||||||
Mocker.GetMock<IDiskProvider>()
|
Mocker.GetMock<IDiskProvider>()
|
||||||
.Setup(v => v.FileExists(It.Is<string>(s => s.EndsWith("Lidarr.Update.exe"))))
|
.Setup(v => v.FileExists(It.Is<string>(s => s.EndsWith("Lidarr.Update".ProcessNameToExe()))))
|
||||||
.Returns(true);
|
.Returns(true);
|
||||||
|
|
||||||
_sandboxFolder = Mocker.GetMock<IAppFolderInfo>().Object.GetUpdateSandboxFolder();
|
_sandboxFolder = Mocker.GetMock<IAppFolderInfo>().Object.GetUpdateSandboxFolder();
|
||||||
|
@ -165,7 +165,7 @@ namespace NzbDrone.Core.Test.UpdateTests
|
||||||
public void should_return_with_warning_if_updater_doesnt_exists()
|
public void should_return_with_warning_if_updater_doesnt_exists()
|
||||||
{
|
{
|
||||||
Mocker.GetMock<IDiskProvider>()
|
Mocker.GetMock<IDiskProvider>()
|
||||||
.Setup(v => v.FileExists(It.Is<string>(s => s.EndsWith("Lidarr.Update.exe"))))
|
.Setup(v => v.FileExists(It.Is<string>(s => s.EndsWith("Lidarr.Update".ProcessNameToExe()))))
|
||||||
.Returns(false);
|
.Returns(false);
|
||||||
|
|
||||||
Subject.Execute(new ApplicationUpdateCommand());
|
Subject.Execute(new ApplicationUpdateCommand());
|
||||||
|
|
|
@ -52,7 +52,7 @@ namespace NzbDrone.Core.HealthCheck
|
||||||
.AddQueryParam("version", BuildInfo.Version)
|
.AddQueryParam("version", BuildInfo.Version)
|
||||||
.AddQueryParam("os", OsInfo.Os.ToString().ToLowerInvariant())
|
.AddQueryParam("os", OsInfo.Os.ToString().ToLowerInvariant())
|
||||||
.AddQueryParam("arch", RuntimeInformation.OSArchitecture)
|
.AddQueryParam("arch", RuntimeInformation.OSArchitecture)
|
||||||
.AddQueryParam("runtime", PlatformInfo.Platform.ToString().ToLowerInvariant())
|
.AddQueryParam("runtime", "netcore")
|
||||||
.AddQueryParam("branch", _configFileProvider.Branch)
|
.AddQueryParam("branch", _configFileProvider.Branch)
|
||||||
.Build();
|
.Build();
|
||||||
try
|
try
|
||||||
|
|
|
@ -146,7 +146,7 @@ namespace NzbDrone.Core.Update
|
||||||
_logger.Info("Preparing client");
|
_logger.Info("Preparing client");
|
||||||
_diskTransferService.TransferFolder(_appFolderInfo.GetUpdateClientFolder(), updateSandboxFolder, TransferMode.Move);
|
_diskTransferService.TransferFolder(_appFolderInfo.GetUpdateClientFolder(), updateSandboxFolder, TransferMode.Move);
|
||||||
|
|
||||||
var updateClientExePath = _appFolderInfo.GetUpdateClientExePath(updatePackage.Runtime);
|
var updateClientExePath = _appFolderInfo.GetUpdateClientExePath();
|
||||||
|
|
||||||
if (!_diskProvider.FileExists(updateClientExePath))
|
if (!_diskProvider.FileExists(updateClientExePath))
|
||||||
{
|
{
|
||||||
|
@ -155,7 +155,7 @@ namespace NzbDrone.Core.Update
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set executable flag on update app
|
// Set executable flag on update app
|
||||||
if (OsInfo.IsOsx || (OsInfo.IsLinux && PlatformInfo.IsNetCore))
|
if (OsInfo.IsOsx || OsInfo.IsLinux)
|
||||||
{
|
{
|
||||||
_diskProvider.SetFilePermissions(updateClientExePath, "755", null);
|
_diskProvider.SetFilePermissions(updateClientExePath, "755", null);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using NzbDrone.Common.EnvironmentInfo;
|
using NzbDrone.Common.EnvironmentInfo;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Update
|
namespace NzbDrone.Core.Update
|
||||||
|
@ -12,6 +12,5 @@ namespace NzbDrone.Core.Update
|
||||||
public UpdateChanges Changes { get; set; }
|
public UpdateChanges Changes { get; set; }
|
||||||
public string Hash { get; set; }
|
public string Hash { get; set; }
|
||||||
public string Branch { get; set; }
|
public string Branch { get; set; }
|
||||||
public PlatformType Runtime { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using FluentValidation.Validators;
|
||||||
using NzbDrone.Common.Cloud;
|
using NzbDrone.Common.Cloud;
|
||||||
using NzbDrone.Common.EnvironmentInfo;
|
using NzbDrone.Common.EnvironmentInfo;
|
||||||
using NzbDrone.Common.Http;
|
using NzbDrone.Common.Http;
|
||||||
|
@ -36,7 +37,7 @@ namespace NzbDrone.Core.Update
|
||||||
.AddQueryParam("version", currentVersion)
|
.AddQueryParam("version", currentVersion)
|
||||||
.AddQueryParam("os", OsInfo.Os.ToString().ToLowerInvariant())
|
.AddQueryParam("os", OsInfo.Os.ToString().ToLowerInvariant())
|
||||||
.AddQueryParam("arch", RuntimeInformation.OSArchitecture)
|
.AddQueryParam("arch", RuntimeInformation.OSArchitecture)
|
||||||
.AddQueryParam("runtime", PlatformInfo.Platform.ToString().ToLowerInvariant())
|
.AddQueryParam("runtime", "netcore")
|
||||||
.AddQueryParam("runtimeVer", _platformInfo.Version)
|
.AddQueryParam("runtimeVer", _platformInfo.Version)
|
||||||
.SetSegment("branch", branch);
|
.SetSegment("branch", branch);
|
||||||
|
|
||||||
|
@ -63,7 +64,7 @@ namespace NzbDrone.Core.Update
|
||||||
.AddQueryParam("version", currentVersion)
|
.AddQueryParam("version", currentVersion)
|
||||||
.AddQueryParam("os", OsInfo.Os.ToString().ToLowerInvariant())
|
.AddQueryParam("os", OsInfo.Os.ToString().ToLowerInvariant())
|
||||||
.AddQueryParam("arch", RuntimeInformation.OSArchitecture)
|
.AddQueryParam("arch", RuntimeInformation.OSArchitecture)
|
||||||
.AddQueryParam("runtime", PlatformInfo.Platform.ToString().ToLowerInvariant())
|
.AddQueryParam("runtime", "netcore")
|
||||||
.AddQueryParam("runtimeVer", _platformInfo.Version)
|
.AddQueryParam("runtimeVer", _platformInfo.Version)
|
||||||
.SetSegment("branch", branch);
|
.SetSegment("branch", branch);
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ namespace NzbDrone.Mono.Test.DiskProviderTests
|
||||||
.Returns<string>(s => s);
|
.Returns<string>(s => s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Ignore("Docker")]
|
||||||
[Test]
|
[Test]
|
||||||
public void should_be_able_to_check_space_on_ramdrive()
|
public void should_be_able_to_check_space_on_ramdrive()
|
||||||
{
|
{
|
||||||
|
|
|
@ -263,9 +263,7 @@ namespace NzbDrone.Mono.Disk
|
||||||
newFile.CreateSymbolicLinkTo(fullPath);
|
newFile.CreateSymbolicLinkTo(fullPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (((PlatformInfo.Platform == PlatformType.Mono && PlatformInfo.GetVersion() >= new Version(6, 0)) ||
|
else if (!FileExists(destination) || overwrite)
|
||||||
PlatformInfo.Platform == PlatformType.NetCore) &&
|
|
||||||
(!FileExists(destination) || overwrite))
|
|
||||||
{
|
{
|
||||||
TransferFilePatched(source, destination, overwrite, false);
|
TransferFilePatched(source, destination, overwrite, false);
|
||||||
}
|
}
|
||||||
|
@ -310,14 +308,9 @@ namespace NzbDrone.Mono.Disk
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ((PlatformInfo.Platform == PlatformType.Mono && PlatformInfo.GetVersion() >= new Version(6, 0)) ||
|
|
||||||
PlatformInfo.Platform == PlatformType.NetCore)
|
|
||||||
{
|
|
||||||
TransferFilePatched(source, destination, false, true);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
base.MoveFileInternal(source, destination);
|
TransferFilePatched(source, destination, false, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -329,7 +322,7 @@ namespace NzbDrone.Mono.Disk
|
||||||
// Catch the exception and attempt to handle these edgecases
|
// Catch the exception and attempt to handle these edgecases
|
||||||
|
|
||||||
// Mono 6.x till 6.10 doesn't properly try use rename first.
|
// Mono 6.x till 6.10 doesn't properly try use rename first.
|
||||||
if (move && (PlatformInfo.Platform == PlatformType.NetCore))
|
if (move)
|
||||||
{
|
{
|
||||||
if (Syscall.lstat(source, out var sourcestat) == 0 &&
|
if (Syscall.lstat(source, out var sourcestat) == 0 &&
|
||||||
Syscall.lstat(destination, out var deststat) != 0 &&
|
Syscall.lstat(destination, out var deststat) != 0 &&
|
||||||
|
@ -357,7 +350,7 @@ namespace NzbDrone.Mono.Disk
|
||||||
var dstInfo = new FileInfo(destination);
|
var dstInfo = new FileInfo(destination);
|
||||||
var exists = dstInfo.Exists && srcInfo.Exists;
|
var exists = dstInfo.Exists && srcInfo.Exists;
|
||||||
|
|
||||||
if (PlatformInfo.Platform == PlatformType.NetCore && exists && dstInfo.Length == srcInfo.Length)
|
if (exists && dstInfo.Length == srcInfo.Length)
|
||||||
{
|
{
|
||||||
// mono 6.0, mono 6.4 and netcore 3.1 bug: full length file since utime and chmod happens at the end
|
// mono 6.0, mono 6.4 and netcore 3.1 bug: full length file since utime and chmod happens at the end
|
||||||
_logger.Debug("{3} failed to {2} file likely due to known {3} bug, attempting to {2} directly. '{0}' -> '{1}'", source, destination, move ? "move" : "copy", PlatformInfo.PlatformName);
|
_logger.Debug("{3} failed to {2} file likely due to known {3} bug, attempting to {2} directly. '{0}' -> '{1}'", source, destination, move ? "move" : "copy", PlatformInfo.PlatformName);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
|
|
|
@ -126,7 +126,7 @@ namespace NzbDrone.Update.UpdateEngine
|
||||||
_diskTransferService.MirrorFolder(_appFolderInfo.GetUpdatePackageFolder(), installationFolder);
|
_diskTransferService.MirrorFolder(_appFolderInfo.GetUpdatePackageFolder(), installationFolder);
|
||||||
|
|
||||||
// Set executable flag on Lidarr app and bundled fpcalc
|
// Set executable flag on Lidarr app and bundled fpcalc
|
||||||
if (OsInfo.IsOsx || (OsInfo.IsLinux && PlatformInfo.IsNetCore))
|
if (OsInfo.IsOsx || OsInfo.IsLinux)
|
||||||
{
|
{
|
||||||
_diskProvider.SetFilePermissions(Path.Combine(installationFolder, "Lidarr"), "755", null);
|
_diskProvider.SetFilePermissions(Path.Combine(installationFolder, "Lidarr"), "755", null);
|
||||||
_diskProvider.SetFilePermissions(Path.Combine(installationFolder, "fpcalc"), "755", null);
|
_diskProvider.SetFilePermissions(Path.Combine(installationFolder, "fpcalc"), "755", null);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue