mirror of
https://github.com/Prowlarr/Prowlarr
synced 2026-05-08 21:14:30 +02:00
Cleanup multi-platform code
This commit is contained in:
parent
1c6e5543df
commit
6579385110
11 changed files with 64 additions and 60 deletions
|
|
@ -278,7 +278,7 @@ public void GetUpdateClientFolder()
|
|||
[Test]
|
||||
public void GetUpdateClientExePath()
|
||||
{
|
||||
GetIAppDirectoryInfo().GetUpdateClientExePath(PlatformType.DotNet).Should().BeEquivalentTo(@"C:\Temp\prowlarr_update\Prowlarr.Update.exe".AsOsAgnostic());
|
||||
GetIAppDirectoryInfo().GetUpdateClientExePath().Should().BeEquivalentTo(@"C:\Temp\prowlarr_update\Prowlarr.Update.exe".AsOsAgnostic());
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
|
|
|||
|
|
@ -2,13 +2,6 @@
|
|||
|
||||
namespace NzbDrone.Common.EnvironmentInfo
|
||||
{
|
||||
public enum PlatformType
|
||||
{
|
||||
DotNet = 0,
|
||||
Mono = 1,
|
||||
NetCore = 2
|
||||
}
|
||||
|
||||
public interface IPlatformInfo
|
||||
{
|
||||
Version Version { get; }
|
||||
|
|
@ -16,36 +9,18 @@ public interface IPlatformInfo
|
|||
|
||||
public class PlatformInfo : IPlatformInfo
|
||||
{
|
||||
private static PlatformType _platform;
|
||||
private static Version _version;
|
||||
|
||||
static PlatformInfo()
|
||||
{
|
||||
_platform = PlatformType.NetCore;
|
||||
_version = Environment.Version;
|
||||
}
|
||||
|
||||
public static PlatformType Platform => _platform;
|
||||
public static bool IsMono => Platform == PlatformType.Mono;
|
||||
public static bool IsDotNet => Platform == PlatformType.DotNet;
|
||||
public static bool IsNetCore => Platform == PlatformType.NetCore;
|
||||
|
||||
public static string PlatformName
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsDotNet)
|
||||
{
|
||||
return ".NET";
|
||||
}
|
||||
else if (IsMono)
|
||||
{
|
||||
return "Mono";
|
||||
}
|
||||
else
|
||||
{
|
||||
return ".NET Core";
|
||||
}
|
||||
return ".NET";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -238,9 +238,9 @@ public static string GetAncestorPath(this string path, string ancestorName)
|
|||
return null;
|
||||
}
|
||||
|
||||
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";
|
||||
}
|
||||
|
|
@ -248,11 +248,6 @@ public static string ProcessNameToExe(this string processName, PlatformType runt
|
|||
return processName;
|
||||
}
|
||||
|
||||
public static string ProcessNameToExe(this string processName)
|
||||
{
|
||||
return processName.ProcessNameToExe(PlatformInfo.Platform);
|
||||
}
|
||||
|
||||
public static string GetAppDataPath(this IAppFolderInfo appFolderInfo)
|
||||
{
|
||||
return appFolderInfo.AppDataFolder;
|
||||
|
|
@ -318,9 +313,9 @@ public static string GetUpdateClientFolder(this IAppFolderInfo appFolderInfo)
|
|||
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)
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ private List<HealthCheck> RetrieveServerChecks()
|
|||
.AddQueryParam("version", BuildInfo.Version)
|
||||
.AddQueryParam("os", OsInfo.Os.ToString().ToLowerInvariant())
|
||||
.AddQueryParam("arch", RuntimeInformation.OSArchitecture)
|
||||
.AddQueryParam("runtime", PlatformInfo.Platform.ToString().ToLowerInvariant())
|
||||
.AddQueryParam("runtime", "netcore")
|
||||
.AddQueryParam("branch", _configFileProvider.Branch)
|
||||
.Build();
|
||||
try
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ private bool InstallUpdate(UpdatePackage updatePackage)
|
|||
_logger.Info("Preparing client");
|
||||
_diskTransferService.TransferFolder(_appFolderInfo.GetUpdateClientFolder(), updateSandboxFolder, TransferMode.Move);
|
||||
|
||||
var updateClientExePath = _appFolderInfo.GetUpdateClientExePath(updatePackage.Runtime);
|
||||
var updateClientExePath = _appFolderInfo.GetUpdateClientExePath();
|
||||
|
||||
if (!_diskProvider.FileExists(updateClientExePath))
|
||||
{
|
||||
|
|
@ -155,7 +155,7 @@ private bool InstallUpdate(UpdatePackage updatePackage)
|
|||
}
|
||||
|
||||
// Set executable flag on update app
|
||||
if (OsInfo.IsOsx || (OsInfo.IsLinux && PlatformInfo.IsNetCore))
|
||||
if (OsInfo.IsOsx || OsInfo.IsLinux)
|
||||
{
|
||||
_diskProvider.SetFilePermissions(updateClientExePath, "755", null);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,5 @@ public class UpdatePackage
|
|||
public UpdateChanges Changes { get; set; }
|
||||
public string Hash { get; set; }
|
||||
public string Branch { get; set; }
|
||||
public PlatformType Runtime { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public UpdatePackage GetLatestUpdate(string branch, Version currentVersion)
|
|||
.AddQueryParam("version", currentVersion)
|
||||
.AddQueryParam("os", OsInfo.Os.ToString().ToLowerInvariant())
|
||||
.AddQueryParam("arch", RuntimeInformation.OSArchitecture)
|
||||
.AddQueryParam("runtime", PlatformInfo.Platform.ToString().ToLowerInvariant())
|
||||
.AddQueryParam("runtime", "netcore")
|
||||
.AddQueryParam("runtimeVer", _platformInfo.Version)
|
||||
.AddQueryParam("dbType", _mainDatabase.DatabaseType)
|
||||
.SetSegment("branch", branch);
|
||||
|
|
@ -67,7 +67,7 @@ public List<UpdatePackage> GetRecentUpdates(string branch, Version currentVersio
|
|||
.AddQueryParam("version", currentVersion)
|
||||
.AddQueryParam("os", OsInfo.Os.ToString().ToLowerInvariant())
|
||||
.AddQueryParam("arch", RuntimeInformation.OSArchitecture)
|
||||
.AddQueryParam("runtime", PlatformInfo.Platform.ToString().ToLowerInvariant())
|
||||
.AddQueryParam("runtime", "netcore")
|
||||
.AddQueryParam("runtimeVer", _platformInfo.Version)
|
||||
.AddQueryParam("dbType", _mainDatabase.DatabaseType)
|
||||
.SetSegment("branch", branch);
|
||||
|
|
|
|||
|
|
@ -247,9 +247,7 @@ protected override void CopyFileInternal(string source, string destination, bool
|
|||
newFile.CreateSymbolicLinkTo(fullPath);
|
||||
}
|
||||
}
|
||||
else if (((PlatformInfo.Platform == PlatformType.Mono && PlatformInfo.GetVersion() >= new Version(6, 0)) ||
|
||||
PlatformInfo.Platform == PlatformType.NetCore) &&
|
||||
(!FileExists(destination) || overwrite))
|
||||
else if (!FileExists(destination) || overwrite)
|
||||
{
|
||||
TransferFilePatched(source, destination, overwrite, false);
|
||||
}
|
||||
|
|
@ -294,14 +292,9 @@ protected override void MoveFileInternal(string source, string destination)
|
|||
throw;
|
||||
}
|
||||
}
|
||||
else if ((PlatformInfo.Platform == PlatformType.Mono && PlatformInfo.GetVersion() >= new Version(6, 0)) ||
|
||||
PlatformInfo.Platform == PlatformType.NetCore)
|
||||
{
|
||||
TransferFilePatched(source, destination, false, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
base.MoveFileInternal(source, destination);
|
||||
TransferFilePatched(source, destination, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -313,7 +306,7 @@ private void TransferFilePatched(string source, string destination, bool overwri
|
|||
// Catch the exception and attempt to handle these edgecases
|
||||
|
||||
// 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 &&
|
||||
Syscall.lstat(destination, out var deststat) != 0 &&
|
||||
|
|
@ -341,7 +334,7 @@ private void TransferFilePatched(string source, string destination, bool overwri
|
|||
var dstInfo = new FileInfo(destination);
|
||||
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
|
||||
_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 NLog;
|
||||
using NzbDrone.Common.Disk;
|
||||
|
|
@ -129,7 +129,7 @@ public void Start(string installationFolder, int processId)
|
|||
_diskTransferService.MirrorFolder(_appFolderInfo.GetUpdatePackageFolder(), installationFolder);
|
||||
|
||||
// Set executable flag on app
|
||||
if (OsInfo.IsOsx || (OsInfo.IsLinux && PlatformInfo.IsNetCore))
|
||||
if (OsInfo.IsOsx || OsInfo.IsLinux)
|
||||
{
|
||||
_diskProvider.SetFilePermissions(Path.Combine(installationFolder, "Prowlarr"), "755", null);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,9 +54,9 @@ public SystemController(IAppFolderInfo appFolderInfo,
|
|||
}
|
||||
|
||||
[HttpGet("status")]
|
||||
public object GetStatus()
|
||||
public SystemResource GetStatus()
|
||||
{
|
||||
return new
|
||||
return new SystemResource
|
||||
{
|
||||
AppName = BuildInfo.AppName,
|
||||
InstanceName = _configFileProvider.InstanceName,
|
||||
|
|
@ -70,8 +70,7 @@ public object GetStatus()
|
|||
AppData = _appFolderInfo.GetAppDataPath(),
|
||||
OsName = _osInfo.Name,
|
||||
OsVersion = _osInfo.Version,
|
||||
IsNetCore = PlatformInfo.IsNetCore,
|
||||
IsMono = PlatformInfo.IsMono,
|
||||
IsNetCore = true,
|
||||
IsLinux = OsInfo.IsLinux,
|
||||
IsOsx = OsInfo.IsOsx,
|
||||
IsWindows = OsInfo.IsWindows,
|
||||
|
|
@ -84,7 +83,7 @@ public object GetStatus()
|
|||
MigrationVersion = _database.Migration,
|
||||
UrlBase = _configFileProvider.UrlBase,
|
||||
RuntimeVersion = _platformInfo.Version,
|
||||
RuntimeName = PlatformInfo.Platform,
|
||||
RuntimeName = "netcore",
|
||||
StartTime = _runtimeInfo.StartTime,
|
||||
PackageVersion = _deploymentInfoProvider.PackageVersion,
|
||||
PackageAuthor = _deploymentInfoProvider.PackageAuthor,
|
||||
|
|
|
|||
43
src/Prowlarr.Api.V1/System/SystemResource.cs
Normal file
43
src/Prowlarr.Api.V1/System/SystemResource.cs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
using System;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Core.Authentication;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Update;
|
||||
|
||||
namespace Prowlarr.Api.V1.System
|
||||
{
|
||||
public class SystemResource
|
||||
{
|
||||
public string AppName { get; set; }
|
||||
public string InstanceName { get; set; }
|
||||
public string Version { get; set; }
|
||||
public DateTime BuildTime { get; set; }
|
||||
public bool IsDebug { get; set; }
|
||||
public bool IsProduction { get; set; }
|
||||
public bool IsAdmin { get; set; }
|
||||
public bool IsUserInteractive { get; set; }
|
||||
public string StartupPath { get; set; }
|
||||
public string AppData { get; set; }
|
||||
public string OsName { get; set; }
|
||||
public string OsVersion { get; set; }
|
||||
public bool IsNetCore { get; set; }
|
||||
public bool IsLinux { get; set; }
|
||||
public bool IsOsx { get; set; }
|
||||
public bool IsWindows { get; set; }
|
||||
public bool IsDocker { get; set; }
|
||||
public RuntimeMode Mode { get; set; }
|
||||
public string Branch { get; set; }
|
||||
public DatabaseType DatabaseType { get; set; }
|
||||
public Version DatabaseVersion { get; set; }
|
||||
public AuthenticationType Authentication { get; set; }
|
||||
public int MigrationVersion { get; set; }
|
||||
public string UrlBase { get; set; }
|
||||
public Version RuntimeVersion { get; set; }
|
||||
public string RuntimeName { get; set; }
|
||||
public DateTime StartTime { get; set; }
|
||||
public string PackageVersion { get; set; }
|
||||
public string PackageAuthor { get; set; }
|
||||
public UpdateMechanism PackageUpdateMechanism { get; set; }
|
||||
public string PackageUpdateMechanismMessage { get; set; }
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue