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 @@ public Response HandleException(NancyContext context, Exception exception) { _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 @@ protected NzbDroneException(string message, params object[] args) } - 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 @@ namespace NzbDrone.Core.Configuration { + public enum ConfigKey + { + DownloadedEpisodesFolder + } + public class ConfigService : IConfigService { private readonly IConfigRepository _repository; @@ -118,9 +123,9 @@ public SabPriorityType SabOlderTvPriority 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 @@ public string SeasonFolderFormat 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.IO; using NLog; using NzbDrone.Common; +using NzbDrone.Core.Configuration; using NzbDrone.Core.Datastore; using NzbDrone.Core.Tv; @@ -26,12 +27,17 @@ public class RootFolderService : IRootFolderService 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 @@ public virtual RootFolder Add(RootFolder rootFolder) 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 @@ public interface ISeriesRepository : IBasicRepository { 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 @@ public Series FindBySlug(string slug) { 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 @@ public interface ISeriesService bool SeriesPathExists(string folder); List GetSeriesInList(IEnumerable seriesIds); Series FindBySlug(string slug); + List GetSeriesPaths(); } public class SeriesService : ISeriesService @@ -112,6 +113,11 @@ public Series FindBySlug(string slug) return series; } + public List GetSeriesPaths() + { + return _seriesRepository.GetSeriesPaths(); + } + public Series FindByTitle(string title) { var tvdbId = _sceneMappingService.GetTvDbId(title);