1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-31 03:11:07 +02:00

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 @@ public virtual void InheritFolderPermissions(string filename)
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 @@ private void WithValidSeries()
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 @@ public void when_files_are_imported_and_folder_is_small_enough_dir_should_be_del
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 @@ public void all_imported_files_should_be_moved()
.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 @@ public void should_logError_and_return_if_size_exceeds_free_space()
.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 @@ public void should_process_if_free_disk_space_equals_size()
//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 @@ public virtual void ProcessDownload(DirectoryInfo subfolderInfo)
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 @@ public virtual void ProcessVideoFile(string videoFile)
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));