aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2024-05-19 21:40:47 -0500
committerJP Dillingham <jpdillingham@gmail.com>2024-05-19 21:40:47 -0500
commit79cd6c0033631b33e9508b7c10e48b9edfafe21d (patch)
treeb78f8e3e79315e586411e3609fbf73cce38d3fe9 /src
parent65337c147088318961e58c549a90ab79dfa51b44 (diff)
downloadslskd-79cd6c0033631b33e9508b7c10e48b9edfafe21d.tar.gz
move options once again
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Core/Options.cs102
-rw-r--r--src/slskd/Files/FileService.cs2
-rw-r--r--src/slskd/Transfers/Downloads/DownloadService.cs4
3 files changed, 60 insertions, 48 deletions
diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs
index e7462848..f2419c83 100644
--- a/src/slskd/Core/Options.cs
+++ b/src/slskd/Core/Options.cs
@@ -210,6 +210,12 @@ namespace slskd
public RelayOptions Relay { get; init; } = new RelayOptions();
/// <summary>
+ /// Gets permission options.
+ /// </summary>
+ [Validate]
+ public PermissionsOptions Permissions { get; init; } = new PermissionsOptions();
+
+ /// <summary>
/// Gets directory options.
/// </summary>
[Validate]
@@ -603,6 +609,57 @@ namespace slskd
}
/// <summary>
+ /// Permission options.
+ /// </summary>
+ public class PermissionsOptions
+ {
+ /// <summary>
+ /// Gets file permission options.
+ /// </summary>
+ [Validate]
+ public FileOptions File { get; init; } = new FileOptions();
+
+ /// <summary>
+ /// File permission options.
+ /// </summary>
+ public class FileOptions : IValidatableObject
+ {
+ /// <summary>
+ /// Gets the permissions to apply to newly created files.
+ /// </summary>
+ /// <remarks>
+ /// Applicable to non-Windows operating systems, only.
+ /// </remarks>
+ [Argument(default, "file-permission-mode")]
+ [EnvironmentVariable("FILE_PERMISSION_MODE")]
+ [Description("the permissions to apply to newly created files (chmod syntax, non-Windows only)")]
+ public string Mode { get; init; }
+
+ /// <summary>
+ /// Extended validation.
+ /// </summary>
+ /// <param name="validationContext"></param>
+ /// <returns></returns>
+ 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;
+ }
+ }
+ }
+
+ /// <summary>
/// Directory options.
/// </summary>
public class DirectoriesOptions
@@ -853,51 +910,6 @@ namespace slskd
[Description("the total download speed limit")]
[Range(1, int.MaxValue)]
public int SpeedLimit { get; init; } = int.MaxValue;
-
- /// <summary>
- /// Gets downloaded file options.
- /// </summary>
- [Validate]
- public GlobalDownloadFileOptions File { get; init; } = new GlobalDownloadFileOptions();
- }
-
- /// <summary>
- /// File options.
- /// </summary>
- public class GlobalDownloadFileOptions : IValidatableObject
- {
- /// <summary>
- /// Gets the permissions to apply to newly downloaded files.
- /// </summary>
- /// <remarks>
- /// Applicable to non-Windows operating systems, only.
- /// </remarks>
- [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; }
-
- /// <summary>
- /// Extended validation.
- /// </summary>
- /// <param name="validationContext"></param>
- /// <returns></returns>
- public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
- {
- var results = new List<ValidationResult>();
-
- if (!string.IsNullOrEmpty(Permissions))
- {
- 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 d9aa9dc3..0d193d73 100644
--- a/src/slskd/Files/FileService.cs
+++ b/src/slskd/Files/FileService.cs
@@ -275,7 +275,7 @@ namespace slskd.Files
// we *MUST* check the OS and skip this on Windows
if (!OperatingSystem.IsWindows())
{
- var appOption = OptionsMonitor.CurrentValue.Global.Download.File.Permissions;
+ 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.
diff --git a/src/slskd/Transfers/Downloads/DownloadService.cs b/src/slskd/Transfers/Downloads/DownloadService.cs
index bdd7ebed..32903bf9 100644
--- a/src/slskd/Transfers/Downloads/DownloadService.cs
+++ b/src/slskd/Transfers/Downloads/DownloadService.cs
@@ -296,8 +296,8 @@ 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 = !string.IsNullOrEmpty(OptionsMonitor.CurrentValue.Global.Download.File.Permissions)
- ? OptionsMonitor.CurrentValue.Global.Download.File.Permissions.ToUnixFileMode()
+ UnixCreateMode = !string.IsNullOrEmpty(OptionsMonitor.CurrentValue.Permissions.File.Mode)
+ ? OptionsMonitor.CurrentValue.Permissions.File.Mode.ToUnixFileMode()
: null,
})),
size: file.Size,