mirror of
https://github.com/lidarr/Lidarr
synced 2025-02-25 07:12:40 +00:00
Fixed: UI loading when artist or root folder path is for wrong OS
(cherry picked from commit 5f7217844533907d7fc6287a48efb31987736c4c) Closes #3961
This commit is contained in:
parent
644123c5d3
commit
c445315064
5 changed files with 46 additions and 9 deletions
|
@ -159,6 +159,11 @@ public static bool IsPathValid(this string path, PathValidationType validationTy
|
|||
|
||||
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.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 @@ public void Setup()
|
|||
.Returns("Some Warning Message");
|
||||
}
|
||||
|
||||
private void GivenMissingRootFolder()
|
||||
private void GivenMissingRootFolder(string rootFolderPath)
|
||||
{
|
||||
var artist = Builder<Artist>.CreateListOfSize(1)
|
||||
.Build()
|
||||
|
@ -41,9 +43,9 @@ private void GivenMissingRootFolder()
|
|||
.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 @@ public void should_not_return_error_when_no_artist()
|
|||
[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.Text.RegularExpressions;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.RootFolders;
|
||||
|
||||
namespace NzbDrone.Core.DiskSpace
|
||||
|
@ -33,7 +34,7 @@ public DiskSpaceService(IDiskProvider diskProvider,
|
|||
|
||||
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 @@ public List<DiskSpace> GetFreeSpace()
|
|||
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 @@ public override HealthCheck Check()
|
|||
.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 @@ public string GetBestRootFolderPath(string path)
|
|||
|
||||
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…
Reference in a new issue