From 2d7aa20448ddd161d772600c5f39b88d2591bdbb Mon Sep 17 00:00:00 2001 From: ta264 Date: Wed, 31 Mar 2021 21:20:32 +0100 Subject: [PATCH] New: Auto rescan on remote path mapping change for Calibre --- .../RootFolders/RootFolderService.cs | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/NzbDrone.Core/RootFolders/RootFolderService.cs b/src/NzbDrone.Core/RootFolders/RootFolderService.cs index cb85af184..b215dc159 100644 --- a/src/NzbDrone.Core/RootFolders/RootFolderService.cs +++ b/src/NzbDrone.Core/RootFolders/RootFolderService.cs @@ -7,9 +7,12 @@ using NzbDrone.Common; using NzbDrone.Common.Disk; using NzbDrone.Common.Extensions; +using NzbDrone.Core.Datastore.Events; using NzbDrone.Core.MediaFiles; using NzbDrone.Core.MediaFiles.Commands; using NzbDrone.Core.Messaging.Commands; +using NzbDrone.Core.Messaging.Events; +using NzbDrone.Core.RemotePathMappings; namespace NzbDrone.Core.RootFolders { @@ -26,7 +29,7 @@ public interface IRootFolderService string GetBestRootFolderPath(string path); } - public class RootFolderService : IRootFolderService + public class RootFolderService : IRootFolderService, IHandle> { private readonly IRootFolderRepository _rootFolderRepository; private readonly IDiskProvider _diskProvider; @@ -171,5 +174,20 @@ private void GetDetails(RootFolder rootFolder) } }).Wait(5000); } + + public void Handle(ModelEvent message) + { + var commands = All() + .Where(x => x.IsCalibreLibrary && + x.CalibreSettings.Host == message.Model.Host && + x.Path.StartsWith(message.Model.LocalPath)) + .Select(x => new RescanFoldersCommand(new List { x.Path }, FilterFilesType.None, true, null)) + .ToList(); + + if (commands.Any()) + { + _commandQueueManager.PushMany(commands); + } + } } }