From 1da4e1f198aff7f5ad7f61381d481acc8dc7119c Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Wed, 1 Jun 2022 10:56:34 -0500 Subject: pass filters to cache --- src/slskd/Shares/SharedFileCache.cs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'src/slskd/Shares/SharedFileCache.cs') diff --git a/src/slskd/Shares/SharedFileCache.cs b/src/slskd/Shares/SharedFileCache.cs index b06f7be6..cb1ccdee 100644 --- a/src/slskd/Shares/SharedFileCache.cs +++ b/src/slskd/Shares/SharedFileCache.cs @@ -53,8 +53,9 @@ namespace slskd.Shares /// /// Initiates the scan, then yields execution back to the caller; does not wait for the operation to complete. /// The list of shares from which to fill the cache. + /// The list of regular expressions used to exclude files or paths from scanning. /// The operation context. - Task FillAsync(IEnumerable shares); + Task FillAsync(IEnumerable shares, IEnumerable filters); /// /// Returns the contents of the specified . @@ -87,13 +88,9 @@ namespace slskd.Shares /// /// Initializes a new instance of the class. /// - /// /// - public SharedFileCache( - IOptionsMonitor optionsMonitor, - ISoulseekFileFactory soulseekFileFactory = null) + public SharedFileCache(ISoulseekFileFactory soulseekFileFactory = null) { - OptionsMonitor = optionsMonitor; SoulseekFileFactory = soulseekFileFactory ?? new SoulseekFileFactory(); } @@ -105,7 +102,6 @@ namespace slskd.Shares private ILogger Log { get; } = Serilog.Log.ForContext(); private HashSet MaskedDirectories { get; set; } private Dictionary MaskedFiles { get; set; } - private IOptionsMonitor OptionsMonitor { get; set; } private List Shares { get; set; } private ISoulseekFileFactory SoulseekFileFactory { get; } private SqliteConnection SQLite { get; set; } @@ -118,6 +114,7 @@ namespace slskd.Shares /// The contents of the cache. public IEnumerable Browse() { + Console.WriteLine(State.ToJson()); if (!State.CurrentValue.Filled) { if (State.CurrentValue.Filling) @@ -167,9 +164,12 @@ namespace slskd.Shares /// Scans the configured shares and fills the cache. /// /// The list of shares from which to fill the cache. + /// The list of regular expressions used to exclude files or paths from scanning. /// The operation context. - public async Task FillAsync(IEnumerable shares) + public async Task FillAsync(IEnumerable shares, IEnumerable filters) { + Console.WriteLine($"Filling: {shares.ToJson()}"); + // obtain the semaphore, or fail if it can't be obtained immediately, indicating that a scan is running. if (!await SyncRoot.WaitAsync(millisecondsTimeout: 0)) { @@ -234,9 +234,6 @@ namespace slskd.Shares Log.Debug("Found {Directories} shared directories (and {Excluded} were excluded) in {Elapsed}ms. Starting file scan.", unmaskedDirectories.Count, excludedDirectories.Count(), sw.ElapsedMilliseconds - swSnapshot); swSnapshot = sw.ElapsedMilliseconds; - var filters = OptionsMonitor.CurrentValue.Filters.Share - .Select(filter => new Regex(filter, RegexOptions.Compiled)); - var files = new Dictionary(); var maskedDirectories = new HashSet(); var current = 0; -- cgit v1.2.3