mirror of https://github.com/Sonarr/Sonarr
Missing root dir won't stop app
Fixed: Missing root dir won't prevent UI from loading
This commit is contained in:
parent
861b2ec1e3
commit
cd98fbb4fa
|
@ -194,7 +194,7 @@ namespace NzbDrone.Common
|
|||
public virtual ulong FreeDiskSpace(DirectoryInfo directoryInfo)
|
||||
{
|
||||
if(!directoryInfo.Exists)
|
||||
throw new DirectoryNotFoundException();
|
||||
throw new DirectoryNotFoundException(directoryInfo.FullName);
|
||||
|
||||
ulong freeBytesAvailable;
|
||||
ulong totalNumberOfBytes;
|
||||
|
|
|
@ -142,6 +142,7 @@
|
|||
<Compile Include="HelperTests\XElementHelperTests\ConvertToTFixture.cs" />
|
||||
<Compile Include="IndexerTests\NzbxFixture.cs" />
|
||||
<Compile Include="JobTests\RenameSeasonJobFixture.cs" />
|
||||
<Compile Include="ProviderTests\RootDirProviderTests\FreeSpaceOnDrivesFixture.cs" />
|
||||
<Compile Include="ProviderTests\SearchProviderTests\GetSeriesTitleFixture.cs" />
|
||||
<Compile Include="ProviderTests\TvRageMappingProviderTests\FindMatchingTvRageSeriesFixture.cs" />
|
||||
<Compile Include="ProviderTests\TvRageMappingProviderTests\ProcessResultsFixture.cs" />
|
||||
|
@ -237,7 +238,7 @@
|
|||
<Compile Include="ProviderTests\DecisionEngineTests\AllowedDownloadSpecificationFixture.cs" />
|
||||
<Compile Include="ProviderTests\JobProviderTests\JobProviderFixture.cs" />
|
||||
<Compile Include="QualityTest.cs" />
|
||||
<Compile Include="ProviderTests\RootDirProviderTest.cs" />
|
||||
<Compile Include="ProviderTests\RootDirProviderTests\RootDirProviderFixture.cs" />
|
||||
<Compile Include="ProviderTests\IndexerProviderTest.cs" />
|
||||
<Compile Include="ProviderTests\HistoryProviderTest.cs" />
|
||||
<Compile Include="ProviderTests\MediaFileProviderTest.cs" />
|
||||
|
|
|
@ -0,0 +1,114 @@
|
|||
// ReSharper disable RedundantUsingDirective
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.Providers.Core;
|
||||
using NzbDrone.Core.Repository;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
using NzbDrone.Test.Common.AutoMoq;
|
||||
using PetaPoco;
|
||||
|
||||
namespace NzbDrone.Core.Test.ProviderTests.RootDirProviderTests
|
||||
{
|
||||
[TestFixture]
|
||||
// ReSharper disable InconsistentNaming
|
||||
public class FreeSpaceOnDrivesFixture : CoreTest
|
||||
{
|
||||
[Test]
|
||||
public void should_return_one_drive_when_only_one_root_dir_exists()
|
||||
{
|
||||
Mocker.GetMock<IDatabase>()
|
||||
.Setup(s => s.Fetch<RootDir>())
|
||||
.Returns(new List<RootDir> { new RootDir { Id = 1, Path = @"C:\Test\TV" } });
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(s => s.GetPathRoot(@"C:\Test\TV"))
|
||||
.Returns(@"C:\");
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(s => s.FreeDiskSpace(new DirectoryInfo(@"C:\")))
|
||||
.Returns(123456);
|
||||
|
||||
var result = Mocker.Resolve<RootDirProvider>().FreeSpaceOnDrives();
|
||||
|
||||
result.Should().HaveCount(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_one_drive_when_two_rootDirs_on_the_same_drive_exist()
|
||||
{
|
||||
Mocker.GetMock<IDatabase>()
|
||||
.Setup(s => s.Fetch<RootDir>())
|
||||
.Returns(new List<RootDir> { new RootDir { Id = 1, Path = @"C:\Test\TV" },
|
||||
new RootDir { Id = 2, Path = @"C:\Test\TV2" }});
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(s => s.GetPathRoot(It.IsAny<String>()))
|
||||
.Returns(@"C:\");
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(s => s.FreeDiskSpace(new DirectoryInfo(@"C:\")))
|
||||
.Returns(123456);
|
||||
|
||||
var result = Mocker.Resolve<RootDirProvider>().FreeSpaceOnDrives();
|
||||
|
||||
result.Should().HaveCount(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_two_drives_when_two_rootDirs_on_the_different_drive_exist()
|
||||
{
|
||||
Mocker.GetMock<IDatabase>()
|
||||
.Setup(s => s.Fetch<RootDir>())
|
||||
.Returns(new List<RootDir> { new RootDir { Id = 1, Path = @"C:\Test\TV" },
|
||||
new RootDir { Id = 2, Path = @"D:\Test\TV" }});
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(s => s.GetPathRoot(@"C:\Test\TV"))
|
||||
.Returns(@"C:\");
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(s => s.GetPathRoot(@"D:\Test\TV"))
|
||||
.Returns(@"D:\");
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(s => s.FreeDiskSpace(It.IsAny<DirectoryInfo>()))
|
||||
.Returns(123456);
|
||||
|
||||
var result = Mocker.Resolve<RootDirProvider>().FreeSpaceOnDrives();
|
||||
|
||||
result.Should().HaveCount(2);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_skip_rootDir_if_not_found_on_disk()
|
||||
{
|
||||
Mocker.GetMock<IDatabase>()
|
||||
.Setup(s => s.Fetch<RootDir>())
|
||||
.Returns(new List<RootDir> { new RootDir { Id = 1, Path = @"C:\Test\TV" } });
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(s => s.GetPathRoot(@"C:\Test\TV"))
|
||||
.Returns(@"C:\");
|
||||
|
||||
Mocker.GetMock<DiskProvider>()
|
||||
.Setup(s => s.FreeDiskSpace(It.IsAny<DirectoryInfo>()))
|
||||
.Throws(new DirectoryNotFoundException());
|
||||
|
||||
var result = Mocker.Resolve<RootDirProvider>().FreeSpaceOnDrives();
|
||||
|
||||
result.Should().HaveCount(0);
|
||||
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -14,11 +14,11 @@ using NzbDrone.Core.Repository;
|
|||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common.AutoMoq;
|
||||
|
||||
namespace NzbDrone.Core.Test.ProviderTests
|
||||
namespace NzbDrone.Core.Test.ProviderTests.RootDirProviderTests
|
||||
{
|
||||
[TestFixture]
|
||||
// ReSharper disable InconsistentNaming
|
||||
public class RootDirProviderTest : CoreTest
|
||||
public class RootDirProviderFixture : CoreTest
|
||||
{
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
|
@ -35,7 +35,6 @@ namespace NzbDrone.Core.Test.ProviderTests
|
|||
.Returns(false);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void GetRootDir_should_return_all_existing_roots()
|
||||
{
|
||||
|
@ -48,7 +47,6 @@ namespace NzbDrone.Core.Test.ProviderTests
|
|||
result.Should().HaveCount(2);
|
||||
}
|
||||
|
||||
|
||||
[TestCase("D:\\TV Shows\\")]
|
||||
[TestCase("//server//folder")]
|
||||
public void should_be_able_to_add_root_dir(string path)
|
||||
|
@ -74,7 +72,6 @@ namespace NzbDrone.Core.Test.ProviderTests
|
|||
Assert.Throws<DirectoryNotFoundException>(() => rootDirProvider.Add(new RootDir { Path = "C:\\TEST" }));
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_be_able_to_remove_root_dir()
|
||||
{
|
||||
|
@ -91,7 +88,6 @@ namespace NzbDrone.Core.Test.ProviderTests
|
|||
rootDirs.Should().HaveCount(1);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void None_existing_folder_returns_empty_list()
|
||||
{
|
||||
|
@ -132,6 +128,5 @@ namespace NzbDrone.Core.Test.ProviderTests
|
|||
rootDirProvider.Add(new RootDir { Path = @"C:\TV" });
|
||||
Assert.Throws<InvalidOperationException>(() => rootDirProvider.Add(new RootDir { Path = @"C:\TV" }));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -99,8 +99,17 @@ namespace NzbDrone.Core.Providers
|
|||
var pathRoot = _diskProvider.GetPathRoot(rootDir.Path);
|
||||
|
||||
if(!freeSpace.ContainsKey(pathRoot))
|
||||
{
|
||||
try
|
||||
{
|
||||
freeSpace.Add(pathRoot, _diskProvider.FreeDiskSpace(new DirectoryInfo(rootDir.Path)));
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Logger.WarnException("Error getting fromm space for: " + pathRoot, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return freeSpace;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue