aboutsummaryrefslogtreecommitdiffstats
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
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
-rw-r--r--config/slskd.example.yml2
-rw-r--r--docs/config.md31
-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
5 files changed, 76 insertions, 22 deletions
diff --git a/config/slskd.example.yml b/config/slskd.example.yml
index 46ef6ec1..475ac65a 100644
--- a/config/slskd.example.yml
+++ b/config/slskd.example.yml
@@ -81,6 +81,8 @@
# destination:
# subdirectory: ${SOURCE_DIRECTORY} # options: SOURCE_USERNAME, SOURCE_PATH, SOURCE_DIRECTORY, BATCH_ID, BATCH_EXTERNAL_ID, SEARCH_ID, SEARCH_TEXT
# exists: rename # 'overwrite' or 'rename'
+# permissions:
+# mode: ~ # chmod syntax, e.g. 644, 777. does nothing on Windows.
# groups:
# default:
# upload:
diff --git a/docs/config.md b/docs/config.md
index 8848060a..c8a8fca2 100644
--- a/docs/config.md
+++ b/docs/config.md
@@ -117,21 +117,11 @@ Users wishing to create files with different permissions can change the umask va
When running within a docker container the environment variable `SLSKD_UMASK` can be used to change the umask for the process within the container, and this will in turn change the resulting file mode on a mounted volume.
-Users can optionally configure alternative permissions for files by setting the file permission mode option. It's not possible to supersede the configured umask value; setting a mode of 777, for example, will have no effect with a umask of 022.
-
-These options have no effect on Windows.
+This option has no effect on Windows.
| Command-Line | Environment Variable | Description |
| ------------------------ | -----------------------------| -------------------------------------------------------------------------------- |
| n/a | `SLSKD_UMASK` | When running within the slskd Docker container, the umask for the process |
-| `--file-permission-mode` | `SLSKD_FILE_PERMISSION_MODE` | The permissions to apply to newly created files (chmod syntax, non-Windows only) |
-
-#### **YAML**
-```yaml
-permissions:
- file:
- mode: 644 # not for Windows, chmod syntax, e.g. 644, 777. can't escalate beyond umask
-```
# Application Directory Configuration
@@ -377,6 +367,25 @@ transfers:
max_delay: 60000 # maximum time between retries, in milliseconds
```
+## Destination
+
+### Permissions
+
+On [Unix-like](https://en.wikipedia.org/wiki/Unix-like) operating systems, downloaded files will be created according to the [umask](https://en.wikipedia.org/wiki/Umask) of the process (see [Permissions](#permissions) for more info).
+
+Users can optionally configure alternative permissions by setting the permission mode option which, when enabled, effectively causes slskd to `chmod` files and directories with the configured mode immediately after creation.
+
+This option has no effect on Windows.
+
+#### **YAML**
+```yaml
+transfers:
+ download:
+ destination:
+ permissions:
+ mode: 644 # chmod syntax, e.g. 644, 777. has no effect on Windows
+```
+
## Global Upload Limits
Global upload limits define the number of queued, daily, and weekly uploads on a _per user_ basis. These limits behave as defaults and are applied if limits for a user's group have not been set.
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;
/*