Fixed: Update path before importing to ensure it hasn't changed

Closes #684
pull/1392/head
Mark McDowall 4 years ago committed by ta264
parent b3c217d713
commit 16fcba02ba

@ -38,7 +38,6 @@ namespace NzbDrone.Core.Test.Download.CompletedDownloadServiceTests
_trackedDownload = Builder<TrackedDownload>.CreateNew() _trackedDownload = Builder<TrackedDownload>.CreateNew()
.With(c => c.State = TrackedDownloadState.Downloading) .With(c => c.State = TrackedDownloadState.Downloading)
.With(c => c.ImportItem = completed)
.With(c => c.DownloadItem = completed) .With(c => c.DownloadItem = completed)
.With(c => c.RemoteBook = remoteBook) .With(c => c.RemoteBook = remoteBook)
.Build(); .Build();
@ -65,6 +64,10 @@ namespace NzbDrone.Core.Test.Download.CompletedDownloadServiceTests
Mocker.GetMock<IHistoryService>() Mocker.GetMock<IHistoryService>()
.Setup(s => s.FindByDownloadId(It.IsAny<string>())) .Setup(s => s.FindByDownloadId(It.IsAny<string>()))
.Returns(new List<EntityHistory>()); .Returns(new List<EntityHistory>());
Mocker.GetMock<IProvideImportItemService>()
.Setup(s => s.ProvideImportItem(It.IsAny<DownloadClientItem>(), It.IsAny<DownloadClientItem>()))
.Returns<DownloadClientItem, DownloadClientItem>((i, p) => i);
} }
private Book CreateBook(int id) private Book CreateBook(int id)

@ -27,21 +27,21 @@ namespace NzbDrone.Core.Download
{ {
private readonly IEventAggregator _eventAggregator; private readonly IEventAggregator _eventAggregator;
private readonly IHistoryService _historyService; private readonly IHistoryService _historyService;
private readonly IProvideImportItemService _provideImportItemService;
private readonly IDownloadedBooksImportService _downloadedTracksImportService; private readonly IDownloadedBooksImportService _downloadedTracksImportService;
private readonly IProvideImportItemService _importItemService;
private readonly ITrackedDownloadAlreadyImported _trackedDownloadAlreadyImported; private readonly ITrackedDownloadAlreadyImported _trackedDownloadAlreadyImported;
private readonly Logger _logger; private readonly Logger _logger;
public CompletedDownloadService(IEventAggregator eventAggregator, public CompletedDownloadService(IEventAggregator eventAggregator,
IHistoryService historyService, IHistoryService historyService,
IProvideImportItemService importItemService, IProvideImportItemService provideImportItemService,
IDownloadedBooksImportService downloadedTracksImportService, IDownloadedBooksImportService downloadedTracksImportService,
ITrackedDownloadAlreadyImported trackedDownloadAlreadyImported, ITrackedDownloadAlreadyImported trackedDownloadAlreadyImported,
Logger logger) Logger logger)
{ {
_eventAggregator = eventAggregator; _eventAggregator = eventAggregator;
_historyService = historyService; _historyService = historyService;
_importItemService = importItemService; _provideImportItemService = provideImportItemService;
_downloadedTracksImportService = downloadedTracksImportService; _downloadedTracksImportService = downloadedTracksImportService;
_trackedDownloadAlreadyImported = trackedDownloadAlreadyImported; _trackedDownloadAlreadyImported = trackedDownloadAlreadyImported;
_logger = logger; _logger = logger;
@ -54,7 +54,7 @@ namespace NzbDrone.Core.Download
return; return;
} }
trackedDownload.ImportItem = _importItemService.ProvideImportItem(trackedDownload.DownloadItem, trackedDownload.ImportItem); SetImportItem(trackedDownload);
// Only process tracked downloads that are still downloading // Only process tracked downloads that are still downloading
if (trackedDownload.State != TrackedDownloadState.Downloading) if (trackedDownload.State != TrackedDownloadState.Downloading)
@ -70,18 +70,8 @@ namespace NzbDrone.Core.Download
return; return;
} }
var downloadItemOutputPath = trackedDownload.ImportItem.OutputPath; if (!ValidatePath(trackedDownload))
if (downloadItemOutputPath.IsEmpty)
{
trackedDownload.Warn("Download doesn't contain intermediate path, Skipping.");
return;
}
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; return;
} }
@ -90,6 +80,13 @@ namespace NzbDrone.Core.Download
public void Import(TrackedDownload trackedDownload) public void Import(TrackedDownload trackedDownload)
{ {
SetImportItem(trackedDownload);
if (!ValidatePath(trackedDownload))
{
return;
}
trackedDownload.State = TrackedDownloadState.Importing; trackedDownload.State = TrackedDownloadState.Importing;
var outputPath = trackedDownload.ImportItem.OutputPath.FullPath; var outputPath = trackedDownload.ImportItem.OutputPath.FullPath;
@ -190,5 +187,30 @@ namespace NzbDrone.Core.Download
_logger.Debug("Not all books have been imported for {0}", trackedDownload.DownloadItem.Title); _logger.Debug("Not all books have been imported for {0}", trackedDownload.DownloadItem.Title);
return false; 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;
}
} }
} }

Loading…
Cancel
Save