aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2024-05-18 14:18:50 -0500
committerJP Dillingham <jp@dillingham.me>2024-05-18 14:18:50 -0500
commit65337c147088318961e58c549a90ab79dfa51b44 (patch)
treed5332e37e6be2587a0551eee024261f2e519b9b1 /src
parent57b0a10b294d89659fba11ba616b1afdefd82d5e (diff)
downloadslskd-65337c147088318961e58c549a90ab79dfa51b44.tar.gz
default file permissions to nothing (use umask)
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Core/Options.cs12
-rw-r--r--src/slskd/Files/FileService.cs12
-rw-r--r--src/slskd/Transfers/Downloads/DownloadService.cs4
3 files changed, 19 insertions, 9 deletions
diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs
index e67be138..e7462848 100644
--- a/src/slskd/Core/Options.cs
+++ b/src/slskd/Core/Options.cs
@@ -875,7 +875,7 @@ namespace slskd
[Argument(default, "downloaded-file-permissions")]
[EnvironmentVariable("DOWNLOADED_FILE_PERMISSIONS")]
[Description("the permissions to apply to newly downloaded files (chmod syntax, non-Windows only)")]
- public string Permissions { get; init; } = "644";
+ public string Permissions { get; init; }
/// <summary>
/// Extended validation.
@@ -884,12 +884,16 @@ namespace slskd
/// <returns></returns>
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
- var regEx = new Regex("^[0-7]{3,4}$", RegexOptions.Compiled);
var results = new List<ValidationResult>();
- if (!regEx.IsMatch(Permissions))
+ if (!string.IsNullOrEmpty(Permissions))
{
- results.Add(new ValidationResult($"Field {nameof(Permissions)} is invalid. Specify a three- or four-character string consisting of only 0-7 (chmod syntax, [0]000-[7]777, inclusive)"));
+ var regEx = new Regex("^[0-7]{3,4}$", RegexOptions.Compiled);
+
+ if (!regEx.IsMatch(Permissions))
+ {
+ results.Add(new ValidationResult($"Field {nameof(Permissions)} 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 3bcdd04f..d9aa9dc3 100644
--- a/src/slskd/Files/FileService.cs
+++ b/src/slskd/Files/FileService.cs
@@ -275,11 +275,15 @@ namespace slskd.Files
// we *MUST* check the OS and skip this on Windows
if (!OperatingSystem.IsWindows())
{
- streamOptions.UnixCreateMode = options?.UnixCreateMode
- ?? OptionsMonitor.CurrentValue.Global.Download.File.Permissions?.ToUnixFileMode()
- ?? UnixFileMode.None;
+ var appOption = OptionsMonitor.CurrentValue.Global.Download.File.Permissions;
- Log.Debug("Setting Unix file mode to {Mode}", streamOptions.UnixCreateMode);
+ // 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);
+ }
}
try
diff --git a/src/slskd/Transfers/Downloads/DownloadService.cs b/src/slskd/Transfers/Downloads/DownloadService.cs
index e6410691..bdd7ebed 100644
--- a/src/slskd/Transfers/Downloads/DownloadService.cs
+++ b/src/slskd/Transfers/Downloads/DownloadService.cs
@@ -296,7 +296,9 @@ namespace slskd.Transfers.Downloads
Access = System.IO.FileAccess.Write,
Mode = System.IO.FileMode.Create, // overwrites file if it exists
Share = System.IO.FileShare.None, // exclusive access for the duration of the download
- UnixCreateMode = OptionsMonitor.CurrentValue.Global.Download.File.Permissions.ToUnixFileMode(),
+ UnixCreateMode = !string.IsNullOrEmpty(OptionsMonitor.CurrentValue.Global.Download.File.Permissions)
+ ? OptionsMonitor.CurrentValue.Global.Download.File.Permissions.ToUnixFileMode()
+ : null,
})),
size: file.Size,
startOffset: 0,