aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Shares/ShareService.cs
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2022-06-01 10:56:34 -0500
committerJP Dillingham <jp@dillingham.me>2022-06-01 10:56:34 -0500
commit1da4e1f198aff7f5ad7f61381d481acc8dc7119c (patch)
tree8d1439876f0348d62b455bf2a54c4bf958ea446f /src/slskd/Shares/ShareService.cs
parentccd0e524b7c2d60362ea272140080e5cc52ab08a (diff)
downloadslskd-1da4e1f198aff7f5ad7f61381d481acc8dc7119c.tar.gz
pass filters to cache
Diffstat (limited to 'src/slskd/Shares/ShareService.cs')
-rw-r--r--src/slskd/Shares/ShareService.cs22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/slskd/Shares/ShareService.cs b/src/slskd/Shares/ShareService.cs
index 7c08ad13..9cae0d42 100644
--- a/src/slskd/Shares/ShareService.cs
+++ b/src/slskd/Shares/ShareService.cs
@@ -21,6 +21,7 @@ namespace slskd.Shares
{
using System.Collections.Generic;
using System.Linq;
+ using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Soulseek;
@@ -39,10 +40,7 @@ namespace slskd.Shares
IOptionsMonitor<Options> optionsMonitor,
ISharedFileCache sharedFileCache = null)
{
- OptionsMonitor = optionsMonitor;
- OptionsMonitor.OnChange(Configure);
-
- Cache = sharedFileCache ?? new SharedFileCache(OptionsMonitor);
+ Cache = sharedFileCache ?? new SharedFileCache();
Cache.StateMonitor.OnChange(cacheState =>
{
var (previous, current) = cacheState;
@@ -58,6 +56,11 @@ namespace slskd.Shares
Files = current.Files,
});
});
+
+ OptionsMonitor = optionsMonitor;
+ OptionsMonitor.OnChange(options => Configure(options));
+
+ Configure(OptionsMonitor.CurrentValue);
}
/// <summary>
@@ -65,6 +68,8 @@ namespace slskd.Shares
/// </summary>
public IReadOnlyList<Share> Shares => SharesList.AsReadOnly();
+ public IReadOnlyList<Regex> FilterRegexes => FilterRegexList.AsReadOnly();
+
/// <summary>
/// Gets the state monitor for the service.
/// </summary>
@@ -76,6 +81,7 @@ namespace slskd.Shares
private List<Share> SharesList { get; set; } = new List<Share>();
private IManagedState<ShareState> State { get; } = new ManagedState<ShareState>();
private SemaphoreSlim SyncRoot { get; } = new SemaphoreSlim(1, 1);
+ private List<Regex> FilterRegexList { get; set; } = new List<Regex>();
/// <summary>
/// Returns the entire contents of the share.
@@ -127,7 +133,7 @@ namespace slskd.Shares
/// <returns>The operation context.</returns>
/// <exception cref="ShareScanInProgressException">Thrown when a scan is already in progress.</exception>
public Task StartScanAsync()
- => Cache.FillAsync(Shares);
+ => Cache.FillAsync(Shares, FilterRegexes);
private void Configure(Options options)
{
@@ -149,7 +155,13 @@ namespace slskd.Shares
.OrderByDescending(share => share.LocalPath.Length) // process subdirectories first. this allows them to be aliased separately from their parent
.ToList();
+ var regexes = options.Filters.Share
+ .Select(filter => new Regex(filter, RegexOptions.Compiled))
+ .ToList();
+
SharesList = shares;
+ FilterRegexList = regexes;
+
State.SetValue(state => state with { ScanPending = true });
LastOptionsHash = optionsHash;