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

pull/6/head
Mark McDowall 11 years ago
parent e3916d5fc8
commit 485f05d4b9

@ -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 @@ namespace NzbDrone.Api.ErrorManagement
{ {
_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,

@ -12,12 +12,10 @@ namespace NzbDrone.Common.Exceptions
} }
protected NzbDroneException(string message) protected NzbDroneException(string message)
: base(message) : base(message)
{ {
} }
} }
} }

@ -8,6 +8,11 @@ using NzbDrone.Core.Download.Clients.Sabnzbd;
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 @@ namespace NzbDrone.Core.Configuration
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 @@ namespace NzbDrone.Core.Configuration
set { SetValue("SeasonFolderFormat", value); } set { SetValue("SeasonFolderFormat", value); }
} }
public bool AutoUnmonitorPreviouslyDownloadedEpisodes public bool AutoUnmonitorPreviouslyDownloadedEpisodes
{ {
get { return GetValueBoolean("AutoUnmonitorPreviouslyDownloadedEpisodes"); } get { return GetValueBoolean("AutoUnmonitorPreviouslyDownloadedEpisodes"); }

@ -4,6 +4,7 @@ using System.Collections.Generic;
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 @@ namespace NzbDrone.Core.RootFolders
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 @@ namespace NzbDrone.Core.RootFolders
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);

@ -10,11 +10,11 @@ namespace NzbDrone.Core.Tv
{ {
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 @@ namespace NzbDrone.Core.Tv
{ {
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();
}
} }
} }

@ -27,6 +27,7 @@ namespace NzbDrone.Core.Tv
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 @@ namespace NzbDrone.Core.Tv
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);

Loading…
Cancel
Save