From 5f7217844533907d7fc6287a48efb31987736c4c Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Thu, 3 Aug 2023 17:55:50 -0700 Subject: [PATCH] Fixed: UI loading when series or root folder path is for wrong OS --- .../Extensions/PathExtensions.cs | 5 ++++ .../Checks/RootFolderCheckFixture.cs | 30 +++++++++++++++---- .../DiskSpace/DiskSpaceService.cs | 3 +- .../HealthCheck/Checks/RootFolderCheck.cs | 3 +- .../RootFolders/RootFolderService.cs | 6 ++-- 5 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/NzbDrone.Common/Extensions/PathExtensions.cs b/src/NzbDrone.Common/Extensions/PathExtensions.cs index dd359e06d..a63afdd6e 100644 --- a/src/NzbDrone.Common/Extensions/PathExtensions.cs +++ b/src/NzbDrone.Common/Extensions/PathExtensions.cs @@ -169,6 +169,11 @@ namespace NzbDrone.Common.Extensions public static bool ContainsInvalidPathChars(this string text) { + if (text.IsNullOrWhiteSpace()) + { + throw new ArgumentNullException("text"); + } + return text.IndexOfAny(Path.GetInvalidPathChars()) >= 0; } diff --git a/src/NzbDrone.Core.Test/HealthCheck/Checks/RootFolderCheckFixture.cs b/src/NzbDrone.Core.Test/HealthCheck/Checks/RootFolderCheckFixture.cs index 1e492cc78..15e420816 100644 --- a/src/NzbDrone.Core.Test/HealthCheck/Checks/RootFolderCheckFixture.cs +++ b/src/NzbDrone.Core.Test/HealthCheck/Checks/RootFolderCheckFixture.cs @@ -6,8 +6,10 @@ using NUnit.Framework; using NzbDrone.Common.Disk; using NzbDrone.Core.HealthCheck.Checks; using NzbDrone.Core.Localization; +using NzbDrone.Core.RootFolders; using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Tv; +using NzbDrone.Test.Common; namespace NzbDrone.Core.Test.HealthCheck.Checks { @@ -22,7 +24,7 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks .Returns("Some Warning Message"); } - private void GivenMissingRootFolder() + private void GivenMissingRootFolder(string rootFolderPath) { var series = Builder.CreateListOfSize(1) .Build() @@ -32,9 +34,9 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks .Setup(s => s.GetAllSeriesPaths()) .Returns(series.ToDictionary(s => s.Id, s => s.Path)); - Mocker.GetMock() - .Setup(s => s.GetParentFolder(series.First().Path)) - .Returns(@"C:\TV"); + Mocker.GetMock() + .Setup(s => s.GetBestRootFolderPath(It.IsAny())) + .Returns(rootFolderPath); Mocker.GetMock() .Setup(s => s.FolderExists(It.IsAny())) @@ -54,7 +56,25 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks [Test] public void should_return_error_if_series_parent_is_missing() { - GivenMissingRootFolder(); + GivenMissingRootFolder(@"C:\TV".AsOsAgnostic()); + + Subject.Check().ShouldBeError(); + } + + [Test] + public void should_return_error_if_series_path_is_for_posix_os() + { + WindowsOnly(); + GivenMissingRootFolder("/mnt/tv"); + + Subject.Check().ShouldBeError(); + } + + [Test] + public void should_return_error_if_series_path_is_for_windows() + { + PosixOnly(); + GivenMissingRootFolder(@"C:\TV"); Subject.Check().ShouldBeError(); } diff --git a/src/NzbDrone.Core/DiskSpace/DiskSpaceService.cs b/src/NzbDrone.Core/DiskSpace/DiskSpaceService.cs index 74ad34a20..c9846b084 100644 --- a/src/NzbDrone.Core/DiskSpace/DiskSpaceService.cs +++ b/src/NzbDrone.Core/DiskSpace/DiskSpaceService.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text.RegularExpressions; using NLog; using NzbDrone.Common.Disk; +using NzbDrone.Common.Extensions; using NzbDrone.Core.Tv; namespace NzbDrone.Core.DiskSpace @@ -43,7 +44,7 @@ namespace NzbDrone.Core.DiskSpace private IEnumerable GetSeriesRootPaths() { return _seriesService.GetAllSeriesPaths() - .Where(s => _diskProvider.FolderExists(s.Value)) + .Where(s => s.Value.IsPathValid(PathValidationType.CurrentOs) && _diskProvider.FolderExists(s.Value)) .Select(s => _diskProvider.GetPathRoot(s.Value)) .Distinct(); } diff --git a/src/NzbDrone.Core/HealthCheck/Checks/RootFolderCheck.cs b/src/NzbDrone.Core/HealthCheck/Checks/RootFolderCheck.cs index 342948474..c730be8da 100644 --- a/src/NzbDrone.Core/HealthCheck/Checks/RootFolderCheck.cs +++ b/src/NzbDrone.Core/HealthCheck/Checks/RootFolderCheck.cs @@ -1,5 +1,6 @@ using System.Linq; using NzbDrone.Common.Disk; +using NzbDrone.Common.Extensions; using NzbDrone.Core.Localization; using NzbDrone.Core.MediaFiles.Events; using NzbDrone.Core.RootFolders; @@ -32,7 +33,7 @@ namespace NzbDrone.Core.HealthCheck.Checks .Select(s => _rootFolderService.GetBestRootFolderPath(s.Value)) .Distinct(); - var missingRootFolders = rootFolders.Where(s => !_diskProvider.FolderExists(s)) + var missingRootFolders = rootFolders.Where(s => !s.IsPathValid(PathValidationType.CurrentOs) || !_diskProvider.FolderExists(s)) .ToList(); if (missingRootFolders.Any()) diff --git a/src/NzbDrone.Core/RootFolders/RootFolderService.cs b/src/NzbDrone.Core/RootFolders/RootFolderService.cs index 8702ddfbf..ab7d49cf5 100644 --- a/src/NzbDrone.Core/RootFolders/RootFolderService.cs +++ b/src/NzbDrone.Core/RootFolders/RootFolderService.cs @@ -190,10 +190,12 @@ namespace NzbDrone.Core.RootFolders if (possibleRootFolder == null) { - return _diskProvider.GetParentFolder(path); + var osPath = new OsPath(path); + + return osPath.Directory.ToString(); } - return possibleRootFolder.Path; + return possibleRootFolder?.Path; } private void GetDetails(RootFolder rootFolder, Dictionary seriesPaths, bool timeout)