From a1f02916d42154d69676aa8e671e913096c73e61 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Wed, 9 Jan 2019 17:51:54 -0800 Subject: [PATCH] Fixed: Importing of completed download when not a child of the download client output path --- .../MediaFiles/ImportApprovedEpisodesFixture.cs | 16 ++++++++++++++++ .../EpisodeImport/ImportApprovedEpisodes.cs | 10 ++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/NzbDrone.Core.Test/MediaFiles/ImportApprovedEpisodesFixture.cs b/src/NzbDrone.Core.Test/MediaFiles/ImportApprovedEpisodesFixture.cs index 5606044e5..e1e5e1d5a 100644 --- a/src/NzbDrone.Core.Test/MediaFiles/ImportApprovedEpisodesFixture.cs +++ b/src/NzbDrone.Core.Test/MediaFiles/ImportApprovedEpisodesFixture.cs @@ -349,5 +349,21 @@ public void should_get_relative_path_when_there_is_no_grandparent_for_UNC_path() Mocker.GetMock().Verify(v => v.Add(It.Is(c => c.OriginalFilePath == $"{name}.mkv"))); } + + [Test] + public void should_use_folder_info_release_title_to_find_relative_path_when_file_is_not_in_download_client_item_output_directory() + { + var name = "Series.Title.S01E01.720p.HDTV.x264-Sonarr"; + var outputPath = Path.Combine(@"C:\Test\Unsorted\TV\".AsOsAgnostic(), name); + var localEpisode = _approvedDecisions.First().LocalEpisode; + + _downloadClientItem.OutputPath = new OsPath(Path.Combine(@"C:\Test\Unsorted\TV-Other\".AsOsAgnostic(), name)); + localEpisode.FolderEpisodeInfo = new ParsedEpisodeInfo { ReleaseTitle = name }; + localEpisode.Path = Path.Combine(outputPath, "subfolder", name + ".mkv"); + + Subject.Import(new List { _approvedDecisions.First() }, true, _downloadClientItem); + + Mocker.GetMock().Verify(v => v.Add(It.Is(c => c.OriginalFilePath == $"{name}\\subfolder\\{name}.mkv".AsOsAgnostic()))); + } } } diff --git a/src/NzbDrone.Core/MediaFiles/EpisodeImport/ImportApprovedEpisodes.cs b/src/NzbDrone.Core/MediaFiles/EpisodeImport/ImportApprovedEpisodes.cs index fb88ad8bf..f44dcdf0a 100644 --- a/src/NzbDrone.Core/MediaFiles/EpisodeImport/ImportApprovedEpisodes.cs +++ b/src/NzbDrone.Core/MediaFiles/EpisodeImport/ImportApprovedEpisodes.cs @@ -151,12 +151,18 @@ public List Import(List decisions, bool newDownloa private string GetOriginalFilePath(DownloadClientItem downloadClientItem, LocalEpisode localEpisode) { + var path = localEpisode.Path; + if (downloadClientItem != null) { - return downloadClientItem.OutputPath.Directory.ToString().GetRelativePath(localEpisode.Path); + var outputDirectory = downloadClientItem.OutputPath.Directory.ToString(); + + if (outputDirectory.IsParentPath(path)) + { + return outputDirectory.GetRelativePath(path); + } } - var path = localEpisode.Path; var folderEpisodeInfo = localEpisode.FolderEpisodeInfo; if (folderEpisodeInfo != null)