1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

Prevent adding a root folder that is the same as drone factory

This commit is contained in:
Mark McDowall 2013-08-02 00:16:37 -07:00
parent e3916d5fc8
commit 485f05d4b9
6 changed files with 33 additions and 11 deletions

View File

@ -1,8 +1,11 @@
using System; using System;
using System.Net;
using FluentValidation; using FluentValidation;
using NLog; using NLog;
using Nancy; using Nancy;
using NzbDrone.Api.Extensions; using NzbDrone.Api.Extensions;
using NzbDrone.Common.Exceptions;
using HttpStatusCode = Nancy.HttpStatusCode;
namespace NzbDrone.Api.ErrorManagement namespace NzbDrone.Api.ErrorManagement
{ {
@ -31,14 +34,11 @@ public Response HandleException(NancyContext context, Exception exception)
{ {
_logger.Warn("Invalid request {0}", validationException.Message); _logger.Warn("Invalid request {0}", validationException.Message);
return validationException.Errors.AsResponse(HttpStatusCode.BadRequest); return validationException.Errors.AsResponse(HttpStatusCode.BadRequest);
} }
_logger.FatalException("Request Failed", exception); _logger.FatalException("Request Failed", exception);
return new ErrorModel() return new ErrorModel()
{ {
Message = exception.Message, Message = exception.Message,

View File

@ -12,12 +12,10 @@ protected NzbDroneException(string message, params object[] args)
} }
protected NzbDroneException(string message) protected NzbDroneException(string message)
: base(message) : base(message)
{ {
} }
} }
} }

View File

@ -8,6 +8,11 @@
namespace NzbDrone.Core.Configuration namespace NzbDrone.Core.Configuration
{ {
public enum ConfigKey
{
DownloadedEpisodesFolder
}
public class ConfigService : IConfigService public class ConfigService : IConfigService
{ {
private readonly IConfigRepository _repository; private readonly IConfigRepository _repository;
@ -118,9 +123,9 @@ public SabPriorityType SabOlderTvPriority
public String DownloadedEpisodesFolder 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 public bool UseSeasonFolder
@ -136,7 +141,6 @@ public string SeasonFolderFormat
set { SetValue("SeasonFolderFormat", value); } set { SetValue("SeasonFolderFormat", value); }
} }
public bool AutoUnmonitorPreviouslyDownloadedEpisodes public bool AutoUnmonitorPreviouslyDownloadedEpisodes
{ {
get { return GetValueBoolean("AutoUnmonitorPreviouslyDownloadedEpisodes"); } get { return GetValueBoolean("AutoUnmonitorPreviouslyDownloadedEpisodes"); }

View File

@ -4,6 +4,7 @@
using System.IO; using System.IO;
using NLog; using NLog;
using NzbDrone.Common; using NzbDrone.Common;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Datastore; using NzbDrone.Core.Datastore;
using NzbDrone.Core.Tv; using NzbDrone.Core.Tv;
@ -26,12 +27,17 @@ public class RootFolderService : IRootFolderService
private readonly IBasicRepository<RootFolder> _rootFolderRepository; private readonly IBasicRepository<RootFolder> _rootFolderRepository;
private readonly IDiskProvider _diskProvider; private readonly IDiskProvider _diskProvider;
private readonly ISeriesRepository _seriesRepository; private readonly ISeriesRepository _seriesRepository;
private readonly IConfigService _configService;
public RootFolderService(IBasicRepository<RootFolder> rootFolderRepository, IDiskProvider diskProvider,ISeriesRepository seriesRepository) public RootFolderService(IBasicRepository<RootFolder> rootFolderRepository,
IDiskProvider diskProvider,
ISeriesRepository seriesRepository,
IConfigService configService)
{ {
_rootFolderRepository = rootFolderRepository; _rootFolderRepository = rootFolderRepository;
_diskProvider = diskProvider; _diskProvider = diskProvider;
_seriesRepository = seriesRepository; _seriesRepository = seriesRepository;
_configService = configService;
} }
public virtual List<RootFolder> All() public virtual List<RootFolder> All()
@ -66,7 +72,10 @@ public virtual RootFolder Add(RootFolder rootFolder)
throw new DirectoryNotFoundException("Can't add root directory that doesn't exist."); throw new DirectoryNotFoundException("Can't add root directory that doesn't exist.");
if (All().Exists(r => DiskProvider.PathEquals(r.Path, rootFolder.Path))) 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); _rootFolderRepository.Insert(rootFolder);

View File

@ -10,11 +10,11 @@ public interface ISeriesRepository : IBasicRepository<Series>
{ {
bool SeriesPathExists(string path); bool SeriesPathExists(string path);
List<Series> Search(string title); List<Series> Search(string title);
Series FindByTitle(string cleanTitle); Series FindByTitle(string cleanTitle);
Series FindByTvdbId(int tvdbId); Series FindByTvdbId(int tvdbId);
void SetSeriesType(int seriesId, SeriesTypes seriesTypes); void SetSeriesType(int seriesId, SeriesTypes seriesTypes);
Series FindBySlug(string slug); Series FindBySlug(string slug);
List<String> GetSeriesPaths();
} }
public class SeriesRepository : BasicRepository<Series>, ISeriesRepository public class SeriesRepository : BasicRepository<Series>, ISeriesRepository
@ -53,5 +53,10 @@ public Series FindBySlug(string slug)
{ {
return Query.SingleOrDefault(c => c.TitleSlug == slug.ToLower()); return Query.SingleOrDefault(c => c.TitleSlug == slug.ToLower());
} }
public List<string> GetSeriesPaths()
{
return Query.Select(s => s.Path).ToList();
}
} }
} }

View File

@ -27,6 +27,7 @@ public interface ISeriesService
bool SeriesPathExists(string folder); bool SeriesPathExists(string folder);
List<Series> GetSeriesInList(IEnumerable<int> seriesIds); List<Series> GetSeriesInList(IEnumerable<int> seriesIds);
Series FindBySlug(string slug); Series FindBySlug(string slug);
List<String> GetSeriesPaths();
} }
public class SeriesService : ISeriesService public class SeriesService : ISeriesService
@ -112,6 +113,11 @@ public Series FindBySlug(string slug)
return series; return series;
} }
public List<string> GetSeriesPaths()
{
return _seriesRepository.GetSeriesPaths();
}
public Series FindByTitle(string title) public Series FindByTitle(string title)
{ {
var tvdbId = _sceneMappingService.GetTvDbId(title); var tvdbId = _sceneMappingService.GetTvDbId(title);