From ca34f64eb0a8f26be66030988284b17c9d65f460 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Wed, 30 Dec 2020 14:01:01 -0800 Subject: [PATCH] Fixed: Update path before importing to ensure it hasn't changed Closes #4206 --- .../Download/CompletedDownloadService.cs | 52 +++++++++++++------ ...Service.cs => ProvideImportItemService.cs} | 0 2 files changed, 37 insertions(+), 15 deletions(-) rename src/NzbDrone.Core/Download/{PrepareImportService.cs => ProvideImportItemService.cs} (100%) diff --git a/src/NzbDrone.Core/Download/CompletedDownloadService.cs b/src/NzbDrone.Core/Download/CompletedDownloadService.cs index 59c5f7a9c..079e35ae5 100644 --- a/src/NzbDrone.Core/Download/CompletedDownloadService.cs +++ b/src/NzbDrone.Core/Download/CompletedDownloadService.cs @@ -28,7 +28,7 @@ namespace NzbDrone.Core.Download { private readonly IEventAggregator _eventAggregator; private readonly IHistoryService _historyService; - private readonly IProvideImportItemService _importItemService; + private readonly IProvideImportItemService _provideImportItemService; private readonly IDownloadedEpisodesImportService _downloadedEpisodesImportService; private readonly IParsingService _parsingService; private readonly ISeriesService _seriesService; @@ -37,7 +37,7 @@ namespace NzbDrone.Core.Download public CompletedDownloadService(IEventAggregator eventAggregator, IHistoryService historyService, - IProvideImportItemService importItemService, + IProvideImportItemService provideImportItemService, IDownloadedEpisodesImportService downloadedEpisodesImportService, IParsingService parsingService, ISeriesService seriesService, @@ -46,7 +46,7 @@ namespace NzbDrone.Core.Download { _eventAggregator = eventAggregator; _historyService = historyService; - _importItemService = importItemService; + _provideImportItemService = provideImportItemService; _downloadedEpisodesImportService = downloadedEpisodesImportService; _parsingService = parsingService; _seriesService = seriesService; @@ -61,7 +61,7 @@ namespace NzbDrone.Core.Download return; } - trackedDownload.ImportItem = _importItemService.ProvideImportItem(trackedDownload.DownloadItem, trackedDownload.ImportItem); + SetImportItem(trackedDownload); // Only process tracked downloads that are still downloading if (trackedDownload.State != TrackedDownloadState.Downloading) @@ -77,18 +77,8 @@ namespace NzbDrone.Core.Download return; } - var downloadItemOutputPath = trackedDownload.ImportItem.OutputPath; - - if (downloadItemOutputPath.IsEmpty) - { - trackedDownload.Warn("Download doesn't contain intermediate path, Skipping."); - return; - } - - if ((OsInfo.IsWindows && !downloadItemOutputPath.IsWindowsPath) || - (OsInfo.IsNotWindows && !downloadItemOutputPath.IsUnixPath)) + if (!ValidatePath(trackedDownload)) { - trackedDownload.Warn("[{0}] is not a valid local path. You may need a Remote Path Mapping.", downloadItemOutputPath); return; } @@ -113,6 +103,13 @@ namespace NzbDrone.Core.Download public void Import(TrackedDownload trackedDownload) { + SetImportItem(trackedDownload); + + if (!ValidatePath(trackedDownload)) + { + return; + } + trackedDownload.State = TrackedDownloadState.Importing; var outputPath = trackedDownload.ImportItem.OutputPath.FullPath; @@ -204,5 +201,30 @@ namespace NzbDrone.Core.Download _logger.Debug("Not all episodes have been imported for {0}", trackedDownload.DownloadItem.Title); return false; } + + private void SetImportItem(TrackedDownload trackedDownload) + { + trackedDownload.ImportItem = _provideImportItemService.ProvideImportItem(trackedDownload.DownloadItem, trackedDownload.ImportItem); + } + + private bool ValidatePath(TrackedDownload trackedDownload) + { + var downloadItemOutputPath = trackedDownload.ImportItem.OutputPath; + + if (downloadItemOutputPath.IsEmpty) + { + trackedDownload.Warn("Download doesn't contain intermediate path, Skipping."); + return false; + } + + if ((OsInfo.IsWindows && !downloadItemOutputPath.IsWindowsPath) || + (OsInfo.IsNotWindows && !downloadItemOutputPath.IsUnixPath)) + { + trackedDownload.Warn("[{0}] is not a valid local path. You may need a Remote Path Mapping.", downloadItemOutputPath); + return false; + } + + return true; + } } } diff --git a/src/NzbDrone.Core/Download/PrepareImportService.cs b/src/NzbDrone.Core/Download/ProvideImportItemService.cs similarity index 100% rename from src/NzbDrone.Core/Download/PrepareImportService.cs rename to src/NzbDrone.Core/Download/ProvideImportItemService.cs