From 3dd7b3d76890f0c716475306eb1992ea60704aad Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Mon, 24 Oct 2011 21:34:48 -0700 Subject: [PATCH] This should fix the bug where a folder was tried to be retagged with the same error. --- NzbDrone.6.0.ReSharper | 35 ++++++++++++-- .../PostDownloadProviderFixture.cs | 4 +- .../ProcessDownloadFixture.cs | 46 ++++++++++++++++++- .../Providers/PostDownloadProvider.cs | 13 ++++-- 4 files changed, 88 insertions(+), 10 deletions(-) diff --git a/NzbDrone.6.0.ReSharper b/NzbDrone.6.0.ReSharper index f0c66ec6f..c4e417d31 100644 --- a/NzbDrone.6.0.ReSharper +++ b/NzbDrone.6.0.ReSharper @@ -9,6 +9,13 @@ + True + False + 2 + SEPARATE + True + True + True public protected @@ -25,8 +32,30 @@ unsafe volatile + False + True + True + False + False + False + True + False + False + False + False + False + True + False + False + False + False + False - + + + System.Linq + + $object$_On$event$ $event$Handler @@ -79,8 +108,8 @@ - - + + diff --git a/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/PostDownloadProviderFixture.cs b/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/PostDownloadProviderFixture.cs index ba71f228e..9d49d06c5 100644 --- a/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/PostDownloadProviderFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/PostDownloadProviderFixture.cs @@ -19,7 +19,7 @@ namespace NzbDrone.Core.Test.ProviderTests [TestCase(@"c:\Root\Test Title", @"c:\Root\_ParseError_Test Title", PostDownloadStatusType.ParseError)] public void GetFolderNameWithStatus_should_return_a_string_with_the_error_removing_existing_error(string currentName, string excpectedName, PostDownloadStatusType status) { - PostDownloadProvider.GetFolderNameWithStatus(new DirectoryInfo(currentName), status).Should().Be( + PostDownloadProvider.GetTaggedFolderName(new DirectoryInfo(currentName), status).Should().Be( excpectedName); } @@ -27,7 +27,7 @@ namespace NzbDrone.Core.Test.ProviderTests [ExpectedException(typeof(InvalidOperationException))] public void GetFolderNameWithStatus_should_throw_if_status_is_not_an_error(PostDownloadStatusType status) { - PostDownloadProvider.GetFolderNameWithStatus(new DirectoryInfo(TempFolder), status); + PostDownloadProvider.GetTaggedFolderName(new DirectoryInfo(TempFolder), status); } diff --git a/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessDownloadFixture.cs b/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessDownloadFixture.cs index be57fb5f5..4201ec0c2 100644 --- a/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessDownloadFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/PostDownloadProviderTests/ProcessDownloadFixture.cs @@ -122,7 +122,7 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests var mocker = new AutoMoqer(MockBehavior.Strict); var droppedFolder = new DirectoryInfo(@"C:\Test\Unsorted TV\The Office - Season 01"); - var taggedFolder = PostDownloadProvider.GetFolderNameWithStatus(droppedFolder, PostDownloadStatusType.Unknown); + var taggedFolder = PostDownloadProvider.GetTaggedFolderName(droppedFolder, PostDownloadStatusType.Unknown); var fakeSeries = Builder.CreateNew() .With(s => s.Title = "The Office") @@ -147,6 +147,50 @@ namespace NzbDrone.Core.Test.ProviderTests.PostDownloadProviderTests ExceptionVerification.ExcpectedWarns(1); } + [TestCase(@"\_UnknownSeries_The Office - S01E01 - Episode Title")] + [TestCase(@"\_UnknownSeries_The Office - S01E01 - Episode Title\")] + [TestCase("\\Test\\_UnknownSeries_The Office - S01E01 - Episode Title\\")] + [TestCase("\\Test\\_UnknownSeries_The Office - S01E01 - Episode Title")] + public void folder_shouldnt_be_tagged_with_same_tag_again(string path) + { + //Setup + var mocker = new AutoMoqer(); + var droppedFolder = new DirectoryInfo(TempFolder + path); + droppedFolder.Create(); + droppedFolder.LastWriteTime = DateTime.Now.AddHours(-1); + + //Act + mocker.GetMock().Setup(s => s.FindSeries(It.IsAny())).Returns(null); + mocker.Resolve().ProcessDownload(droppedFolder); + + //Assert + mocker.VerifyAllMocks(); + mocker.GetMock().Verify(c => c.MoveDirectory(It.IsAny(), It.IsAny()), Times.Never()); + ExceptionVerification.ExcpectedWarns(1); + } + + [Test] + public void folder_should_be_tagged_if_existing_tag_is_diffrent() + { + //Setup + var mocker = new AutoMoqer(); + var droppedFolder = new DirectoryInfo(TempFolder + @"\_UnknownEpisode_The Office - S01E01 - Episode Title"); + droppedFolder.Create(); + droppedFolder.LastWriteTime = DateTime.Now.AddHours(-1); + + var taggedFolder = TempFolder + @"\_UnknownSeries_The Office - S01E01 - Episode Title"; + + mocker.GetMock().Setup(s => s.FindSeries(It.IsAny())).Returns(null); + + //Act + mocker.Resolve().ProcessDownload(droppedFolder); + + //Assert + mocker.VerifyAllMocks(); + mocker.GetMock().Verify(c => c.MoveDirectory(droppedFolder.FullName, taggedFolder), Times.Once()); + ExceptionVerification.ExcpectedWarns(1); + } + [Test] public void when_files_are_imported_and_folder_is_small_enought_dir_should_be_deleted() { diff --git a/NzbDrone.Core/Providers/PostDownloadProvider.cs b/NzbDrone.Core/Providers/PostDownloadProvider.cs index 2c4980f8e..b0080d2d0 100644 --- a/NzbDrone.Core/Providers/PostDownloadProvider.cs +++ b/NzbDrone.Core/Providers/PostDownloadProvider.cs @@ -76,7 +76,7 @@ namespace NzbDrone.Core.Providers { if (importedFiles.Count == 0) { - Logger.Warn("Unable to Import new download [{0}], no importable files were found..", + Logger.Warn("Unable to Import new download [{0}], no importable files were found.", subfolderInfo.Name); TagFolder(subfolderInfo, PostDownloadStatusType.ParseError); } @@ -89,12 +89,17 @@ namespace NzbDrone.Core.Providers } } - public void TagFolder(DirectoryInfo directory, PostDownloadStatusType status) + private void TagFolder(DirectoryInfo directory, PostDownloadStatusType status) { - _diskProvider.MoveDirectory(directory.FullName, GetFolderNameWithStatus(directory, status)); + var target = GetTaggedFolderName(directory, status); + + if (!String.Equals(Parser.NormalizePath(target), Parser.NormalizePath(directory.FullName), StringComparison.InvariantCultureIgnoreCase)) + { + _diskProvider.MoveDirectory(directory.FullName, target); + } } - public static string GetFolderNameWithStatus(DirectoryInfo directoryInfo, PostDownloadStatusType status) + public static string GetTaggedFolderName(DirectoryInfo directoryInfo, PostDownloadStatusType status) { if (status == PostDownloadStatusType.NoError) throw new InvalidOperationException("Can't tag a folder with a None-error status. " + status);