From 587aff602a2a3e2b70709acd98b7f37c5d145fc3 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Tue, 5 May 2015 08:37:11 -0700 Subject: [PATCH] Fixed: Don't delete downloads unless a file was imported --- .../DownloadedEpisodesImportServiceFixture.cs | 36 +++++++++++++++++++ .../DownloadedEpisodesImportService.cs | 4 ++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/NzbDrone.Core.Test/MediaFiles/DownloadedEpisodesImportServiceFixture.cs b/src/NzbDrone.Core.Test/MediaFiles/DownloadedEpisodesImportServiceFixture.cs index 810f3300e..dcaff126d 100644 --- a/src/NzbDrone.Core.Test/MediaFiles/DownloadedEpisodesImportServiceFixture.cs +++ b/src/NzbDrone.Core.Test/MediaFiles/DownloadedEpisodesImportServiceFixture.cs @@ -327,6 +327,42 @@ namespace NzbDrone.Core.Test.MediaFiles ExceptionVerification.ExpectedErrors(1); } + [Test] + public void should_not_delete_if_no_files_were_imported() + { + GivenValidSeries(); + + var localEpisode = new LocalEpisode(); + + var imported = new List(); + imported.Add(new ImportDecision(localEpisode)); + + Mocker.GetMock() + .Setup(s => s.GetImportDecisions(It.IsAny>(), It.IsAny(), null, true)) + .Returns(imported); + + Mocker.GetMock() + .Setup(s => s.Import(It.IsAny>(), true, null)) + .Returns(new List()); + + Mocker.GetMock() + .Setup(s => s.IsSample(It.IsAny(), + It.IsAny(), + It.IsAny(), + It.IsAny(), + It.IsAny())) + .Returns(true); + + Mocker.GetMock() + .Setup(s => s.GetFileSize(It.IsAny())) + .Returns(15.Megabytes()); + + Subject.ProcessRootFolder(new DirectoryInfo(_droneFactory)); + + Mocker.GetMock() + .Verify(v => v.DeleteFolder(It.IsAny(), true), Times.Never()); + } + private void VerifyNoImport() { Mocker.GetMock().Verify(c => c.Import(It.IsAny>(), true, null), diff --git a/src/NzbDrone.Core/MediaFiles/DownloadedEpisodesImportService.cs b/src/NzbDrone.Core/MediaFiles/DownloadedEpisodesImportService.cs index b41c380e8..938d87a12 100644 --- a/src/NzbDrone.Core/MediaFiles/DownloadedEpisodesImportService.cs +++ b/src/NzbDrone.Core/MediaFiles/DownloadedEpisodesImportService.cs @@ -152,7 +152,9 @@ namespace NzbDrone.Core.MediaFiles var decisions = _importDecisionMaker.GetImportDecisions(videoFiles.ToList(), series, folderInfo, true); var importResults = _importApprovedEpisodes.Import(decisions, true, downloadClientItem); - if ((downloadClientItem == null || !downloadClientItem.IsReadOnly) && importResults.Any() && ShouldDeleteFolder(directoryInfo, series)) + if ((downloadClientItem == null || !downloadClientItem.IsReadOnly) && + importResults.Any(i => i.Result == ImportResultType.Imported) && + ShouldDeleteFolder(directoryInfo, series)) { _logger.Debug("Deleting folder after importing valid files"); _diskProvider.DeleteFolder(directoryInfo.FullName, true);