From 081c5fc33269666dfb1033f3510a1fb8eaf93137 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Mon, 6 Mar 2017 11:00:38 -0800 Subject: [PATCH] Broken ExtraFiles migration due to extentionless files Fixed: Prevent extensionless files from being imported Fixed: Broken migration due to extensionless extra files --- ...108_fix_metadata_file_extensionsFixture.cs | 22 +++++++++++++++++++ .../Migration/108_fix_extra_file_extension.cs | 4 ++++ .../Others/ExistingOtherExtraImporter.cs | 10 ++++++++- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/NzbDrone.Core.Test/Datastore/Migration/108_fix_metadata_file_extensionsFixture.cs b/src/NzbDrone.Core.Test/Datastore/Migration/108_fix_metadata_file_extensionsFixture.cs index 1eb0bd802..5a8a1fe02 100644 --- a/src/NzbDrone.Core.Test/Datastore/Migration/108_fix_metadata_file_extensionsFixture.cs +++ b/src/NzbDrone.Core.Test/Datastore/Migration/108_fix_metadata_file_extensionsFixture.cs @@ -10,6 +10,28 @@ namespace NzbDrone.Core.Test.Datastore.Migration [TestFixture] public class fix_extra_file_extensionsFixture : MigrationTest { + [Test] + public void should_extra_files_that_do_not_have_an_extension() + { + var db = WithMigrationTestDb(c => + { + c.Insert.IntoTable("ExtraFiles").Row(new + { + SeriesId = 1, + SeasonNumber = 1, + EpisodeFileId = 1, + RelativePath = "Series.Title.S01E01", + Added = "2016-05-30 20:23:02.3725923", + LastUpdated = "2016-05-30 20:23:02.3725923", + Extension = "" + }); + }); + + var items = db.Query("Select * from ExtraFiles"); + + items.Should().BeEmpty(); + } + [Test] public void should_fix_double_extension() { diff --git a/src/NzbDrone.Core/Datastore/Migration/108_fix_extra_file_extension.cs b/src/NzbDrone.Core/Datastore/Migration/108_fix_extra_file_extension.cs index 3093ebbda..bce22cb6c 100644 --- a/src/NzbDrone.Core/Datastore/Migration/108_fix_extra_file_extension.cs +++ b/src/NzbDrone.Core/Datastore/Migration/108_fix_extra_file_extension.cs @@ -10,6 +10,10 @@ public class fix_extra_file_extension : NzbDroneMigrationBase { protected override void MainDbUpgrade() { + // Delete extraneous files without extensions that Sonarr found previously, + // these will be blocked from importing as well. + Execute.Sql("DELETE FROM ExtraFiles WHERE TRIM(Extension) = ''"); + Execute.WithConnection(FixExtraFileExtension); } diff --git a/src/NzbDrone.Core/Extras/Others/ExistingOtherExtraImporter.cs b/src/NzbDrone.Core/Extras/Others/ExistingOtherExtraImporter.cs index 6315daeb1..05afb5645 100644 --- a/src/NzbDrone.Core/Extras/Others/ExistingOtherExtraImporter.cs +++ b/src/NzbDrone.Core/Extras/Others/ExistingOtherExtraImporter.cs @@ -36,6 +36,14 @@ public override IEnumerable ProcessFiles(Series series, List foreach (var possibleExtraFile in filterResult.FilesOnDisk) { + var extension = Path.GetExtension(possibleExtraFile); + + if (extension.IsNullOrWhiteSpace()) + { + _logger.Debug("No extension for file: {0}", possibleExtraFile); + continue; + } + var localEpisode = _parsingService.GetLocalEpisode(possibleExtraFile, series); if (localEpisode == null) @@ -62,7 +70,7 @@ public override IEnumerable ProcessFiles(Series series, List SeasonNumber = localEpisode.SeasonNumber, EpisodeFileId = localEpisode.Episodes.First().EpisodeFileId, RelativePath = series.Path.GetRelativePath(possibleExtraFile), - Extension = Path.GetExtension(possibleExtraFile) + Extension = extension }; extraFiles.Add(extraFile);