From d221780782481d931daa11b04e14229accceee6d Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 17 May 2024 18:27:32 -0500 Subject: move config under Global --- src/slskd/Core/Options.cs | 82 ++++++++++++------------ src/slskd/Files/FileService.cs | 2 +- src/slskd/Transfers/Downloads/DownloadService.cs | 2 +- 3 files changed, 43 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index 37b333ba..e67be138 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -209,12 +209,6 @@ namespace slskd [Validate] public RelayOptions Relay { get; init; } = new RelayOptions(); - /// - /// Gets file options. - /// - [Validate] - public FilesOptions Files { get; init; } = new FilesOptions(); - /// /// Gets directory options. /// @@ -608,41 +602,6 @@ namespace slskd } } - /// - /// File options. - /// - public class FilesOptions : IValidatableObject - { - /// - /// Gets the permissions to apply to newly created files. - /// - /// - /// Applicable to non-Windows operating systems, only. - /// - [Argument(default, "file-permissions")] - [EnvironmentVariable("FILE_PERMISSIONS")] - [Description("the permissions to apply to newly created files (chmod syntax, non-Windows only)")] - public string Permissions { get; init; } = "644"; - - /// - /// Extended validation. - /// - /// - /// - public IEnumerable Validate(ValidationContext validationContext) - { - var regEx = new Regex("^[0-7]{3,4}$", RegexOptions.Compiled); - var results = new List(); - - if (!regEx.IsMatch(Permissions)) - { - results.Add(new ValidationResult($"Field {nameof(Permissions)} is invalid. Specify a three-character string consisting of only 0-7 (chmod syntax, 000-777, inclusive)")); - } - - return results; - } - } - /// /// Directory options. /// @@ -894,6 +853,47 @@ 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; } = "644"; + + /// + /// Extended validation. + /// + /// + /// + public IEnumerable Validate(ValidationContext validationContext) + { + var regEx = new Regex("^[0-7]{3,4}$", RegexOptions.Compiled); + var results = new List(); + + 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 91dadba6..3bcdd04f 100644 --- a/src/slskd/Files/FileService.cs +++ b/src/slskd/Files/FileService.cs @@ -276,7 +276,7 @@ namespace slskd.Files if (!OperatingSystem.IsWindows()) { streamOptions.UnixCreateMode = options?.UnixCreateMode - ?? OptionsMonitor.CurrentValue.Files.Permissions?.ToUnixFileMode() + ?? OptionsMonitor.CurrentValue.Global.Download.File.Permissions?.ToUnixFileMode() ?? UnixFileMode.None; Log.Debug("Setting Unix file mode to {Mode}", streamOptions.UnixCreateMode); diff --git a/src/slskd/Transfers/Downloads/DownloadService.cs b/src/slskd/Transfers/Downloads/DownloadService.cs index f848928f..e6410691 100644 --- a/src/slskd/Transfers/Downloads/DownloadService.cs +++ b/src/slskd/Transfers/Downloads/DownloadService.cs @@ -296,7 +296,7 @@ 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.Files.Permissions.ToUnixFileMode(), + UnixCreateMode = OptionsMonitor.CurrentValue.Global.Download.File.Permissions.ToUnixFileMode(), })), size: file.Size, startOffset: 0, -- cgit v1.2.3