mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-16 11:37:58 +02:00
Fixed: Clear EpisodeFile records from database if Series folder is missing, but root folder appears to be mounted.
This commit is contained in:
parent
be4d70e3a9
commit
37d5a3f2ad
@ -5,6 +5,7 @@
|
||||
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 @@ private void GivenParentFolderExists()
|
||||
|
||||
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)
|
||||
@ -56,7 +57,7 @@ public void should_not_scan_if_series_root_folder_does_not_exist()
|
||||
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 @@ public void should_not_scan_if_series_root_folder_is_empty()
|
||||
.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 @@ public void should_not_scan_extras_subfolder()
|
||||
|
||||
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 @@ public void should_scan_dotHack_folder()
|
||||
.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()
|
||||
{
|
||||
|
@ -85,8 +85,7 @@ public void Scan(Series series)
|
||||
|
||||
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 @@ public void Scan(Series series)
|
||||
{
|
||||
_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 @@ public SeriesScanSkippedEvent(Series series, SeriesScanSkippedReason reason)
|
||||
public enum SeriesScanSkippedReason
|
||||
{
|
||||
RootFolderDoesNotExist,
|
||||
RootFolderIsEmpty,
|
||||
SeriesFolderDoesNotExist
|
||||
RootFolderIsEmpty
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user