Skip import when Series.Path doesn't exist

This commit is contained in:
Mark McDowall 2012-10-19 23:46:12 -07:00
parent 887456b337
commit b5e196fcef
4 changed files with 50 additions and 6 deletions

View File

@ -193,6 +193,9 @@ namespace NzbDrone.Common
public virtual ulong FreeDiskSpace(DirectoryInfo directoryInfo)
{
if (!directoryInfo.Exists)
throw new DirectoryNotFoundException();
ulong freeBytesAvailable;
ulong totalNumberOfBytes;
ulong totalNumberOfFreeBytes;

View File

@ -18,18 +18,20 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskProviderTests
public class FreeDiskSpaceTest : CoreTest
{
[Test]
public void FreeDiskSpace()
public void should_return_free_disk_space()
{
//Setup
//Act
var di = new DirectoryInfo(Directory.GetCurrentDirectory());
var result = Mocker.Resolve<DiskProvider>().FreeDiskSpace(di);
//Asert
//Checks to ensure that the free space on the first is greater than 0 (It should be in 99.99999999999999% of cases... I hope)
result.Should().BeGreaterThan(0);
}
[Test]
public void should_throw_if_directoy_does_not_exist()
{
var di = new DirectoryInfo(@"Z:\NOT_A_REAL_PATH\DOES_NOT_EXIST");
Assert.Throws<DirectoryNotFoundException>(() => Mocker.Resolve<DiskProvider>().FreeDiskSpace(di));
}
}
}

View File

@ -49,6 +49,10 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
Mocker.GetMock<SeriesProvider>()
.Setup(c => c.FindSeries(It.IsAny<string>()))
.Returns(fakeSeries);
Mocker.GetMock<DiskProvider>()
.Setup(c => c.FolderExists(fakeSeries.Path))
.Returns(true);
}
private void WithImportableFiles()
@ -295,6 +299,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
Mocker.GetMock<DiskScanProvider>().Setup(s => s.MoveEpisodeFile(It.IsAny<EpisodeFile>(), true)).Returns(new EpisodeFile());
Mocker.GetMock<DiskProvider>().Setup(s => s.GetDirectorySize(droppedFolder.FullName)).Returns(Constants.IgnoreFileSize - 1.Megabytes());
Mocker.GetMock<DiskProvider>().Setup(s => s.DeleteFolder(droppedFolder.FullName, true));
Mocker.GetMock<DiskProvider>().Setup(s => s.FolderExists(fakeSeries.Path)).Returns(true);
Mocker.GetMock<MetadataProvider>().Setup(s => s.CreateForEpisodeFiles(It.IsAny<List<EpisodeFile>>()));
//Act
@ -316,6 +321,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
.Build().ToList();
Mocker.GetMock<SeriesProvider>().Setup(s => s.FindSeries(It.IsAny<string>())).Returns(fakeSeries);
Mocker.GetMock<DiskProvider>().Setup(s => s.FolderExists(fakeSeries.Path)).Returns(true);
Mocker.GetMock<DiskScanProvider>().Setup(s => s.Scan(fakeSeries, droppedFolder.FullName)).Returns(fakeEpisodeFiles);
//Act
@ -345,6 +351,10 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
.Setup(s => s.GetDirectorySize(downloadName.FullName))
.Returns(10);
Mocker.GetMock<DiskProvider>()
.Setup(s => s.FolderExists(series.Path))
.Returns(true);
Mocker.GetMock<DiskProvider>()
.Setup(s => s.FreeDiskSpace(new DirectoryInfo(series.Path)))
.Returns(9);
@ -407,5 +417,22 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests
//Assert
Mocker.GetMock<DiskScanProvider>().Verify(c => c.Scan(fakeSeries, downloadName.FullName), Times.Once());
}
[Test]
public void should_return_if_series_path_does_not_exist()
{
var downloadName = new DirectoryInfo(@"C:\Test\Drop\30.Rock.S01E01.Pilot");
WithValidSeries();
Mocker.GetMock<DiskProvider>()
.Setup(s => s.FolderExists(fakeSeries.Path))
.Returns(false);
Mocker.Resolve<PostDownloadProvider>().ProcessDownload(downloadName);
Mocker.GetMock<DiskProvider>().Verify(c => c.GetDirectorySize(It.IsAny<String>()), Times.Never());
ExceptionVerification.ExpectedWarns(1);
}
}
}

View File

@ -81,6 +81,12 @@ namespace NzbDrone.Core.Providers
return;
}
if (!_diskProvider.FolderExists(series.Path))
{
Logger.Warn("Series Folder doesn't exist: {0}", series.Path);
return;
}
var size = _diskProvider.GetDirectorySize(subfolderInfo.FullName);
var freeSpace = _diskProvider.FreeDiskSpace(new DirectoryInfo(series.Path));
@ -138,6 +144,12 @@ namespace NzbDrone.Core.Providers
return;
}
if (!_diskProvider.FolderExists(series.Path))
{
Logger.Warn("Series Folder doesn't exist: {0}", series.Path);
return;
}
var size = _diskProvider.GetSize(videoFile);
var freeSpace = _diskProvider.FreeDiskSpace(new DirectoryInfo(series.Path));