From d3890bd712cad129d672f9e02c9992b0d8c45a6e Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Wed, 2 Nov 2016 11:09:29 -0700 Subject: [PATCH] New: Health check warning for macOS when running from App Translocation folder --- .../EnsureTest/PathExtensionFixture.cs | 17 ++++++++++++++++- .../Extensions/PathExtensions.cs | 16 ++++++++++++++++ .../HealthCheck/Checks/UpdateCheck.cs | 8 ++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/NzbDrone.Common.Test/EnsureTest/PathExtensionFixture.cs b/src/NzbDrone.Common.Test/EnsureTest/PathExtensionFixture.cs index 3388df9ad..0b5025ade 100644 --- a/src/NzbDrone.Common.Test/EnsureTest/PathExtensionFixture.cs +++ b/src/NzbDrone.Common.Test/EnsureTest/PathExtensionFixture.cs @@ -1,5 +1,7 @@ -using NUnit.Framework; +using FluentAssertions; +using NUnit.Framework; using NzbDrone.Common.EnsureThat; +using NzbDrone.Common.Extensions; using NzbDrone.Test.Common; namespace NzbDrone.Common.Test.EnsureTest @@ -22,5 +24,18 @@ namespace NzbDrone.Common.Test.EnsureTest MonoOnly(); Ensure.That(path, () => path).IsValidPath(); } + + [Test] + public void GetAncestorFolders_should_return_all_ancestors_in_path() + { + var path = @"C:\Test\TV\Series Title".AsOsAgnostic(); + var result = path.GetAncestorFolders(); + + result.Count.Should().Be(4); + result[0].Should().Be(@"C:\".AsOsAgnostic()); + result[1].Should().Be(@"Test".AsOsAgnostic()); + result[2].Should().Be(@"TV".AsOsAgnostic()); + result[3].Should().Be(@"Series Title".AsOsAgnostic()); + } } } diff --git a/src/NzbDrone.Common/Extensions/PathExtensions.cs b/src/NzbDrone.Common/Extensions/PathExtensions.cs index c37243439..7e77f9d7e 100644 --- a/src/NzbDrone.Common/Extensions/PathExtensions.cs +++ b/src/NzbDrone.Common/Extensions/PathExtensions.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.IO; using System.Text.RegularExpressions; using NzbDrone.Common.EnsureThat; @@ -174,6 +175,21 @@ namespace NzbDrone.Common.Extensions return Path.Combine(GetProperCapitalization(dirInfo), fileName); } + public static List GetAncestorFolders(this string path) + { + var directory = new DirectoryInfo(path); + var directories = new List(); + + while (directory != null) + { + directories.Insert(0, directory.Name); + + directory = directory.Parent; + } + + return directories; + } + public static string GetAppDataPath(this IAppFolderInfo appFolderInfo) { return appFolderInfo.AppDataFolder; diff --git a/src/NzbDrone.Core/HealthCheck/Checks/UpdateCheck.cs b/src/NzbDrone.Core/HealthCheck/Checks/UpdateCheck.cs index c0e2d4f8e..a27fab3c1 100644 --- a/src/NzbDrone.Core/HealthCheck/Checks/UpdateCheck.cs +++ b/src/NzbDrone.Core/HealthCheck/Checks/UpdateCheck.cs @@ -2,6 +2,7 @@ using System.IO; using NzbDrone.Common.Disk; using NzbDrone.Common.EnvironmentInfo; +using NzbDrone.Common.Extensions; using NzbDrone.Core.Configuration; using NzbDrone.Core.Update; @@ -33,6 +34,13 @@ namespace NzbDrone.Core.HealthCheck.Checks if ((OsInfo.IsWindows || _configFileProvider.UpdateAutomatically) && _configFileProvider.UpdateMechanism == UpdateMechanism.BuiltIn) { + if (OsInfo.IsOsx && startupFolder.GetAncestorFolders().Contains("AppTranslocation")) + { + return new HealthCheck(GetType(), HealthCheckResult.Error, + string.Format("Cannot install update because startup folder '{0}' is in an App Translocation folder.", startupFolder), + "Cannot install update because startup folder is in an App Translocation folder."); + } + if (!_diskProvider.FolderWritable(startupFolder)) { return new HealthCheck(GetType(), HealthCheckResult.Error,