aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Common/Validation/AbsolutePathAttribute.cs
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-06-06 11:15:20 -0500
committerGitHub <noreply@github.com>2026-06-06 11:15:20 -0500
commitec836b73cf40226d7a754b42762f4dab44b97749 (patch)
tree06030fad73ed32f4701f88a2dc492f83e7fc8a81 /src/slskd/Common/Validation/AbsolutePathAttribute.cs
parent2e3fd1d2f66a9f5ec2b1ec80d6c19348529cab63 (diff)
parentd35ac4573e2ac5817af3a2b9a6025d41959b9caf (diff)
downloadslskd-ec836b73cf40226d7a754b42762f4dab44b97749.tar.gz
Merge pull request #1746 from slskd/destination
Add options providing granular control over download location
Diffstat (limited to 'src/slskd/Common/Validation/AbsolutePathAttribute.cs')
-rw-r--r--src/slskd/Common/Validation/AbsolutePathAttribute.cs28
1 files changed, 20 insertions, 8 deletions
diff --git a/src/slskd/Common/Validation/AbsolutePathAttribute.cs b/src/slskd/Common/Validation/AbsolutePathAttribute.cs
index eb1c9069..217a4eea 100644
--- a/src/slskd/Common/Validation/AbsolutePathAttribute.cs
+++ b/src/slskd/Common/Validation/AbsolutePathAttribute.cs
@@ -33,23 +33,24 @@
namespace slskd.Validation
{
using System.ComponentModel.DataAnnotations;
- using System.Runtime.InteropServices;
/// <summary>
/// Validates that the specified path is absolute.
/// </summary>
public class AbsolutePathAttribute : ValidationAttribute
{
- public AbsolutePathAttribute()
+ public AbsolutePathAttribute(OperatingSystem os = OperatingSystem.Current)
{
- }
+ if (os != OperatingSystem.Current && os != OperatingSystem.Any && os != OperatingSystem.All)
+ {
+ throw new System.ArgumentException("OperatingSystem argument for AbsolutePathAttribute must be one of: Current, Any, All", nameof(os));
+ }
- public AbsolutePathAttribute(OSPlatform? os = null)
- {
OS = os;
}
- public OSPlatform? OS { get; }
+ public OperatingSystem OS { get; }
+ private OperatingSystem? Injected { get; }
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
@@ -57,9 +58,20 @@ namespace slskd.Validation
{
var path = value.ToString();
- if (!FileSafety.IsPathAbsolute(path, os: OS))
+ if (OS == OperatingSystem.Current)
+ {
+ if (!FileSafety.IsPathAbsolute(path, os: Injected ?? Compute.OperatingSystem()))
+ {
+ return new ValidationResult($"The {validationContext.DisplayName} field must be an absolute path on the current operating system.");
+ }
+
+ return ValidationResult.Success;
+ }
+
+ // OS == OperatingSystem.All or .Any
+ if (!FileSafety.IsPathAbsolute(path, os: OperatingSystem.Linux) || !FileSafety.IsPathAbsolute(path, os: OperatingSystem.Windows))
{
- return new ValidationResult($"The {validationContext.DisplayName} field must be an absolute file path.");
+ return new ValidationResult($"The {validationContext.DisplayName} field must be an absolute path on all operating systems.");
}
}