aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2022-12-18 16:11:34 -0600
committerGitHub <noreply@github.com>2022-12-18 16:11:34 -0600
commitc9db752fc723ab5d9c65fbf076ce0e29bf6a89c1 (patch)
treef18f2fc774d1f6fd272edd920ba5202d9ec468c7
parent57c10999226805dab67243e74502e9fc6b2e92fa (diff)
parent0f1b69a9c82232067afdcea684a2f84deb304110 (diff)
downloadslskd-c9db752fc723ab5d9c65fbf076ce0e29bf6a89c1.tar.gz
Merge pull request #804 from slskd/regex
Default to case insensitivity for user-defined regular expressions, add flag to enable sensitivity
-rw-r--r--docs/config.md31
-rw-r--r--src/slskd/Application.cs12
-rw-r--r--src/slskd/Core/Options.cs9
-rw-r--r--src/slskd/Program.cs6
-rw-r--r--src/slskd/Shares/ShareScanner.cs12
5 files changed, 56 insertions, 14 deletions
diff --git a/docs/config.md b/docs/config.md
index 6a96588d..aed3a424 100644
--- a/docs/config.md
+++ b/docs/config.md
@@ -143,6 +143,8 @@ Aliases:
Share filters can be used to prevent certain types of files from being shared. This option is an array that can take any number of filters. Filters must be a valid regular expression; a few examples are included below and in the example configuration included with the application, but the list is empty by default.
+Filter expressions are case insensitive by default.
+
| Command Line | Environment Variable | Description |
| ------------------------- | ----------------------------- | --------------------------------------------------------------------- |
| `--share-filter` | `SLSKD_SHARE_FILTER` | A list of regular expressions used to filter files from shares |
@@ -683,6 +685,8 @@ A number of filters can be configured to control various aspects of how the appl
Share filters can be used to prevent certain types of files from being shared. This option is an array that can take any number of filters. Filters must be a valid regular expression; a few examples are included below and in the example configuration included with the application, but the list is empty by default.
+Filter expressions are case insensitive by default.
+
| Command Line | Environment Variable | Description |
| ------------------------- | ----------------------- | --------------------------------------------------------------------- |
| `--share-filter` | `SLSKD_SHARE_FILTER` | A list of regular expressions used to filter files from shares |
@@ -849,18 +853,19 @@ feature:
Several additional feature flags are provided to change the application's runtime behavior, which is helpful during development. Available feature flags are:
-| Flag | Environment Variable | Description |
-| -------------------- | -------------------------- | ---------------------------------------------------------------- |
-| `-d\|--debug` | `SLSKD_DEBUG` | Run the application in debug mode. Produces verbose log output. |
-| `--experimental` | `SLSKD_EXPERIMENTAL` | Run the application in experimental mode. YMMV. |
-| `-n\|--no-logo` | `SLSKD_NO_LOGO` | Don't show the application logo on startup |
-| `-x\|--no-start` | `SLSKD_NO_START` | Bootstrap the application, but don't start |
-| `--no-connect` | `SLSKD_NO_CONNECT` | Start the application, but don't connect to the server |
-| `--no-share-scan` | `SLSKD_NO_SHARE_SCAN` | Don't perform a scan of shared directories on startup |
-| `--force-share-scan` | `SLSKD_FORCE_SHARE_SCAN` | Force a scan of shared directories on startup |
-| `--no-version-check` | `SLSKD_NO_VERSION_CHECK` | Don't perform a version check on startup |
-| `--log-sql` | `SLSKD_LOG_SQL` | Log SQL queries generated by Entity Framework |
-| `--volatile` | `SLSKD_VOLATILE` | Use volatile data storage (all data will be lost at shutdown) |
+| Flag | Environment Variable | Description |
+| ------------------------ | ---------------------------- | ---------------------------------------------------------------- |
+| `-d\|--debug` | `SLSKD_DEBUG` | Run the application in debug mode. Produces verbose log output. |
+| `--experimental` | `SLSKD_EXPERIMENTAL` | Run the application in experimental mode. YMMV. |
+| `-n\|--no-logo` | `SLSKD_NO_LOGO` | Don't show the application logo on startup |
+| `-x\|--no-start` | `SLSKD_NO_START` | Bootstrap the application, but don't start |
+| `--no-connect` | `SLSKD_NO_CONNECT` | Start the application, but don't connect to the server |
+| `--no-share-scan` | `SLSKD_NO_SHARE_SCAN` | Don't perform a scan of shared directories on startup |
+| `--force-share-scan` | `SLSKD_FORCE_SHARE_SCAN` | Force a scan of shared directories on startup |
+| `--no-version-check` | `SLSKD_NO_VERSION_CHECK` | Don't perform a version check on startup |
+| `--log-sql` | `SLSKD_LOG_SQL` | Log SQL queries generated by Entity Framework |
+| `--volatile` | `SLSKD_VOLATILE` | Use volatile data storage (all data will be lost at shutdown) |
+| `--case-sensitive-regex` | `SLSKD_CASE_SENSITIVE_REGEX` | User-defined regular expressions are case sensitive |
#### **YAML**
```yaml
@@ -872,6 +877,8 @@ flags:
no_share_scan: false
no_version_check: false
log_sql: false
+ volatile: false
+ case_sensitive_regex: false
```
# Commands
diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs
index 71fb140d..44b7c627 100644
--- a/src/slskd/Application.cs
+++ b/src/slskd/Application.cs
@@ -118,7 +118,16 @@ namespace slskd
PreviousOptions = OptionsMonitor.CurrentValue;
- CompiledSearchResponseFilters = OptionsAtStartup.Filters.Search.Request.Select(f => new Regex(f, RegexOptions.Compiled));
+ Flags = Program.Flags;
+
+ var regexOptions = RegexOptions.Compiled;
+
+ if (!Flags.CaseSensitiveRegEx)
+ {
+ regexOptions |= RegexOptions.IgnoreCase;
+ }
+
+ CompiledSearchResponseFilters = OptionsAtStartup.Filters.Search.Request.Select(f => new Regex(f, regexOptions));
State = state;
State.OnChange(state => State_OnChange(state));
@@ -203,6 +212,7 @@ namespace slskd
private IMemoryCache Cache { get; set; } = new MemoryCache(new MemoryCacheOptions());
private IEnumerable<Regex> CompiledSearchResponseFilters { get; set; }
private IEnumerable<Guid> ActiveDownloadIdsAtPreviousShutdown { get; set; } = Enumerable.Empty<Guid>();
+ private Options.FlagsOptions Flags { get; set; }
public void CollectGarbage()
{
diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs
index 814b9b90..e23fd640 100644
--- a/src/slskd/Core/Options.cs
+++ b/src/slskd/Core/Options.cs
@@ -381,6 +381,15 @@ namespace slskd
[Description("use volatile data storage (all data will be lost at shutdown)")]
[RequiresRestart]
public bool Volatile { get; init; } = false;
+
+ /// <summary>
+ /// Gets a value indicating whether user-defined regular expressions are case sensitive.
+ /// </summary>
+ [Argument(default, "case-sensitive-regex")]
+ [EnvironmentVariable("CASE_SENSITIVE_REGEX")]
+ [Description("user-defined regular expressions are case sensitive")]
+ [RequiresRestart]
+ public bool CaseSensitiveRegEx { get; init; } = false;
}
/// <summary>
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs
index 0b82e825..04d3b7e4 100644
--- a/src/slskd/Program.cs
+++ b/src/slskd/Program.cs
@@ -158,6 +158,11 @@ namespace slskd
public static bool IsRelayAgent { get; private set; }
/// <summary>
+ /// Gets the application flags.
+ /// </summary>
+ public static Options.FlagsOptions Flags { get; private set; }
+
+ /// <summary>
/// Gets the path where application data is saved.
/// </summary>
[Argument('a', "app-dir", "path where application data is saved")]
@@ -364,6 +369,7 @@ namespace slskd
}
IsRelayAgent = OptionsAtStartup.Relay.Enabled && OptionsAtStartup.Relay.Mode.ToEnum<RelayMode>() == RelayMode.Agent;
+ Flags = OptionsAtStartup.Flags;
ConfigureGlobalLogger();
Log = Serilog.Log.ForContext(typeof(Program));
diff --git a/src/slskd/Shares/ShareScanner.cs b/src/slskd/Shares/ShareScanner.cs
index f5bbcd41..30a67ee6 100644
--- a/src/slskd/Shares/ShareScanner.cs
+++ b/src/slskd/Shares/ShareScanner.cs
@@ -72,6 +72,8 @@ namespace slskd.Shares
{
WorkerCount = workerCount;
SoulseekFileFactory = soulseekFileFactory ?? new SoulseekFileFactory();
+
+ Flags = Program.Flags;
}
/// <summary>
@@ -86,6 +88,7 @@ namespace slskd.Shares
private IManagedState<SharedFileCacheState> State { get; } = new ManagedState<SharedFileCacheState>();
private SemaphoreSlim SyncRoot { get; } = new SemaphoreSlim(1);
private CancellationTokenSource CancellationTokenSource { get; set; }
+ private Options.FlagsOptions Flags { get; set; }
/// <summary>
/// Scans the configured shares and fills the cache.
@@ -132,8 +135,15 @@ namespace slskd.Shares
Log.Information("Shared file cache re-created and ready for scan.");
}
+ var regexOptions = RegexOptions.Compiled;
+
+ if (!Flags.CaseSensitiveRegEx)
+ {
+ regexOptions |= RegexOptions.IgnoreCase;
+ }
+
var filters = options.Filters
- .Select(filter => new Regex(filter, RegexOptions.Compiled))
+ .Select(filter => new Regex(filter, regexOptions))
.ToList();
Log.Information("Starting shared file scan");