From 485f05d4b910970c7bbd80f45496e69497b8d7ba Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Fri, 2 Aug 2013 00:16:37 -0700 Subject: [PATCH] Prevent adding a root folder that is the same as drone factory --- .../ErrorManagement/NzbDroneErrorPipeline.cs | 6 +++--- NzbDrone.Common/Exceptions/NzbDroneException.cs | 2 -- NzbDrone.Core/Configuration/ConfigService.cs | 10 +++++++--- NzbDrone.Core/RootFolders/RootFolderService.cs | 13 +++++++++++-- NzbDrone.Core/Tv/SeriesRepository.cs | 7 ++++++- NzbDrone.Core/Tv/SeriesService.cs | 6 ++++++ 6 files changed, 33 insertions(+), 11 deletions(-) diff --git a/NzbDrone.Api/ErrorManagement/NzbDroneErrorPipeline.cs b/NzbDrone.Api/ErrorManagement/NzbDroneErrorPipeline.cs index 871bc0e2b..0deee3096 100644 --- a/NzbDrone.Api/ErrorManagement/NzbDroneErrorPipeline.cs +++ b/NzbDrone.Api/ErrorManagement/NzbDroneErrorPipeline.cs @@ -1,8 +1,11 @@ using System; +using System.Net; using FluentValidation; using NLog; using Nancy; using NzbDrone.Api.Extensions; +using NzbDrone.Common.Exceptions; +using HttpStatusCode = Nancy.HttpStatusCode; namespace NzbDrone.Api.ErrorManagement { @@ -31,14 +34,11 @@ namespace NzbDrone.Api.ErrorManagement { _logger.Warn("Invalid request {0}", validationException.Message); - return validationException.Errors.AsResponse(HttpStatusCode.BadRequest); - } _logger.FatalException("Request Failed", exception); - return new ErrorModel() { Message = exception.Message, diff --git a/NzbDrone.Common/Exceptions/NzbDroneException.cs b/NzbDrone.Common/Exceptions/NzbDroneException.cs index 484b05bac..09b431fc6 100644 --- a/NzbDrone.Common/Exceptions/NzbDroneException.cs +++ b/NzbDrone.Common/Exceptions/NzbDroneException.cs @@ -12,12 +12,10 @@ namespace NzbDrone.Common.Exceptions } - protected NzbDroneException(string message) : base(message) { } } - } diff --git a/NzbDrone.Core/Configuration/ConfigService.cs b/NzbDrone.Core/Configuration/ConfigService.cs index 18a02490b..fe0896dfe 100644 --- a/NzbDrone.Core/Configuration/ConfigService.cs +++ b/NzbDrone.Core/Configuration/ConfigService.cs @@ -8,6 +8,11 @@ using NzbDrone.Core.Download.Clients.Sabnzbd; namespace NzbDrone.Core.Configuration { + public enum ConfigKey + { + DownloadedEpisodesFolder + } + public class ConfigService : IConfigService { private readonly IConfigRepository _repository; @@ -118,9 +123,9 @@ namespace NzbDrone.Core.Configuration public String DownloadedEpisodesFolder { - get { return GetValue("DownloadedEpisodesFolder"); } + get { return GetValue(ConfigKey.DownloadedEpisodesFolder.ToString()); } - set { SetValue("DownloadedEpisodesFolder", value); } + set { SetValue(ConfigKey.DownloadedEpisodesFolder.ToString(), value); } } public bool UseSeasonFolder @@ -136,7 +141,6 @@ namespace NzbDrone.Core.Configuration set { SetValue("SeasonFolderFormat", value); } } - public bool AutoUnmonitorPreviouslyDownloadedEpisodes { get { return GetValueBoolean("AutoUnmonitorPreviouslyDownloadedEpisodes"); } diff --git a/NzbDrone.Core/RootFolders/RootFolderService.cs b/NzbDrone.Core/RootFolders/RootFolderService.cs index 86fd61679..505a17997 100644 --- a/NzbDrone.Core/RootFolders/RootFolderService.cs +++ b/NzbDrone.Core/RootFolders/RootFolderService.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.IO; using NLog; using NzbDrone.Common; +using NzbDrone.Core.Configuration; using NzbDrone.Core.Datastore; using NzbDrone.Core.Tv; @@ -26,12 +27,17 @@ namespace NzbDrone.Core.RootFolders private readonly IBasicRepository _rootFolderRepository; private readonly IDiskProvider _diskProvider; private readonly ISeriesRepository _seriesRepository; + private readonly IConfigService _configService; - public RootFolderService(IBasicRepository rootFolderRepository, IDiskProvider diskProvider,ISeriesRepository seriesRepository) + public RootFolderService(IBasicRepository rootFolderRepository, + IDiskProvider diskProvider, + ISeriesRepository seriesRepository, + IConfigService configService) { _rootFolderRepository = rootFolderRepository; _diskProvider = diskProvider; _seriesRepository = seriesRepository; + _configService = configService; } public virtual List All() @@ -66,7 +72,10 @@ namespace NzbDrone.Core.RootFolders throw new DirectoryNotFoundException("Can't add root directory that doesn't exist."); if (All().Exists(r => DiskProvider.PathEquals(r.Path, rootFolder.Path))) - throw new InvalidOperationException("Root directory already exist."); + throw new InvalidOperationException("Recent directory already exist."); + + if (DiskProvider.PathEquals(_configService.DownloadedEpisodesFolder, rootFolder.Path)) + throw new InvalidOperationException("Drone Factory folder cannot be used."); _rootFolderRepository.Insert(rootFolder); diff --git a/NzbDrone.Core/Tv/SeriesRepository.cs b/NzbDrone.Core/Tv/SeriesRepository.cs index a07a62ae4..74bbf258e 100644 --- a/NzbDrone.Core/Tv/SeriesRepository.cs +++ b/NzbDrone.Core/Tv/SeriesRepository.cs @@ -10,11 +10,11 @@ namespace NzbDrone.Core.Tv { bool SeriesPathExists(string path); List Search(string title); - Series FindByTitle(string cleanTitle); Series FindByTvdbId(int tvdbId); void SetSeriesType(int seriesId, SeriesTypes seriesTypes); Series FindBySlug(string slug); + List GetSeriesPaths(); } public class SeriesRepository : BasicRepository, ISeriesRepository @@ -53,5 +53,10 @@ namespace NzbDrone.Core.Tv { return Query.SingleOrDefault(c => c.TitleSlug == slug.ToLower()); } + + public List GetSeriesPaths() + { + return Query.Select(s => s.Path).ToList(); + } } } \ No newline at end of file diff --git a/NzbDrone.Core/Tv/SeriesService.cs b/NzbDrone.Core/Tv/SeriesService.cs index c6176bb65..e6e311247 100644 --- a/NzbDrone.Core/Tv/SeriesService.cs +++ b/NzbDrone.Core/Tv/SeriesService.cs @@ -27,6 +27,7 @@ namespace NzbDrone.Core.Tv bool SeriesPathExists(string folder); List GetSeriesInList(IEnumerable seriesIds); Series FindBySlug(string slug); + List GetSeriesPaths(); } public class SeriesService : ISeriesService @@ -112,6 +113,11 @@ namespace NzbDrone.Core.Tv return series; } + public List GetSeriesPaths() + { + return _seriesRepository.GetSeriesPaths(); + } + public Series FindByTitle(string title) { var tvdbId = _sceneMappingService.GetTvDbId(title);