From 79cd6c0033631b33e9508b7c10e48b9edfafe21d Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 19 May 2024 21:40:47 -0500 Subject: move options once again --- src/slskd/Core/Options.cs | 102 +++++++++++++---------- src/slskd/Files/FileService.cs | 2 +- src/slskd/Transfers/Downloads/DownloadService.cs | 4 +- 3 files changed, 60 insertions(+), 48 deletions(-) (limited to 'src') 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 @@ -209,6 +209,12 @@ namespace slskd [Validate] public RelayOptions Relay { get; init; } = new RelayOptions(); + /// + /// Gets permission options. + /// + [Validate] + public PermissionsOptions Permissions { get; init; } = new PermissionsOptions(); + /// /// Gets directory options. /// @@ -602,6 +608,57 @@ namespace slskd } } + /// + /// Permission options. + /// + public class PermissionsOptions + { + /// + /// Gets file permission options. + /// + [Validate] + public FileOptions File { get; init; } = new FileOptions(); + + /// + /// File permission options. + /// + public class FileOptions : IValidatableObject + { + /// + /// Gets the permissions to apply to newly created files. + /// + /// + /// Applicable to non-Windows operating systems, only. + /// + [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; } + + /// + /// Extended validation. + /// + /// + /// + public IEnumerable Validate(ValidationContext validationContext) + { + var results = new List(); + + 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; + } + } + } + /// /// Directory options. /// @@ -853,51 +910,6 @@ namespace slskd [Description("the total download speed limit")] [Range(1, int.MaxValue)] public int SpeedLimit { get; init; } = int.MaxValue; - - /// - /// Gets downloaded file options. - /// - [Validate] - public GlobalDownloadFileOptions File { get; init; } = new GlobalDownloadFileOptions(); - } - - /// - /// File options. - /// - public class GlobalDownloadFileOptions : IValidatableObject - { - /// - /// Gets the permissions to apply to newly downloaded files. - /// - /// - /// Applicable to non-Windows operating systems, only. - /// - [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; } - - /// - /// Extended validation. - /// - /// - /// - public IEnumerable Validate(ValidationContext validationContext) - { - var results = new List(); - - 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, -- cgit v1.2.3