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

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

@ -5,6 +5,7 @@ using FizzWare.NBuilder;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Common.Disk; using NzbDrone.Common.Disk;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.MediaFiles; using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.MediaFiles.EpisodeImport; using NzbDrone.Core.MediaFiles.EpisodeImport;
using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Test.Framework;
@ -38,7 +39,7 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
Mocker.GetMock<IDiskProvider>() Mocker.GetMock<IDiskProvider>()
.Setup(s => s.GetDirectories(It.IsAny<string>())) .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) private void GivenFiles(IEnumerable<string> files)
@ -50,13 +51,13 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
[Test] [Test]
public void should_not_scan_if_series_root_folder_does_not_exist() public void should_not_scan_if_series_root_folder_does_not_exist()
{ {
Subject.Scan(_series); Subject.Scan(_series);
ExceptionVerification.ExpectedWarns(1); ExceptionVerification.ExpectedWarns(1);
Mocker.GetMock<IMediaFileTableCleanupService>() 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] [Test]
@ -78,6 +79,63 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
.Verify(v => v.Clean(It.IsAny<Series>(), new List<string>()), Times.Never()); .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] [Test]
public void should_not_scan_extras_subfolder() public void should_not_scan_extras_subfolder()
{ {
@ -94,6 +152,9 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests
Subject.Scan(_series); Subject.Scan(_series);
Mocker.GetMock<IDiskProvider>()
.Verify(v => v.GetFiles(It.IsAny<string>(), It.IsAny<SearchOption>()), Times.Once());
Mocker.GetMock<IMakeImportDecision>() Mocker.GetMock<IMakeImportDecision>()
.Verify(v => v.GetImportDecisions(It.Is<List<string>>(l => l.Count == 1), _series), Times.Once()); .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()); .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] [Test]
public void should_exclude_osx_metadata_files() public void should_exclude_osx_metadata_files()
{ {

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

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

Loading…
Cancel
Save