aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Core/Options.cs
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-05-31 21:17:39 -0500
committerJP Dillingham <jp@dillingham.me>2026-05-31 21:17:39 -0500
commita19fcd796c3acd497388daa0e38f5fa37bf511ee (patch)
tree9cff5b7e687da2bf5819164887edf7ae39adc4bb /src/slskd/Core/Options.cs
parent845da6c1c95ed18ec88c93a48f0a04c539f28bc3 (diff)
parent9c8a0cdbb1bf86c1d313919b37446b22a353c7c3 (diff)
downloadslskd-a19fcd796c3acd497388daa0e38f5fa37bf511ee.tar.gz
Merge branch 'destination' of github.com:slskd/slskd into destination
Diffstat (limited to 'src/slskd/Core/Options.cs')
-rw-r--r--src/slskd/Core/Options.cs35
1 files changed, 24 insertions, 11 deletions
diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs
index 298ea2c0..4e7dca7b 100644
--- a/src/slskd/Core/Options.cs
+++ b/src/slskd/Core/Options.cs
@@ -832,22 +832,22 @@ namespace slskd
var directories = Directories ?? Enumerable.Empty<string>();
- bool IsBlankPath(string share) => Regex.IsMatch(share.LocalizePath(), @"^(!|-){0,1}(\[.*\])$");
+ bool IsBlankPath(string share) => Regex.IsMatch(FileSafety.LocalizePath(share), @"^(!|-){0,1}(\[.*\])$");
directories?.Where(share => IsBlankPath(share)).ToList()
.ForEach(blank => results.Add(new ValidationResult($"Share {blank} does not specify a path")));
- bool IsRootMount(string share) => Regex.IsMatch(share.LocalizePath(), @"^(!|-){0,1}(\[.*\])/$");
+ bool IsRootMount(string share) => Regex.IsMatch(FileSafety.LocalizePath(share), @"^(!|-){0,1}(\[.*\])/$");
directories?.Where(share => IsRootMount(share)).ToList()
.ForEach(blank => results.Add(new ValidationResult($"Share {blank} specifies a root mount, which is not supported.")));
// starts with '/', 'X:', or '\\'
- bool IsAbsolutePath(string share) => Regex.IsMatch(share.LocalizePath(), @"^(!|-){0,1}(\[.*\])?(\/|[a-zA-Z]:|\\\\).*$");
+ bool IsAbsolutePath(string share) => Regex.IsMatch(FileSafety.LocalizePath(share), @"^(!|-){0,1}(\[.*\])?(\/|[a-zA-Z]:|\\\\).*$");
directories?.Where(share => !IsAbsolutePath(share)).ToList()
.ForEach(relativePath => results.Add(new ValidationResult($"Share {relativePath} contains a relative path; only absolute paths are supported.")));
// contains /./ or /../ or \.\ or \..\ or ..\ or ../ or \.. or /..
// which is resolved by some OS and will cause weird, unintended side effects
- bool ContainsTraversalSegments(string share) => Regex.IsMatch(share.LocalizePath(), @"^\.+[\/\\]?|[\/\\]\.+[\/\\]|[\/\\]\.+$");
+ bool ContainsTraversalSegments(string share) => Regex.IsMatch(FileSafety.LocalizePath(share), @"^\.+[\/\\]?|[\/\\]\.+[\/\\]|[\/\\]\.+$");
directories?.Where(share => ContainsTraversalSegments(share)).ToList()
.ForEach(badPath => results.Add(new ValidationResult($"Share {badPath} contains an unsafe path traversal segment.")));
@@ -1069,26 +1069,39 @@ namespace slskd
/// </summary>
public class DestinationOptions
{
+ /// <summary>
+ /// Gets the destination subdirectory for the files in the batch.
+ /// </summary>
[RelativePath]
[NonTraversingPath]
[String(AllowNull = true, AllowEmpty = false, AllowWhiteSpace = false, MinimumLength = 1)]
public string Subdirectory { get; init; } = "{SOURCE_DIRECTORY}";
- [Enum(typeof(DestinationConflictStrategy))]
- public string Conflict { get; init; } = DestinationConflictStrategy.Rename.ToString().ToLowerInvariant();
+ /// <summary>
+ /// Gets the strategy for handling existing files on disk.
+ /// </summary>
+ [Enum(typeof(DestinationExistsStrategy))]
+ public string Exists { get; init; } = DestinationExistsStrategy.Rename.ToString().ToLowerInvariant();
+ /// <summary>
+ /// Gets the permissions to apply to downloaded files and directories.
+ /// </summary>
[Validate]
public DestinationPermissionsOptions Permissions { get; init; } = new DestinationPermissionsOptions();
+ /// <summary>
+ /// Download destination permission options.
+ /// </summary>
public class DestinationPermissionsOptions : IValidatableObject
{
- public string Mode { get; init; }
-
/// <summary>
- /// Extended validation.
+ /// Gets the permissions to apply to newly created files.
/// </summary>
- /// <param name="validationContext"></param>
- /// <returns></returns>
+ /// <remarks>
+ /// Applicable to non-Windows operating systems, only.
+ /// </remarks>
+ public string Mode { get; init; }
+
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
var results = new List<ValidationResult>();