aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Files/FileService.cs
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-02-15 17:10:15 -0600
committerGitHub <noreply@github.com>2026-02-15 17:10:15 -0600
commit183645f2e1d99c8e5ef1334ade9acfe399f82be1 (patch)
treefa097fc0203de8afe6b5b83d2596c06fcbbf439a /src/slskd/Files/FileService.cs
parent86d1ebbed867b43655173065441c17720a1e7c58 (diff)
parent13e54844f0568de7449281051c99ed3f234bc25a (diff)
downloadslskd-183645f2e1d99c8e5ef1334ade9acfe399f82be1.tar.gz
Merge pull request #1642 from slskd/mode-null
Fix download error when no file mode is configured
Diffstat (limited to 'src/slskd/Files/FileService.cs')
-rw-r--r--src/slskd/Files/FileService.cs40
1 files changed, 15 insertions, 25 deletions
diff --git a/src/slskd/Files/FileService.cs b/src/slskd/Files/FileService.cs
index 6c2e6d41..de577b6c 100644
--- a/src/slskd/Files/FileService.cs
+++ b/src/slskd/Files/FileService.cs
@@ -327,11 +327,13 @@ namespace slskd.Files
var path = Path.GetDirectoryName(filename);
+ UnixFileMode? unixCreateMode = options?.UnixCreateMode ?? OptionsMonitor.CurrentValue.Permissions.File.Mode?.ToUnixFileMode();
+
if (!Directory.Exists(path))
{
- if (!OperatingSystem.IsWindows())
+ if (!OperatingSystem.IsWindows() && unixCreateMode.HasValue)
{
- Directory.CreateDirectory(path, OptionsMonitor.CurrentValue.Permissions.File.Mode.ToUnixFileMode());
+ Directory.CreateDirectory(path, unixCreateMode.Value);
}
else
{
@@ -351,17 +353,11 @@ namespace slskd.Files
// attempting to use UnixCreateMode on Windows raises an Exception
// we *MUST* check the OS and skip this on Windows
- if (!OperatingSystem.IsWindows())
+ // if we omit this on *nix systems, the application's UMASK is used
+ if (!OperatingSystem.IsWindows() && unixCreateMode.HasValue)
{
- var appOption = OptionsMonitor.CurrentValue.Permissions.File.Mode;
-
- // if options haven't been passed in and none have been set in app config, omit this
- // so that the application's umask will be applied, saving users the hassle of setting it twice.
- if (options?.UnixCreateMode != null || !string.IsNullOrWhiteSpace(appOption))
- {
- streamOptions.UnixCreateMode = options?.UnixCreateMode ?? appOption?.ToUnixFileMode();
- Log.Debug("Setting Unix file mode to {Mode}", streamOptions.UnixCreateMode);
- }
+ streamOptions.UnixCreateMode = unixCreateMode;
+ Log.Debug("Setting Unix file mode to {Mode}", streamOptions.UnixCreateMode);
}
try
@@ -405,11 +401,13 @@ namespace slskd.Files
throw new FileNotFoundException($"The specified source file does not exist", fileName: sourceFilename);
}
+ UnixFileMode? unixCreateMode = unixFileMode ?? OptionsMonitor.CurrentValue.Permissions.File.Mode?.ToUnixFileMode();
+
if (!Directory.Exists(destinationDirectory))
{
- if (!OperatingSystem.IsWindows())
+ if (!OperatingSystem.IsWindows() && unixCreateMode.HasValue)
{
- Directory.CreateDirectory(destinationDirectory, OptionsMonitor.CurrentValue.Permissions.File.Mode.ToUnixFileMode());
+ Directory.CreateDirectory(destinationDirectory, unixCreateMode.Value);
}
else
{
@@ -442,18 +440,10 @@ namespace slskd.Files
// attempting to use UnixCreateMode on Windows raises an Exception
// we *MUST* check the OS and skip this on Windows
- if (!OperatingSystem.IsWindows())
+ if (!OperatingSystem.IsWindows() && unixCreateMode.HasValue)
{
- var appOption = OptionsMonitor.CurrentValue.Permissions.File.Mode;
- var mode = unixFileMode ?? appOption?.ToUnixFileMode();
-
- // if options haven't been passed in and none have been set in app config, omit this
- // so that the application's umask will be applied, saving users the hassle of setting it twice.
- if (mode.HasValue)
- {
- File.SetUnixFileMode(destinationFilename, mode.Value);
- Log.Debug("Successfully set Unix file mode to {Mode}", mode);
- }
+ File.SetUnixFileMode(destinationFilename, unixCreateMode.Value);
+ Log.Debug("Successfully set Unix file mode to {Mode}", unixCreateMode);
}
// if the parent directory is empty after the move, delete it