From c7aa1bae5e06cd834e096141c70a86f8bebca0ca Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Thu, 30 Jan 2025 18:50:48 -0800 Subject: [PATCH] Fixed: Ignore special folders inside Blackhole watch folders (cherry picked from commit e79dd6f8e689617b1fd9f96c639ac300669112c5) --- .../Disk/FileSystemLookupService.cs | 33 +------------ src/NzbDrone.Common/Disk/SpecialFolders.cs | 47 +++++++++++++++++++ .../Blackhole/ScanWatchFolderFixture.cs | 17 +++++++ .../Clients/Blackhole/ScanWatchFolder.cs | 8 +++- 4 files changed, 72 insertions(+), 33 deletions(-) create mode 100644 src/NzbDrone.Common/Disk/SpecialFolders.cs diff --git a/src/NzbDrone.Common/Disk/FileSystemLookupService.cs b/src/NzbDrone.Common/Disk/FileSystemLookupService.cs index 8b9d1bae0..efd2fcbdb 100644 --- a/src/NzbDrone.Common/Disk/FileSystemLookupService.cs +++ b/src/NzbDrone.Common/Disk/FileSystemLookupService.cs @@ -17,37 +17,6 @@ namespace NzbDrone.Common.Disk private readonly IDiskProvider _diskProvider; private readonly IRuntimeInfo _runtimeInfo; - private readonly HashSet _setToRemove = new HashSet - { - // Windows - "boot", - "bootmgr", - "cache", - "msocache", - "recovery", - "$recycle.bin", - "recycler", - "system volume information", - "temporary internet files", - "windows", - - // OS X - ".fseventd", - ".spotlight", - ".trashes", - ".vol", - "cachedmessages", - "caches", - "trash", - - // QNAP - ".@__thumb", - - // Synology - "@eadir", - "#recycle" - }; - public FileSystemLookupService(IDiskProvider diskProvider, IRuntimeInfo runtimeInfo) { _diskProvider = diskProvider; @@ -158,7 +127,7 @@ namespace NzbDrone.Common.Disk }) .ToList(); - directories.RemoveAll(d => _setToRemove.Contains(d.Name.ToLowerInvariant())); + directories.RemoveAll(d => SpecialFolders.IsSpecialFolder(d.Name)); return directories; } diff --git a/src/NzbDrone.Common/Disk/SpecialFolders.cs b/src/NzbDrone.Common/Disk/SpecialFolders.cs new file mode 100644 index 000000000..b1339a7ed --- /dev/null +++ b/src/NzbDrone.Common/Disk/SpecialFolders.cs @@ -0,0 +1,47 @@ +using System.Collections.Generic; + +namespace NzbDrone.Common.Disk; + +public static class SpecialFolders +{ + private static readonly HashSet _specialFolders = new HashSet + { + // Windows + "boot", + "bootmgr", + "cache", + "msocache", + "recovery", + "$recycle.bin", + "recycler", + "system volume information", + "temporary internet files", + "windows", + + // OS X + ".fseventd", + ".spotlight", + ".trashes", + ".vol", + "cachedmessages", + "caches", + "trash", + + // QNAP + ".@__thumb", + + // Synology + "@eadir", + "#recycle" + }; + + public static bool IsSpecialFolder(string folder) + { + if (folder == null) + { + return false; + } + + return _specialFolders.Contains(folder.ToLowerInvariant()); + } +} diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/ScanWatchFolderFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/ScanWatchFolderFixture.cs index de9cb8593..968c04023 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/ScanWatchFolderFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/ScanWatchFolderFixture.cs @@ -95,5 +95,22 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole VerifySingleItem(DownloadItemStatus.Completed); } + + [TestCase("@eaDir")] + [TestCase(".@__thumb")] + public void GetItems_should_not_include_special_subfolders(string folderName) + { + GivenCompletedItem(); + + var targetDir = Path.Combine(_completedDownloadFolder, folderName); + + Mocker.GetMock() + .Setup(c => c.GetDirectories(_completedDownloadFolder)) + .Returns(new[] { targetDir }); + + var items = Subject.GetItems(_completedDownloadFolder, TimeSpan.FromMilliseconds(50)).ToList(); + + items.Count.Should().Be(0); + } } } diff --git a/src/NzbDrone.Core/Download/Clients/Blackhole/ScanWatchFolder.cs b/src/NzbDrone.Core/Download/Clients/Blackhole/ScanWatchFolder.cs index ef5bb0a0d..6aa21ab38 100644 --- a/src/NzbDrone.Core/Download/Clients/Blackhole/ScanWatchFolder.cs +++ b/src/NzbDrone.Core/Download/Clients/Blackhole/ScanWatchFolder.cs @@ -52,7 +52,13 @@ namespace NzbDrone.Core.Download.Clients.Blackhole { foreach (var folder in _diskScanService.FilterPaths(watchFolder, _diskProvider.GetDirectories(watchFolder))) { - var title = FileNameBuilder.CleanFileName(Path.GetFileName(folder)); + var folderName = Path.GetFileName(folder); + var title = FileNameBuilder.CleanFileName(folderName); + + if (SpecialFolders.IsSpecialFolder(folderName)) + { + continue; + } var newWatchItem = new WatchFolderItem {