diff --git a/src/NzbDrone.Core.Test/MediaFiles/DownloadedEpisodesImportServiceFixture.cs b/src/NzbDrone.Core.Test/MediaFiles/DownloadedEpisodesImportServiceFixture.cs index 11e5a2f1b..f75b4d5e0 100644 --- a/src/NzbDrone.Core.Test/MediaFiles/DownloadedEpisodesImportServiceFixture.cs +++ b/src/NzbDrone.Core.Test/MediaFiles/DownloadedEpisodesImportServiceFixture.cs @@ -446,6 +446,58 @@ namespace NzbDrone.Core.Test.MediaFiles .Verify(v => v.DeleteFolder(It.IsAny(), true), Times.Never()); } + [Test] + public void should_return_rejection_if_nothing_imported_and_contains_rar_file() + { + GivenValidSeries(); + + var path = @"C:\Test\Unsorted\Series.Title.S01E01.abc-Sonarr".AsOsAgnostic(); + var imported = new List(); + + Mocker.GetMock() + .Setup(s => s.GetImportDecisions(It.IsAny>(), It.IsAny(), It.IsAny(), null, true, true)) + .Returns(imported); + + Mocker.GetMock() + .Setup(s => s.Import(It.IsAny>(), true, null, ImportMode.Auto)) + .Returns(imported.Select(i => new ImportResult(i)).ToList()); + + Mocker.GetMock() + .Setup(s => s.GetFiles(It.IsAny(), SearchOption.AllDirectories)) + .Returns(new[] { _videoFiles.First().Replace(".ext", ".rar") }); + + var result = Subject.ProcessPath(path); + + result.Count.Should().Be(1); + result.First().Result.Should().Be(ImportResultType.Rejected); + } + + [Test] + public void should_return_rejection_if_nothing_imported_and_contains_executable_file() + { + GivenValidSeries(); + + var path = @"C:\Test\Unsorted\Series.Title.S01E01.abc-Sonarr".AsOsAgnostic(); + var imported = new List(); + + Mocker.GetMock() + .Setup(s => s.GetImportDecisions(It.IsAny>(), It.IsAny(), It.IsAny(), null, true, true)) + .Returns(imported); + + Mocker.GetMock() + .Setup(s => s.Import(It.IsAny>(), true, null, ImportMode.Auto)) + .Returns(imported.Select(i => new ImportResult(i)).ToList()); + + Mocker.GetMock() + .Setup(s => s.GetFiles(It.IsAny(), SearchOption.AllDirectories)) + .Returns(new[] { _videoFiles.First().Replace(".ext", ".exe") }); + + var result = Subject.ProcessPath(path); + + result.Count.Should().Be(1); + result.First().Result.Should().Be(ImportResultType.Rejected); + } + private void VerifyNoImport() { Mocker.GetMock().Verify(c => c.Import(It.IsAny>(), true, null, ImportMode.Auto), diff --git a/src/NzbDrone.Core/Download/CompletedDownloadService.cs b/src/NzbDrone.Core/Download/CompletedDownloadService.cs index 516bfa7e2..c512114dd 100644 --- a/src/NzbDrone.Core/Download/CompletedDownloadService.cs +++ b/src/NzbDrone.Core/Download/CompletedDownloadService.cs @@ -147,6 +147,18 @@ namespace NzbDrone.Core.Download return; } + if (importResults.Count == 1) + { + var firstResult = importResults.First(); + + if (firstResult.Result == ImportResultType.Rejected && firstResult.ImportDecision.LocalEpisode == null) + { + trackedDownload.Warn(new TrackedDownloadStatusMessage(firstResult.Errors.First(), new List())); + + return; + } + } + var statusMessages = new List { new TrackedDownloadStatusMessage("One or more episodes expected in this release were not imported or missing", new List()) diff --git a/src/NzbDrone.Core/MediaFiles/DownloadedEpisodesImportService.cs b/src/NzbDrone.Core/MediaFiles/DownloadedEpisodesImportService.cs index 5368e6faf..c08666a5b 100644 --- a/src/NzbDrone.Core/MediaFiles/DownloadedEpisodesImportService.cs +++ b/src/NzbDrone.Core/MediaFiles/DownloadedEpisodesImportService.cs @@ -175,8 +175,11 @@ namespace NzbDrone.Core.MediaFiles { if (_seriesService.SeriesPathExists(directoryInfo.FullName)) { - _logger.Warn("Unable to process folder that is mapped to an existing show"); - return new List(); + _logger.Warn("Unable to process folder that is mapped to an existing series"); + return new List + { + RejectionResult("Import path is mapped to a series folder") + }; } var folderInfo = Parser.Parser.ParseTitle(directoryInfo.Name); @@ -211,6 +214,10 @@ namespace NzbDrone.Core.MediaFiles _logger.Debug("Deleting folder after importing valid files"); _diskProvider.DeleteFolder(directoryInfo.FullName, true); } + else if (importResults.Empty()) + { + importResults.AddIfNotNull(CheckEmptyResultForIssue(directoryInfo.FullName)); + } return importResults; } @@ -295,6 +302,28 @@ namespace NzbDrone.Core.MediaFiles return new ImportResult(new ImportDecision(localEpisode, new Rejection("Unknown Series")), message); } + private ImportResult RejectionResult(string message) + { + return new ImportResult(new ImportDecision(null, new Rejection(message)), message); + } + + private ImportResult CheckEmptyResultForIssue(string folder) + { + var files = _diskProvider.GetFiles(folder, SearchOption.AllDirectories); + + if (files.Any(file => FileExtensions.ExecutableExtensions.Contains(Path.GetExtension(file)))) + { + return RejectionResult("Caution: Found executable file"); + } + + if (files.Any(file => FileExtensions.ArchiveExtensions.Contains(Path.GetExtension(file)))) + { + return RejectionResult("Found archive file, might need to be extracted"); + } + + return null; + } + private void LogInaccessiblePathError(string path) { if (_runtimeInfo.IsWindowsService) diff --git a/src/NzbDrone.Core/MediaFiles/FileExtensions.cs b/src/NzbDrone.Core/MediaFiles/FileExtensions.cs new file mode 100644 index 000000000..a6b0c1991 --- /dev/null +++ b/src/NzbDrone.Core/MediaFiles/FileExtensions.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; + +namespace NzbDrone.Core.MediaFiles +{ + internal static class FileExtensions + { + private static List _archiveExtensions = new List + { + ".rar", + ".r00", + ".zip", + ".tar", + ".gz", + ".tar.gz" + }; + + private static List _executableExtensions = new List + { + ".exe", + ".bat", + ".cmd", + ".sh" + }; + + public static HashSet ArchiveExtensions => new HashSet(_archiveExtensions, StringComparer.OrdinalIgnoreCase); + public static HashSet ExecutableExtensions => new HashSet(_executableExtensions, StringComparer.OrdinalIgnoreCase); + } +}