diff --git a/src/NzbDrone.Core.Test/MediaFiles/EpisodeFileMovingServiceTests/MoveEpisodeFileFixture.cs b/src/NzbDrone.Core.Test/MediaFiles/EpisodeFileMovingServiceTests/MoveEpisodeFileFixture.cs index f8575915d..41ed18709 100644 --- a/src/NzbDrone.Core.Test/MediaFiles/EpisodeFileMovingServiceTests/MoveEpisodeFileFixture.cs +++ b/src/NzbDrone.Core.Test/MediaFiles/EpisodeFileMovingServiceTests/MoveEpisodeFileFixture.cs @@ -12,6 +12,7 @@ using NzbDrone.Core.MediaFiles.Events; using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Organizer; using NzbDrone.Core.Parser.Model; +using NzbDrone.Core.RootFolders; using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Tv; using NzbDrone.Test.Common; @@ -51,6 +52,11 @@ namespace NzbDrone.Core.Test.MediaFiles.EpisodeFileMovingServiceTests .Returns(@"C:\Test\TV\Series\Season 01".AsOsAgnostic()); var rootFolder = @"C:\Test\TV\".AsOsAgnostic(); + + Mocker.GetMock() + .Setup(s => s.GetBestRootFolderPath(It.IsAny())) + .Returns(rootFolder); + Mocker.GetMock() .Setup(s => s.FolderExists(rootFolder)) .Returns(true); diff --git a/src/NzbDrone.Core/MediaFiles/EpisodeFileMovingService.cs b/src/NzbDrone.Core/MediaFiles/EpisodeFileMovingService.cs index 2518df234..6bf474d94 100644 --- a/src/NzbDrone.Core/MediaFiles/EpisodeFileMovingService.cs +++ b/src/NzbDrone.Core/MediaFiles/EpisodeFileMovingService.cs @@ -12,6 +12,7 @@ using NzbDrone.Core.MediaFiles.Events; using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Organizer; using NzbDrone.Core.Parser.Model; +using NzbDrone.Core.RootFolders; using NzbDrone.Core.Tv; namespace NzbDrone.Core.MediaFiles @@ -32,6 +33,7 @@ namespace NzbDrone.Core.MediaFiles private readonly IDiskProvider _diskProvider; private readonly IMediaFileAttributeService _mediaFileAttributeService; private readonly IImportScript _scriptImportDecider; + private readonly IRootFolderService _rootFolderService; private readonly IEventAggregator _eventAggregator; private readonly IConfigService _configService; private readonly Logger _logger; @@ -43,6 +45,7 @@ namespace NzbDrone.Core.MediaFiles IDiskProvider diskProvider, IMediaFileAttributeService mediaFileAttributeService, IImportScript scriptImportDecider, + IRootFolderService rootFolderService, IEventAggregator eventAggregator, IConfigService configService, Logger logger) @@ -54,6 +57,7 @@ namespace NzbDrone.Core.MediaFiles _diskProvider = diskProvider; _mediaFileAttributeService = mediaFileAttributeService; _scriptImportDecider = scriptImportDecider; + _rootFolderService = rootFolderService; _eventAggregator = eventAggregator; _configService = configService; _logger = logger; @@ -180,11 +184,16 @@ namespace NzbDrone.Core.MediaFiles var episodeFolder = Path.GetDirectoryName(filePath); var seasonFolder = _buildFileNames.BuildSeasonPath(series, seasonNumber); var seriesFolder = series.Path; - var rootFolder = new OsPath(seriesFolder).Directory.FullPath; + var rootFolder = _rootFolderService.GetBestRootFolderPath(seriesFolder); + + if (rootFolder.IsNullOrWhiteSpace()) + { + throw new RootFolderNotFoundException($"Root folder was not found, '{seriesFolder}' is not a subdirectory of a defined root folder."); + } if (!_diskProvider.FolderExists(rootFolder)) { - throw new RootFolderNotFoundException(string.Format("Root folder '{0}' was not found.", rootFolder)); + throw new RootFolderNotFoundException($"Root folder '{rootFolder}' was not found."); } var changed = false;