aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-06-07 12:21:42 -0500
committerGitHub <noreply@github.com>2026-06-07 12:21:42 -0500
commit77af3c020a880b2a820ca11afe27184c5df9e455 (patch)
tree23e9cfaa410f1eee7c1b20d0a876ab90478d59f6 /src
parentdb7f9a0f1e91bb02ce61bb68b89b557421a46d12 (diff)
parent611395e5686c2ec3ca11def92dc09230b2e97cc4 (diff)
downloadslskd-77af3c020a880b2a820ca11afe27184c5df9e455.tar.gz
Merge pull request #1756 from slskd/perms
Move 'permissions' options under 'destination', improve application of directory mode
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Core/Options.cs49
-rw-r--r--src/slskd/Files/FileService.cs12
-rw-r--r--src/slskd/Transfers/Downloads/DownloadService.cs4
3 files changed, 54 insertions, 11 deletions
diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs
index 29d37806..f35a56df 100644
--- a/src/slskd/Core/Options.cs
+++ b/src/slskd/Core/Options.cs
@@ -235,11 +235,8 @@ namespace slskd
[Validate]
public RelayOptions Relay { get; init; } = new RelayOptions();
- /// <summary>
- /// Gets permission options.
- /// </summary>
- [Validate]
- public PermissionsOptions Permissions { get; init; } = new PermissionsOptions();
+ [Obsolete("temporary sentinel to warn users about breaking change. use Transfers.Download.Destination.Permissions instead.")]
+ public object Permissions { get; init; } = null;
/// <summary>
/// Gets directory options.
@@ -364,6 +361,11 @@ namespace slskd
{
results.Add(new ValidationResult("The 'integration' key has been renamed to 'integrations'. Add an 's' to the end of the key to remove this error (no other changes were made)"));
}
+
+ if (Permissions is not null)
+ {
+ results.Add(new ValidationResult("The 'permissions' keys have been moved under a new 'destination' key under transfers -> download, and the behavior has changed. See https://github.com/slskd/slskd/pull/1756 for details"));
+ }
#pragma warning restore CS0618 // Type or member is obsolete
return results;
@@ -1082,6 +1084,43 @@ namespace slskd
/// </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
+ {
+ /// <summary>
+ /// Gets the permissions to apply to newly created files.
+ /// </summary>
+ /// <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>();
+
+ if (!string.IsNullOrEmpty(Mode))
+ {
+ var regEx = new Regex("^[0-7]{3,4}$", RegexOptions.Compiled);
+
+ if (!regEx.IsMatch(Mode))
+ {
+ results.Add(new ValidationResult($"Field {nameof(Mode)} is invalid. Specify a three- or four-character string consisting of only 0-7 (chmod syntax, [0]000-[7]777, inclusive)"));
+ }
+ }
+
+ return results;
+ }
+ }
}
}
diff --git a/src/slskd/Files/FileService.cs b/src/slskd/Files/FileService.cs
index 3b304d99..62d17f20 100644
--- a/src/slskd/Files/FileService.cs
+++ b/src/slskd/Files/FileService.cs
@@ -389,13 +389,15 @@ namespace slskd.Files
var path = Path.GetDirectoryName(filename);
- UnixFileMode? unixCreateMode = options?.UnixCreateMode ?? OptionsMonitor.CurrentValue.Permissions.File.Mode?.ToUnixFileMode();
+ UnixFileMode? unixCreateMode = options?.UnixCreateMode ?? OptionsMonitor.CurrentValue.Transfers.Download.Destination.Permissions.Mode?.ToUnixFileMode();
if (!Directory.Exists(path))
{
if (!OperatingSystem.IsWindows() && unixCreateMode.HasValue)
{
- Directory.CreateDirectory(path, unixCreateMode.Value.WithExecuteFlagsForEachReadFlag());
+ var mode = unixCreateMode.Value.WithExecuteFlagsForEachReadFlag();
+ Directory.CreateDirectory(path, unixCreateMode: mode);
+ File.SetUnixFileMode(path, mode: mode);
}
else
{
@@ -469,13 +471,15 @@ namespace slskd.Files
throw new FileNotFoundException($"The specified source file does not exist", fileName: sourceFilename);
}
- UnixFileMode? unixCreateMode = unixFileMode ?? OptionsMonitor.CurrentValue.Permissions.File.Mode?.ToUnixFileMode();
+ UnixFileMode? unixCreateMode = unixFileMode ?? OptionsMonitor.CurrentValue.Transfers.Download.Destination.Permissions.Mode?.ToUnixFileMode();
if (!Directory.Exists(destinationDirectory))
{
if (!OperatingSystem.IsWindows() && unixCreateMode.HasValue)
{
- Directory.CreateDirectory(destinationDirectory, unixCreateMode.Value.WithExecuteFlagsForEachReadFlag());
+ var mode = unixCreateMode.Value.WithExecuteFlagsForEachReadFlag();
+ Directory.CreateDirectory(destinationDirectory, unixCreateMode: mode);
+ File.SetUnixFileMode(destinationDirectory, mode: mode);
}
else
{
diff --git a/src/slskd/Transfers/Downloads/DownloadService.cs b/src/slskd/Transfers/Downloads/DownloadService.cs
index c6892fc4..7c794e55 100644
--- a/src/slskd/Transfers/Downloads/DownloadService.cs
+++ b/src/slskd/Transfers/Downloads/DownloadService.cs
@@ -1218,8 +1218,8 @@ namespace slskd.Transfers.Downloads
}),
disposeOutputStreamOnCompletion: true);
- UnixFileMode? unixFileMode = !string.IsNullOrEmpty(OptionsMonitor.CurrentValue.Permissions.File.Mode)
- ? OptionsMonitor.CurrentValue.Permissions.File.Mode.ToUnixFileMode()
+ UnixFileMode? unixFileMode = !string.IsNullOrEmpty(OptionsMonitor.CurrentValue.Transfers.Download.Destination.Permissions.Mode)
+ ? OptionsMonitor.CurrentValue.Transfers.Download.Destination.Permissions.Mode.ToUnixFileMode()
: null;
/*