From 8781b78be91501cc33dfe7d9a5ceb7ada7173ba7 Mon Sep 17 00:00:00 2001 From: ta264 Date: Thu, 6 Aug 2020 21:19:46 +0100 Subject: [PATCH] Fixed: Validate calibre connection before saving root folder --- src/NzbDrone.Core/RootFolders/RootFolderService.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/NzbDrone.Core/RootFolders/RootFolderService.cs b/src/NzbDrone.Core/RootFolders/RootFolderService.cs index 368d668b9..f3060ebef 100644 --- a/src/NzbDrone.Core/RootFolders/RootFolderService.cs +++ b/src/NzbDrone.Core/RootFolders/RootFolderService.cs @@ -2,11 +2,15 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Net; using System.Threading.Tasks; using NLog; using NzbDrone.Common; using NzbDrone.Common.Disk; using NzbDrone.Common.Extensions; +using NzbDrone.Common.Http; +using NzbDrone.Core.Books.Calibre; +using NzbDrone.Core.Exceptions; using NzbDrone.Core.MediaFiles; using NzbDrone.Core.MediaFiles.Commands; using NzbDrone.Core.Messaging.Commands; @@ -30,16 +34,19 @@ public class RootFolderService : IRootFolderService { private readonly IRootFolderRepository _rootFolderRepository; private readonly IDiskProvider _diskProvider; + private readonly ICalibreProxy _calibreProxy; private readonly IManageCommandQueue _commandQueueManager; private readonly Logger _logger; public RootFolderService(IRootFolderRepository rootFolderRepository, + ICalibreProxy calibreProxy, IDiskProvider diskProvider, IManageCommandQueue commandQueueManager, Logger logger) { _rootFolderRepository = rootFolderRepository; _diskProvider = diskProvider; + _calibreProxy = calibreProxy; _commandQueueManager = commandQueueManager; _logger = logger; } @@ -91,6 +98,12 @@ private void VerifyRootFolder(RootFolder rootFolder) { throw new UnauthorizedAccessException(string.Format("Root folder path '{0}' is not writable by user '{1}'", rootFolder.Path, Environment.UserName)); } + + if (rootFolder.IsCalibreLibrary) + { + // This will throw on failure + _calibreProxy.GetLibraryInfo(rootFolder.CalibreSettings); + } } public RootFolder Add(RootFolder rootFolder)