aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Files/FileService.cs
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-02-15 16:44:15 -0600
committerJP Dillingham <jp@dillingham.me>2026-02-15 16:44:15 -0600
commit1916c29cec5ae50c8946f2df75c19af52703fc4c (patch)
tree7e5aee2e33d9a20f78d66fdda3197ec7d197648d /src/slskd/Files/FileService.cs
parent86d1ebbed867b43655173065441c17720a1e7c58 (diff)
downloadslskd-1916c29cec5ae50c8946f2df75c19af52703fc4c.tar.gz
fix download error when no file mode is configured
Diffstat (limited to 'src/slskd/Files/FileService.cs')
-rw-r--r--src/slskd/Files/FileService.cs38
1 files changed, 14 insertions, 24 deletions
diff --git a/src/slskd/Files/FileService.cs b/src/slskd/Files/FileService.cs
index 6c2e6d41..62adeb33 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,9 +401,11 @@ 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());
}
@@ -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