From 69406a95d44b74cd361fc56315a0d606f471a2ef Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Thu, 19 May 2011 19:12:36 -0700 Subject: [PATCH 1/2] Fixed bug when a file that wasn't parsable would try to be imported --- NzbDrone.Core.Test/MediaFileProviderTests.cs | 34 ++++++++++++++++++++ NzbDrone.Core/Providers/MediaFileProvider.cs | 4 ++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/NzbDrone.Core.Test/MediaFileProviderTests.cs b/NzbDrone.Core.Test/MediaFileProviderTests.cs index 6fe658c41..1ed614356 100644 --- a/NzbDrone.Core.Test/MediaFileProviderTests.cs +++ b/NzbDrone.Core.Test/MediaFileProviderTests.cs @@ -166,6 +166,40 @@ namespace NzbDrone.Core.Test Assert.IsNull(result); } + + [Test] + [Description("Verifies that a un-parsable file isn't imported")] + public void import_unparsable_file() + { + //Arrange + ///////////////////////////////////////// + + //Constants + const string fileName = @"WEEDS.avi"; + const int size = 12345; + + //Fakes + var fakeSeries = Builder.CreateNew().Build(); + + //Mocks + var mocker = new AutoMoqer(); + + mocker.GetMock(MockBehavior.Strict) + .Setup(r => r.Exists(It.IsAny>>())).Returns(false).Verifiable(); + + mocker.GetMock() + .Setup(e => e.GetSize(fileName)).Returns(size).Verifiable(); + + + //Act + var result = mocker.Resolve().ImportFile(fakeSeries, fileName); + + //Assert + mocker.VerifyAllMocks(); + Assert.IsNull(result); + ExceptionVerification.ExcpectedWarns(1); + } + [Test] [Description("Verifies that a new file imported properly")] public void import_sample_file() diff --git a/NzbDrone.Core/Providers/MediaFileProvider.cs b/NzbDrone.Core/Providers/MediaFileProvider.cs index 29832ca21..56b3a433c 100644 --- a/NzbDrone.Core/Providers/MediaFileProvider.cs +++ b/NzbDrone.Core/Providers/MediaFileProvider.cs @@ -72,11 +72,13 @@ namespace NzbDrone.Core.Providers if (!_repository.Exists(e => e.Path == Parser.NormalizePath(filePath))) { var parseResult = Parser.ParseEpisodeInfo(filePath); - parseResult.CleanTitle = series.Title;//replaces the nasty path as title to help with logging + if (parseResult == null) return null; + parseResult.CleanTitle = series.Title;//replaces the nasty path as title to help with logging + //Stores the list of episodes to add to the EpisodeFile var episodes = new List(); From 9cad9bbbd7e47c893854b3c0a95a9e367d554697 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Thu, 19 May 2011 19:13:21 -0700 Subject: [PATCH 2/2] Optimized logging to improve performance --- NzbDrone.Core/CentralDispatch.cs | 2 +- NzbDrone.Core/Providers/SeriesProvider.cs | 1 + NzbDrone.Web/log.config | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/NzbDrone.Core/CentralDispatch.cs b/NzbDrone.Core/CentralDispatch.cs index 73c0cf34a..82aace69e 100644 --- a/NzbDrone.Core/CentralDispatch.cs +++ b/NzbDrone.Core/CentralDispatch.cs @@ -75,7 +75,7 @@ namespace NzbDrone.Core var logRepository = new SimpleRepository(logDbProvider, SimpleRepositoryOptions.RunMigrations); //dbProvider.ExecuteQuery(new QueryCommand("VACUUM", dbProvider)); - dbProvider.Log = new NlogWriter(); + //dbProvider.Log = new NlogWriter(); _kernel.Bind().ToSelf().InSingletonScope(); _kernel.Bind().ToSelf().InTransientScope(); diff --git a/NzbDrone.Core/Providers/SeriesProvider.cs b/NzbDrone.Core/Providers/SeriesProvider.cs index b3a9b823f..18958712d 100644 --- a/NzbDrone.Core/Providers/SeriesProvider.cs +++ b/NzbDrone.Core/Providers/SeriesProvider.cs @@ -108,6 +108,7 @@ namespace NzbDrone.Core.Providers public virtual Series FindSeries(string title) { + //TODO:Add series alias support here. if a series is not found in the repo should be tried using its aliases var normalizeTitle = Parser.NormalizeTitle(title); return _repository.Single(s => s.CleanTitle == normalizeTitle); } diff --git a/NzbDrone.Web/log.config b/NzbDrone.Web/log.config index ac57d4f6d..8abd77ebc 100644 --- a/NzbDrone.Web/log.config +++ b/NzbDrone.Web/log.config @@ -9,10 +9,10 @@ - -