1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-14 11:23:42 +02:00

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

Closes #4206
This commit is contained in:
Mark McDowall 2020-12-30 14:01:01 -08:00
parent c7b950f213
commit ca34f64eb0
2 changed files with 37 additions and 15 deletions

View File

@ -28,7 +28,7 @@ public class CompletedDownloadService : ICompletedDownloadService
{ {
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 IDownloadedEpisodesImportService _downloadedEpisodesImportService; private readonly IDownloadedEpisodesImportService _downloadedEpisodesImportService;
private readonly IParsingService _parsingService; private readonly IParsingService _parsingService;
private readonly ISeriesService _seriesService; private readonly ISeriesService _seriesService;
@ -37,7 +37,7 @@ public class CompletedDownloadService : ICompletedDownloadService
public CompletedDownloadService(IEventAggregator eventAggregator, public CompletedDownloadService(IEventAggregator eventAggregator,
IHistoryService historyService, IHistoryService historyService,
IProvideImportItemService importItemService, IProvideImportItemService provideImportItemService,
IDownloadedEpisodesImportService downloadedEpisodesImportService, IDownloadedEpisodesImportService downloadedEpisodesImportService,
IParsingService parsingService, IParsingService parsingService,
ISeriesService seriesService, ISeriesService seriesService,
@ -46,7 +46,7 @@ public CompletedDownloadService(IEventAggregator eventAggregator,
{ {
_eventAggregator = eventAggregator; _eventAggregator = eventAggregator;
_historyService = historyService; _historyService = historyService;
_importItemService = importItemService; _provideImportItemService = provideImportItemService;
_downloadedEpisodesImportService = downloadedEpisodesImportService; _downloadedEpisodesImportService = downloadedEpisodesImportService;
_parsingService = parsingService; _parsingService = parsingService;
_seriesService = seriesService; _seriesService = seriesService;
@ -61,7 +61,7 @@ public void Check(TrackedDownload trackedDownload)
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)
@ -77,18 +77,8 @@ public void Check(TrackedDownload trackedDownload)
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;
} }
@ -113,6 +103,13 @@ public void Check(TrackedDownload trackedDownload)
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;
@ -204,5 +201,30 @@ public bool VerifyImport(TrackedDownload trackedDownload, List<ImportResult> imp
_logger.Debug("Not all episodes have been imported for {0}", trackedDownload.DownloadItem.Title); _logger.Debug("Not all episodes 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;
}
} }
} }