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

Closes #5654
Closes #5682
Closes #5780

(cherry picked from commit ca34f64eb0a8f26be66030988284b17c9d65f460)
pull/5827/head
Mark McDowall 4 years ago committed by Qstick
parent 07f5312d43
commit 986f8d43c0

@ -37,7 +37,6 @@ namespace NzbDrone.Core.Test.Download
_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.RemoteMovie = remoteMovie) .With(c => c.RemoteMovie = remoteMovie)
.Build(); .Build();
@ -61,6 +60,10 @@ namespace NzbDrone.Core.Test.Download
Mocker.GetMock<IHistoryService>() Mocker.GetMock<IHistoryService>()
.Setup(s => s.FindByDownloadId(It.IsAny<string>())) .Setup(s => s.FindByDownloadId(It.IsAny<string>()))
.Returns(new List<MovieHistory>()); .Returns(new List<MovieHistory>());
Mocker.GetMock<IProvideImportItemService>()
.Setup(s => s.ProvideImportItem(It.IsAny<DownloadClientItem>(), It.IsAny<DownloadClientItem>()))
.Returns<DownloadClientItem, DownloadClientItem>((i, p) => i);
} }
private RemoteMovie BuildRemoteMovie() private RemoteMovie BuildRemoteMovie()

@ -27,7 +27,7 @@ namespace NzbDrone.Core.Download
{ {
private readonly IEventAggregator _eventAggregator; private readonly IEventAggregator _eventAggregator;
private readonly IHistoryService _historyService; private readonly IHistoryService _historyService;
private readonly IProvideImportItemService _importItemService; private readonly IProvideImportItemService _provideImportItemService;
private readonly IDownloadedMovieImportService _downloadedMovieImportService; private readonly IDownloadedMovieImportService _downloadedMovieImportService;
private readonly IParsingService _parsingService; private readonly IParsingService _parsingService;
private readonly IMovieService _movieService; private readonly IMovieService _movieService;
@ -36,7 +36,7 @@ namespace NzbDrone.Core.Download
public CompletedDownloadService(IEventAggregator eventAggregator, public CompletedDownloadService(IEventAggregator eventAggregator,
IHistoryService historyService, IHistoryService historyService,
IProvideImportItemService importItemService, IProvideImportItemService provideImportItemService,
IDownloadedMovieImportService downloadedMovieImportService, IDownloadedMovieImportService downloadedMovieImportService,
IParsingService parsingService, IParsingService parsingService,
IMovieService movieService, IMovieService movieService,
@ -45,7 +45,7 @@ namespace NzbDrone.Core.Download
{ {
_eventAggregator = eventAggregator; _eventAggregator = eventAggregator;
_historyService = historyService; _historyService = historyService;
_importItemService = importItemService; _provideImportItemService = provideImportItemService;
_downloadedMovieImportService = downloadedMovieImportService; _downloadedMovieImportService = downloadedMovieImportService;
_parsingService = parsingService; _parsingService = parsingService;
_movieService = movieService; _movieService = movieService;
@ -60,7 +60,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)
@ -76,18 +76,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;
} }
@ -112,6 +102,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;
@ -202,5 +199,30 @@ namespace NzbDrone.Core.Download
_logger.Debug("Not all movies have been imported for {0}", trackedDownload.DownloadItem.Title); _logger.Debug("Not all movies 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