Fixed: Clear EpisodeFile records from database if Series folder is missing, but root folder appears to be mounted.

pull/4/head
Daniel Smith 8 years ago committed by Taloth
parent be4d70e3a9
commit 37d5a3f2ad

@ -5,6 +5,7 @@ using FizzWare.NBuilder;
using Moq;
using NUnit.Framework;
using NzbDrone.Common.Disk;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.MediaFiles.EpisodeImport;
using NzbDrone.Core.Test.Framework;
@ -38,7 +39,7 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.GetDirectories(It.IsAny<string>()))
.Returns(new string[] { @"C:\Test\TV\Series2".AsOsAgnostic() });
.Returns(new[] { @"C:\Test\TV\Series2".AsOsAgnostic() });
}
private void GivenFiles(IEnumerable<string> files)
@ -50,13 +51,13 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
[Test]
public void should_not_scan_if_series_root_folder_does_not_exist()
{
{
Subject.Scan(_series);
ExceptionVerification.ExpectedWarns(1);
Mocker.GetMock<IMediaFileTableCleanupService>()
.Verify(v => v.Clean(It.IsAny<Series>(), It.IsAny<List<string>>()), Times.Never());
.Verify(v => v.Clean(It.IsAny<Series>(), It.IsAny<List<string>>()), Times.Never());
}
[Test]
@ -78,6 +79,63 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
.Verify(v => v.Clean(It.IsAny<Series>(), new List<string>()), Times.Never());
}
[Test]
public void should_clean_but_not_import_if_series_folder_does_not_exist()
{
GivenParentFolderExists();
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.FolderExists(@"C:\Test\TV\Series"))
.Returns(false);
Subject.Scan(_series);
Mocker.GetMock<IMediaFileTableCleanupService>()
.Verify(v => v.Clean(It.IsAny<Series>(), It.IsAny<List<string>>()), Times.Once());
Mocker.GetMock<IMakeImportDecision>()
.Verify(v => v.GetImportDecisions(It.IsAny<List<string>>(), _series), Times.Never());
}
[Test]
public void should_create_and_clean_but_not_import_if_series_folder_does_not_exist_but_create_folder_enabled()
{
GivenParentFolderExists();
Mocker.GetMock<IConfigService>()
.Setup(s => s.CreateEmptySeriesFolders)
.Returns(true);
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.FolderExists(@"C:\Test\TV\Series"))
.Returns(false);
Subject.Scan(_series);
Mocker.GetMock<IMediaFileTableCleanupService>()
.Verify(v => v.Clean(It.IsAny<Series>(), It.IsAny<List<string>>()), Times.Once());
Mocker.GetMock<IMakeImportDecision>()
.Verify(v => v.GetImportDecisions(It.IsAny<List<string>>(), _series), Times.Never());
}
[Test]
public void should_find_files_at_root_of_series_folder()
{
GivenParentFolderExists();
GivenFiles(new List<string>
{
Path.Combine(_series.Path, "file1.mkv").AsOsAgnostic(),
Path.Combine(_series.Path, "s01e01.mkv").AsOsAgnostic()
});
Subject.Scan(_series);
Mocker.GetMock<IMakeImportDecision>()
.Verify(v => v.GetImportDecisions(It.Is<List<string>>(l => l.Count == 2), _series), Times.Once());
}
[Test]
public void should_not_scan_extras_subfolder()
{
@ -94,6 +152,9 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
Subject.Scan(_series);
Mocker.GetMock<IDiskProvider>()
.Verify(v => v.GetFiles(It.IsAny<string>(), It.IsAny<SearchOption>()), Times.Once());
Mocker.GetMock<IMakeImportDecision>()
.Verify(v => v.GetImportDecisions(It.Is<List<string>>(l => l.Count == 1), _series), Times.Once());
}
@ -229,23 +290,6 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
.Verify(v => v.GetImportDecisions(It.Is<List<string>>(l => l.Count == 2), _series), Times.Once());
}
[Test]
public void should_find_files_at_root_of_series_folder()
{
GivenParentFolderExists();
GivenFiles(new List<string>
{
Path.Combine(_series.Path, "file1.mkv").AsOsAgnostic(),
Path.Combine(_series.Path, "s01e01.mkv").AsOsAgnostic()
});
Subject.Scan(_series);
Mocker.GetMock<IMakeImportDecision>()
.Verify(v => v.GetImportDecisions(It.Is<List<string>>(l => l.Count == 2), _series), Times.Once());
}
[Test]
public void should_exclude_osx_metadata_files()
{

@ -78,15 +78,14 @@ namespace NzbDrone.Core.MediaFiles
{
_logger.Warn("Series' root folder ({0}) is empty.", rootFolder);
_eventAggregator.PublishEvent(new SeriesScanSkippedEvent(series, SeriesScanSkippedReason.RootFolderIsEmpty));
return;
return;
}
_logger.ProgressInfo("Scanning disk for {0}", series.Title);
if (!_diskProvider.FolderExists(series.Path))
{
if (_configService.CreateEmptySeriesFolders &&
_diskProvider.FolderExists(rootFolder))
if (_configService.CreateEmptySeriesFolders)
{
_logger.Debug("Creating missing series folder: {0}", series.Path);
_diskProvider.CreateFolder(series.Path);
@ -96,27 +95,35 @@ namespace NzbDrone.Core.MediaFiles
{
_logger.Debug("Series folder doesn't exist: {0}", series.Path);
}
_eventAggregator.PublishEvent(new SeriesScanSkippedEvent(series, SeriesScanSkippedReason.SeriesFolderDoesNotExist));
CleanMediaFiles(series, new List<string>());
CompletedScanning(series);
return;
}
var videoFilesStopwatch = Stopwatch.StartNew();
var mediaFileList = FilterFiles(series, GetVideoFiles(series.Path)).ToList();
videoFilesStopwatch.Stop();
_logger.Trace("Finished getting episode files for: {0} [{1}]", series, videoFilesStopwatch.Elapsed);
_logger.Debug("{0} Cleaning up media files in DB", series);
_mediaFileTableCleanupService.Clean(series, mediaFileList);
CleanMediaFiles(series, mediaFileList);
var decisionsStopwatch = Stopwatch.StartNew();
var decisions = _importDecisionMaker.GetImportDecisions(mediaFileList, series);
decisionsStopwatch.Stop();
_logger.Trace("Import decisions complete for: {0} [{1}]", series, decisionsStopwatch.Elapsed);
_importApprovedEpisodes.Import(decisions, false);
CompletedScanning(series);
}
private void CleanMediaFiles(Series series, List<string> mediaFileList)
{
_logger.Debug("{0} Cleaning up media files in DB", series);
_mediaFileTableCleanupService.Clean(series, mediaFileList);
}
private void CompletedScanning(Series series)
{
_logger.Info("Completed scanning disk for {0}", series.Title);
_eventAggregator.PublishEvent(new SeriesScannedEvent(series));
}

@ -18,7 +18,6 @@ namespace NzbDrone.Core.MediaFiles.Events
public enum SeriesScanSkippedReason
{
RootFolderDoesNotExist,
RootFolderIsEmpty,
SeriesFolderDoesNotExist
RootFolderIsEmpty
}
}

Loading…
Cancel
Save