New: Auto rescan on remote path mapping change for Calibre

pull/965/head
ta264 4 years ago
parent 9be948b7cc
commit 2d7aa20448

@ -7,9 +7,12 @@ using NLog;
using NzbDrone.Common; using NzbDrone.Common;
using NzbDrone.Common.Disk; using NzbDrone.Common.Disk;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
using NzbDrone.Core.Datastore.Events;
using NzbDrone.Core.MediaFiles; using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.MediaFiles.Commands; using NzbDrone.Core.MediaFiles.Commands;
using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.RemotePathMappings;
namespace NzbDrone.Core.RootFolders namespace NzbDrone.Core.RootFolders
{ {
@ -26,7 +29,7 @@ namespace NzbDrone.Core.RootFolders
string GetBestRootFolderPath(string path); string GetBestRootFolderPath(string path);
} }
public class RootFolderService : IRootFolderService public class RootFolderService : IRootFolderService, IHandle<ModelEvent<RemotePathMapping>>
{ {
private readonly IRootFolderRepository _rootFolderRepository; private readonly IRootFolderRepository _rootFolderRepository;
private readonly IDiskProvider _diskProvider; private readonly IDiskProvider _diskProvider;
@ -171,5 +174,20 @@ namespace NzbDrone.Core.RootFolders
} }
}).Wait(5000); }).Wait(5000);
} }
public void Handle(ModelEvent<RemotePathMapping> 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<string> { x.Path }, FilterFilesType.None, true, null))
.ToList();
if (commands.Any())
{
_commandQueueManager.PushMany(commands);
}
}
} }
} }

Loading…
Cancel
Save