mirror of
https://github.com/Readarr/Readarr
synced 2025-12-23 16:55:12 +01:00
Fixed: UI loading when author or root folder path is for wrong OS
(cherry picked from commit 5f7217844533907d7fc6287a48efb31987736c4c)
This commit is contained in:
parent
a7b965100d
commit
cc70d61735
5 changed files with 47 additions and 10 deletions
|
|
@ -160,6 +160,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.HealthCheck.Checks;
|
||||
using NzbDrone.Core.ImportLists;
|
||||
using NzbDrone.Core.Localization;
|
||||
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 author = Builder<Author>.CreateListOfSize(1)
|
||||
.Build()
|
||||
|
|
@ -41,9 +43,9 @@ private void GivenMissingRootFolder()
|
|||
.Setup(s => s.All())
|
||||
.Returns(importList);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(s => s.GetParentFolder(author.First().Path))
|
||||
.Returns(@"C:\Books");
|
||||
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_book()
|
|||
[Test]
|
||||
public void should_return_error_if_book_parent_is_missing()
|
||||
{
|
||||
GivenMissingRootFolder();
|
||||
GivenMissingRootFolder(@"C:\Books".AsOsAgnostic());
|
||||
|
||||
Subject.Check().ShouldBeError();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_error_if_series_path_is_for_posix_os()
|
||||
{
|
||||
WindowsOnly();
|
||||
GivenMissingRootFolder("/mnt/books");
|
||||
|
||||
Subject.Check().ShouldBeError();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_error_if_series_path_is_for_windows()
|
||||
{
|
||||
PosixOnly();
|
||||
GivenMissingRootFolder(@"C:\Books");
|
||||
|
||||
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.Books;
|
||||
using NzbDrone.Core.Books.Events;
|
||||
using NzbDrone.Core.ImportLists;
|
||||
|
|
@ -35,8 +36,8 @@ public override HealthCheck Check()
|
|||
.Select(s => _rootFolderService.GetBestRootFolderPath(s.Value))
|
||||
.Distinct();
|
||||
|
||||
var missingRootFolders = rootFolders.Where(s => !_diskProvider.FolderExists(s))
|
||||
.ToList();
|
||||
var missingRootFolders = rootFolders.Where(s => !s.IsPathValid(PathValidationType.CurrentOs) || !_diskProvider.FolderExists(s))
|
||||
.ToList();
|
||||
|
||||
missingRootFolders.AddRange(_importListFactory.All()
|
||||
.Select(s => s.RootFolderPath)
|
||||
|
|
|
|||
|
|
@ -168,10 +168,12 @@ public string GetBestRootFolderPath(string path, List<RootFolder> allRootFolders
|
|||
|
||||
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