diff --git a/src/NzbDrone.Core.Test/Extras/ExtraServiceFixture.cs b/src/NzbDrone.Core.Test/Extras/ExtraServiceFixture.cs index 16331ebbc..c8dafafd6 100644 --- a/src/NzbDrone.Core.Test/Extras/ExtraServiceFixture.cs +++ b/src/NzbDrone.Core.Test/Extras/ExtraServiceFixture.cs @@ -121,7 +121,7 @@ namespace NzbDrone.Core.Test.Extras WithExistingFile(file); } - Mocker.GetMock().Setup(s => s.GetFiles(_episodeFolder, SearchOption.AllDirectories)) + Mocker.GetMock().Setup(s => s.GetFiles(_episodeFolder, It.IsAny())) .Returns(files.ToArray()); } @@ -202,5 +202,45 @@ namespace NzbDrone.Core.Test.Extras _subtitleService.Verify(v => v.ImportFiles(_localEpisode, _episodeFile, new List { nfofile }, true), Times.Never()); _otherExtraService.Verify(v => v.ImportFiles(_localEpisode, _episodeFile, new List { nfofile }, true), Times.Once()); } + + [Test] + public void should_search_subtitles_when_importing_from_job_folder() + { + _localEpisode.FolderEpisodeInfo = new ParsedEpisodeInfo(); + + var subtitleFile = Path.Combine(_episodeFolder, "Series.Title.S01E01.en.srt").AsOsAgnostic(); + + var files = new List { + _localEpisode.Path, + subtitleFile + }; + + WithExistingFiles(files); + + Subject.ImportEpisode(_localEpisode, _episodeFile, true); + + Mocker.GetMock().Verify(v => v.GetFiles(_episodeFolder, SearchOption.AllDirectories), Times.Once); + Mocker.GetMock().Verify(v => v.GetFiles(_episodeFolder, SearchOption.TopDirectoryOnly), Times.Never); + } + + [Test] + public void should_not_search_subtitles_when_not_importing_from_job_folder() + { + _localEpisode.FolderEpisodeInfo = null; + + var subtitleFile = Path.Combine(_episodeFolder, "Series.Title.S01E01.en.srt").AsOsAgnostic(); + + var files = new List { + _localEpisode.Path, + subtitleFile + }; + + WithExistingFiles(files); + + Subject.ImportEpisode(_localEpisode, _episodeFile, true); + + Mocker.GetMock().Verify(v => v.GetFiles(_episodeFolder, SearchOption.AllDirectories), Times.Never); + Mocker.GetMock().Verify(v => v.GetFiles(_episodeFolder, SearchOption.TopDirectoryOnly), Times.Once); + } } } diff --git a/src/NzbDrone.Core/Extras/ExtraService.cs b/src/NzbDrone.Core/Extras/ExtraService.cs index 69b5aac3d..b27c000fb 100644 --- a/src/NzbDrone.Core/Extras/ExtraService.cs +++ b/src/NzbDrone.Core/Extras/ExtraService.cs @@ -61,13 +61,17 @@ namespace NzbDrone.Core.Extras return; } + var folderSearchOption = localEpisode.FolderEpisodeInfo == null + ? SearchOption.TopDirectoryOnly + : SearchOption.AllDirectories; + var wantedExtensions = _configService.ExtraFileExtensions.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .Select(e => e.Trim(' ', '.') .Insert(0, ".")) .ToList(); var sourceFolder = _diskProvider.GetParentFolder(localEpisode.Path); - var files = _diskProvider.GetFiles(sourceFolder, SearchOption.AllDirectories); + var files = _diskProvider.GetFiles(sourceFolder, folderSearchOption); var managedFiles = _extraFileManagers.Select((i) => new List()).ToArray(); foreach (var file in files)