Fixed: UI loading when artist or root folder path is for wrong OS

(cherry picked from commit 5f7217844533907d7fc6287a48efb31987736c4c)

Closes #3961
pull/3965/head
Mark McDowall 9 months ago committed by Bogdan
parent 644123c5d3
commit c445315064

@ -159,6 +159,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;
}

@ -8,7 +8,9 @@ using NzbDrone.Core.HealthCheck.Checks;
using NzbDrone.Core.ImportLists;
using NzbDrone.Core.Localization;
using NzbDrone.Core.Music;
using NzbDrone.Core.RootFolders;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.HealthCheck.Checks
{
@ -23,7 +25,7 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks
.Returns("Some Warning Message");
}
private void GivenMissingRootFolder()
private void GivenMissingRootFolder(string rootFolderPath)
{
var artist = Builder<Artist>.CreateListOfSize(1)
.Build()
@ -41,9 +43,9 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks
.Setup(s => s.All())
.Returns(importList);
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.GetParentFolder(artist.First().Path))
.Returns(@"C:\Music");
Mocker.GetMock<IRootFolderService>()
.Setup(s => s.GetBestRootFolderPath(It.IsAny<string>()))
.Returns(rootFolderPath);
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.FolderExists(It.IsAny<string>()))
@ -67,7 +69,25 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks
[Test]
public void should_return_error_if_artist_parent_is_missing()
{
GivenMissingRootFolder();
GivenMissingRootFolder(@"C:\Music".AsOsAgnostic());
Subject.Check().ShouldBeError();
}
[Test]
public void should_return_error_if_series_path_is_for_posix_os()
{
WindowsOnly();
GivenMissingRootFolder("/mnt/music");
Subject.Check().ShouldBeError();
}
[Test]
public void should_return_error_if_series_path_is_for_windows()
{
PosixOnly();
GivenMissingRootFolder(@"C:\Music");
Subject.Check().ShouldBeError();
}

@ -5,6 +5,7 @@ using System.Linq;
using System.Text.RegularExpressions;
using NLog;
using NzbDrone.Common.Disk;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.RootFolders;
namespace NzbDrone.Core.DiskSpace
@ -33,7 +34,7 @@ namespace NzbDrone.Core.DiskSpace
public List<DiskSpace> GetFreeSpace()
{
var importantRootFolders = _rootFolderService.All().Select(x => x.Path).ToList();
var importantRootFolders = GetRootPaths().Distinct().ToList();
var optionalRootFolders = GetFixedDisksRootPaths().Except(importantRootFolders).Distinct().ToList();
@ -42,6 +43,14 @@ namespace NzbDrone.Core.DiskSpace
return diskSpace;
}
private IEnumerable<string> GetRootPaths()
{
return _rootFolderService.All()
.Select(x => x.Path)
.Where(path => path.IsPathValid(PathValidationType.CurrentOs) && _diskProvider.FolderExists(path))
.Distinct();
}
private IEnumerable<string> GetFixedDisksRootPaths()
{
return _diskProvider.GetMounts()

@ -1,5 +1,6 @@
using System.Linq;
using NzbDrone.Common.Disk;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.ImportLists;
using NzbDrone.Core.Localization;
using NzbDrone.Core.MediaFiles.Events;
@ -35,7 +36,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();
missingRootFolders.AddRange(_importListFactory.All()

@ -152,10 +152,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)

Loading…
Cancel
Save