aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Shares/SharedFileCache.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/SharedFileCache.cs
parentccd0e524b7c2d60362ea272140080e5cc52ab08a (diff)
downloadslskd-1da4e1f198aff7f5ad7f61381d481acc8dc7119c.tar.gz
pass filters to cache
Diffstat (limited to 'src/slskd/Shares/SharedFileCache.cs')
-rw-r--r--src/slskd/Shares/SharedFileCache.cs19
1 files changed, 8 insertions, 11 deletions
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
/// </summary>
/// <remarks>Initiates the scan, then yields execution back to the caller; does not wait for the operation to complete.</remarks>
/// <param name="shares">The list of shares from which to fill the cache.</param>
+ /// <param name="filters">The list of regular expressions used to exclude files or paths from scanning.</param>
/// <returns>The operation context.</returns>
- Task FillAsync(IEnumerable<Share> shares);
+ Task FillAsync(IEnumerable<Share> shares, IEnumerable<Regex> filters);
/// <summary>
/// Returns the contents of the specified <paramref name="directory"/>.
@@ -87,13 +88,9 @@ namespace slskd.Shares
/// <summary>
/// Initializes a new instance of the <see cref="SharedFileCache"/> class.
/// </summary>
- /// <param name="optionsMonitor"></param>
/// <param name="soulseekFileFactory"></param>
- public SharedFileCache(
- IOptionsMonitor<Options> 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<SharedFileCache>();
private HashSet<string> MaskedDirectories { get; set; }
private Dictionary<string, File> MaskedFiles { get; set; }
- private IOptionsMonitor<Options> OptionsMonitor { get; set; }
private List<Share> Shares { get; set; }
private ISoulseekFileFactory SoulseekFileFactory { get; }
private SqliteConnection SQLite { get; set; }
@@ -118,6 +114,7 @@ namespace slskd.Shares
/// <returns>The contents of the cache.</returns>
public IEnumerable<Directory> 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.
/// </summary>
/// <param name="shares">The list of shares from which to fill the cache.</param>
+ /// <param name="filters">The list of regular expressions used to exclude files or paths from scanning.</param>
/// <returns>The operation context.</returns>
- public async Task FillAsync(IEnumerable<Share> shares)
+ public async Task FillAsync(IEnumerable<Share> shares, IEnumerable<Regex> 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<string, File>();
var maskedDirectories = new HashSet<string>();
var current = 0;