From b3352564fa75bf360d8925de01368731d371454e Mon Sep 17 00:00:00 2001 From: Qstick Date: Sun, 24 Jan 2021 21:44:00 -0500 Subject: [PATCH] Fixed: Update path before importing to ensure it hasn't changed Fixes #1847 --- .../Download/CompletedDownloadService.cs | 52 +++++++++++++------ 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/src/NzbDrone.Core/Download/CompletedDownloadService.cs b/src/NzbDrone.Core/Download/CompletedDownloadService.cs index df0ef5a1b..9fa38e029 100644 --- a/src/NzbDrone.Core/Download/CompletedDownloadService.cs +++ b/src/NzbDrone.Core/Download/CompletedDownloadService.cs @@ -26,19 +26,19 @@ namespace NzbDrone.Core.Download private readonly IHistoryService _historyService; private readonly IDownloadedTracksImportService _downloadedTracksImportService; private readonly IArtistService _artistService; - private readonly IProvideImportItemService _importItemService; + private readonly IProvideImportItemService _provideImportItemService; private readonly ITrackedDownloadAlreadyImported _trackedDownloadAlreadyImported; public CompletedDownloadService(IEventAggregator eventAggregator, IHistoryService historyService, - IProvideImportItemService importItemService, + IProvideImportItemService provideImportItemService, IDownloadedTracksImportService downloadedTracksImportService, IArtistService artistService, ITrackedDownloadAlreadyImported trackedDownloadAlreadyImported) { _eventAggregator = eventAggregator; _historyService = historyService; - _importItemService = importItemService; + _provideImportItemService = provideImportItemService; _downloadedTracksImportService = downloadedTracksImportService; _artistService = artistService; _trackedDownloadAlreadyImported = trackedDownloadAlreadyImported; @@ -52,7 +52,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) @@ -68,18 +68,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; } @@ -104,6 +94,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; @@ -169,5 +166,30 @@ namespace NzbDrone.Core.Download return; } } + + 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; + } } }