From 62efca5084e251bb5c11af511a2edaf0920c1dd3 Mon Sep 17 00:00:00 2001 From: Qstick Date: Tue, 12 May 2020 21:47:18 +0100 Subject: [PATCH] Handle V3 Update Folder --- .../PathExtensionFixture.cs | 4 +-- .../Extensions/PathExtensions.cs | 29 ++++++++++++++++--- .../UpdateTests/UpdateServiceFixture.cs | 4 +-- .../Update/InstallUpdateService.cs | 10 +++---- 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/NzbDrone.Common.Test/PathExtensionFixture.cs b/src/NzbDrone.Common.Test/PathExtensionFixture.cs index 5fa373e12d..6e35561fff 100644 --- a/src/NzbDrone.Common.Test/PathExtensionFixture.cs +++ b/src/NzbDrone.Common.Test/PathExtensionFixture.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; using FluentAssertions; using Moq; @@ -257,7 +257,7 @@ public void GetUpdatePackageFolder() [Test] public void GetUpdateClientFolder() { - GetIAppDirectoryInfo().GetUpdateClientFolder().Should().BeEquivalentTo(@"C:\Temp\radarr_update\Radarr\NzbDrone.Update\".AsOsAgnostic()); + GetIAppDirectoryInfo().GetUpdateClientFolder(new Version("0.2.0.1480")).Should().BeEquivalentTo(@"C:\Temp\radarr_update\Radarr\NzbDrone.Update\".AsOsAgnostic()); } [Test] diff --git a/src/NzbDrone.Common/Extensions/PathExtensions.cs b/src/NzbDrone.Common/Extensions/PathExtensions.cs index 34fc833f74..e5f01f095c 100644 --- a/src/NzbDrone.Common/Extensions/PathExtensions.cs +++ b/src/NzbDrone.Common/Extensions/PathExtensions.cs @@ -14,7 +14,7 @@ public static class PathExtensions private const string NZBDRONE_DB = "nzbdrone.db"; private const string NZBDRONE_LOG_DB = "logs.db"; private const string NLOG_CONFIG_FILE = "nlog.config"; - private const string UPDATE_CLIENT_EXE = "Radarr.Update.exe"; + private const string UPDATE_CLIENT_EXE_NAME = "Radarr.Update"; private const string BACKUP_FOLDER = "Backups"; private static readonly string UPDATE_SANDBOX_FOLDER_NAME = "radarr_update" + Path.DirectorySeparatorChar; @@ -22,6 +22,7 @@ public static class PathExtensions private static readonly string UPDATE_BACKUP_FOLDER_NAME = "radarr_backup" + Path.DirectorySeparatorChar; private static readonly string UPDATE_BACKUP_APPDATA_FOLDER_NAME = "radarr_appdata_backup" + Path.DirectorySeparatorChar; private static readonly string UPDATE_CLIENT_FOLDER_NAME = "NzbDrone.Update" + Path.DirectorySeparatorChar; + private static readonly string UPDATE_V3_CLIENT_FOLDER_NAME = "Radarr.Update" + Path.DirectorySeparatorChar; private static readonly string UPDATE_LOG_FOLDER_NAME = "UpdateLogs" + Path.DirectorySeparatorChar; public static string CleanFilePath(this string path) @@ -191,6 +192,19 @@ public static List GetAncestorFolders(this string path) return directories; } + public static string ProcessNameToExe(this string processName) + { + // Windows always has exe (but is shunted to net core) + // Linux is kept on mono pending manual upgrade to net core so has .exe + // macOS is shunted to net core and does not have .exe + if (OsInfo.IsWindows || OsInfo.IsLinux) + { + processName += ".exe"; + } + + return processName; + } + public static string GetAppDataPath(this IAppFolderInfo appFolderInfo) { return appFolderInfo.AppDataFolder; @@ -246,14 +260,21 @@ public static string GetUpdatePackageFolder(this IAppFolderInfo appFolderInfo) return Path.Combine(GetUpdateSandboxFolder(appFolderInfo), UPDATE_PACKAGE_FOLDER_NAME); } - public static string GetUpdateClientFolder(this IAppFolderInfo appFolderInfo) + public static string GetUpdateClientFolder(this IAppFolderInfo appFolderInfo, Version version) { - return Path.Combine(GetUpdatePackageFolder(appFolderInfo), UPDATE_CLIENT_FOLDER_NAME); + if (version.Major >= 3) + { + return Path.Combine(GetUpdatePackageFolder(appFolderInfo), UPDATE_V3_CLIENT_FOLDER_NAME); + } + else + { + return Path.Combine(GetUpdatePackageFolder(appFolderInfo), UPDATE_CLIENT_FOLDER_NAME); + } } public static string GetUpdateClientExePath(this IAppFolderInfo appFolderInfo) { - return Path.Combine(GetUpdateSandboxFolder(appFolderInfo), UPDATE_CLIENT_EXE); + return Path.Combine(GetUpdateSandboxFolder(appFolderInfo), UPDATE_CLIENT_EXE_NAME).ProcessNameToExe(); } public static string GetBackupFolder(this IAppFolderInfo appFolderInfo) diff --git a/src/NzbDrone.Core.Test/UpdateTests/UpdateServiceFixture.cs b/src/NzbDrone.Core.Test/UpdateTests/UpdateServiceFixture.cs index f839242082..be5c3fb7e8 100644 --- a/src/NzbDrone.Core.Test/UpdateTests/UpdateServiceFixture.cs +++ b/src/NzbDrone.Core.Test/UpdateTests/UpdateServiceFixture.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using FluentAssertions; @@ -131,7 +131,7 @@ public void Should_extract_update_package() [Test] public void Should_copy_update_client_to_root_of_sandbox() { - var updateClientFolder = Mocker.GetMock().Object.GetUpdateClientFolder(); + var updateClientFolder = Mocker.GetMock().Object.GetUpdateClientFolder(It.IsAny()); Subject.Execute(new ApplicationUpdateCommand()); diff --git a/src/NzbDrone.Core/Update/InstallUpdateService.cs b/src/NzbDrone.Core/Update/InstallUpdateService.cs index e42a075cdd..ee3e942f3e 100644 --- a/src/NzbDrone.Core/Update/InstallUpdateService.cs +++ b/src/NzbDrone.Core/Update/InstallUpdateService.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using NLog; @@ -121,12 +121,12 @@ private void InstallUpdate(UpdatePackage updatePackage) if (OsInfo.IsNotWindows && _configFileProvider.UpdateMechanism == UpdateMechanism.Script) { - InstallUpdateWithScript(updateSandboxFolder); + InstallUpdateWithScript(updateSandboxFolder, updatePackage.Version); return; } _logger.Info("Preparing client"); - _diskTransferService.TransferFolder(_appFolderInfo.GetUpdateClientFolder(), updateSandboxFolder, TransferMode.Move, false); + _diskTransferService.TransferFolder(_appFolderInfo.GetUpdateClientFolder(updatePackage.Version), updateSandboxFolder, TransferMode.Move, false); _logger.Info("Starting update client {0}", _appFolderInfo.GetUpdateClientExePath()); _logger.ProgressInfo("Radarr will restart shortly."); @@ -153,7 +153,7 @@ private void EnsureValidBranch(UpdatePackage package) } } - private void InstallUpdateWithScript(string updateSandboxFolder) + private void InstallUpdateWithScript(string updateSandboxFolder, Version version) { var scriptPath = _configFileProvider.UpdateScriptPath; @@ -168,7 +168,7 @@ private void InstallUpdateWithScript(string updateSandboxFolder) } _logger.Info("Removing NzbDrone.Update"); - _diskProvider.DeleteFolder(_appFolderInfo.GetUpdateClientFolder(), true); + _diskProvider.DeleteFolder(_appFolderInfo.GetUpdateClientFolder(version), true); _logger.ProgressInfo("Starting update script: {0}", _configFileProvider.UpdateScriptPath); _processProvider.Start(scriptPath, GetUpdaterArgs(updateSandboxFolder));