| | | 1 | | using Anichron.Worker.Settings; |
| | | 2 | | using Microsoft.Extensions.Options; |
| | | 3 | | |
| | | 4 | | namespace Anichron.Worker.Crawling; |
| | | 5 | | |
| | 76 | 6 | | internal sealed class CrawlExclusions(IOptions<WorkerSettings> options) |
| | | 7 | | { |
| | 76 | 8 | | private readonly HashSet<string> directoryNames = new( |
| | 76 | 9 | | [ |
| | 76 | 10 | | .. BuiltInDirectoryNames(), |
| | 76 | 11 | | .. options.Value.ExcludedDirectoryNames(), |
| | 76 | 12 | | ], |
| | 76 | 13 | | StringComparer.OrdinalIgnoreCase); |
| | | 14 | | |
| | 76 | 15 | | private readonly string[] appLibrarySuffixes = AppLibrarySuffixes(); |
| | | 16 | | |
| | | 17 | | public bool IsExcludedDirectory(string name) |
| | 65 | 18 | | => name.StartsWith('.') |
| | 65 | 19 | | || directoryNames.Contains(name) |
| | 65 | 20 | | || appLibrarySuffixes.Any(suffix => name.EndsWith(suffix, StringComparison.OrdinalIgnoreCase)); |
| | | 21 | | |
| | | 22 | | public static bool IsExcludedFile(string name) |
| | 92 | 23 | | => name.StartsWith('.'); |
| | | 24 | | |
| | | 25 | | private static string[] BuiltInDirectoryNames() |
| | 76 | 26 | | { |
| | 76 | 27 | | return |
| | 76 | 28 | | [ |
| | 76 | 29 | | "@eaDir", "#recycle", "#snapshot", "@tmp", |
| | 76 | 30 | | "@Recycle", "@Recently-Snapshot", |
| | 76 | 31 | | "$RECYCLE.BIN", "System Volume Information", "RECYCLER", |
| | 76 | 32 | | "lost+found", |
| | 76 | 33 | | "files_trashbin", "files_versions", |
| | 76 | 34 | | ]; |
| | 76 | 35 | | } |
| | | 36 | | |
| | | 37 | | private static string[] AppLibrarySuffixes() |
| | 76 | 38 | | { |
| | 76 | 39 | | return [".photoslibrary", ".photolibrary", ".lrdata", ".fcpbundle", ".imovielibrary"]; |
| | 76 | 40 | | } |
| | | 41 | | } |