From b0420bd49b64995671b80deeef54cffece0a4d41 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 10 Sep 2022 13:14:45 -0500 Subject: add StorageType --- src/slskd/Core/Types/StorageType.cs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/slskd/Core/Types/StorageType.cs (limited to 'src/slskd/Core') diff --git a/src/slskd/Core/Types/StorageType.cs b/src/slskd/Core/Types/StorageType.cs new file mode 100644 index 00000000..63b19899 --- /dev/null +++ b/src/slskd/Core/Types/StorageType.cs @@ -0,0 +1,35 @@ +// +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see https://www.gnu.org/licenses/. +// + +namespace slskd +{ + /// + /// Storage type. + /// + public enum StorageType + { + /// + /// Stored in memory. + /// + Memory = 0, + + /// + /// Stored on disk. + /// + Disk = 1, + } +} -- cgit v1.2.3 From 5e11cc0fc0703dc161140b28f7e2cd0f65facf9c Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 10 Sep 2022 13:17:18 -0500 Subject: consolidate share options, add cache storage option --- config/slskd.example.yml | 12 ++++---- src/slskd/Core/Options.cs | 76 +++++++++++++++++++++++++++++++++++++---------- 2 files changed, 68 insertions(+), 20 deletions(-) (limited to 'src/slskd/Core') diff --git a/config/slskd.example.yml b/config/slskd.example.yml index 7038c576..46033bff 100644 --- a/config/slskd.example.yml +++ b/config/slskd.example.yml @@ -12,8 +12,14 @@ # directories: # incomplete: ~ # downloads: ~ -# shared: +# shares: +# directories: # - ~ +# filters: +# - \.ini$ +# - Thumbs.db$ +# - \.DS_Store$ +# cache_storage: memory # rooms: # - ~ # global: @@ -48,10 +54,6 @@ # - alice # - bob # filters: -# share: -# - \.ini$ -# - Thumbs.db$ -# - \.DS_Store$ # search: # request: # - ^.{1,2}$ diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index d6d4b04c..327036aa 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -196,6 +196,13 @@ namespace slskd [RequiresRestart] public DirectoriesOptions Directories { get; init; } = new DirectoriesOptions(); + /// + /// Gets share options. + /// + [Validate] + [RequiresRestart] + public SharesOptions Shares { get; init; } = new SharesOptions(); + /// /// Gets global options. /// @@ -324,7 +331,7 @@ namespace slskd /// /// Directory options. /// - public class DirectoriesOptions : IValidatableObject + public class DirectoriesOptions { /// /// Gets the path where incomplete downloads are saved. @@ -345,14 +352,36 @@ namespace slskd [DirectoryExists(ensureWriteable: true)] [RequiresRestart] public string Downloads { get; init; } = Program.DefaultDownloadsDirectory; + } + /// + /// Share options. + /// + public class SharesOptions : IValidatableObject + { /// /// Gets the list of paths to shared files. /// [Argument('s', "shared")] [EnvironmentVariable("SHARED_DIR")] - [Description("path to shared files")] - public string[] Shared { get; init; } = Array.Empty(); + [Description("paths to shared files")] + public string[] Directories { get; init; } = Array.Empty(); + + /// + /// Gets the list of shared file filters. + /// + [Argument(default, "share-filter")] + [EnvironmentVariable("SHARE_FILTER")] + [Description("regular expressions to filter files from shares")] + public string[] Filters { get; init; } = Array.Empty(); + + /// + /// Gets the type of storage to use for the share cache. + /// + [Argument(default, "share-cache-storage")] + [EnvironmentVariable("SHARE_CACHE_STORAGE")] + [Description("the type of storage to use for the cache")] + public StorageType CacheStorage { get; init; } = StorageType.Memory; /// /// Extended validation. @@ -363,17 +392,27 @@ namespace slskd { var results = new List(); + results.AddRange(ValidateShares()); + results.AddRange(ValidateFilters()); + + return results; + } + + private IEnumerable ValidateShares() + { + var results = new List(); + bool IsBlankPath(string share) => Regex.IsMatch(share.LocalizePath(), @"^(!|-){0,1}(\[.*\])$"); - Shared.Where(share => IsBlankPath(share)).ToList() + Directories.Where(share => IsBlankPath(share)).ToList() .ForEach(blank => results.Add(new ValidationResult($"Share {blank} doees not specify a path"))); bool IsRootMount(string share) => Regex.IsMatch(share.LocalizePath(), @"^(!|-){0,1}(\[.*\])/$"); - Shared.Where(share => IsRootMount(share)).ToList() + Directories.Where(share => IsRootMount(share)).ToList() .ForEach(blank => results.Add(new ValidationResult($"Share {blank} specifies a root mount, which is not supported."))); // starts with '/', 'X:', or '\\' bool IsAbsolutePath(string share) => Regex.IsMatch(share.LocalizePath(), @"^(!|-){0,1}(\[.*\])?(\/|[a-zA-Z]:|\\\\).*$"); - Shared.Where(share => !IsAbsolutePath(share)).ToList() + Directories.Where(share => !IsAbsolutePath(share)).ToList() .ForEach(relativePath => results.Add(new ValidationResult($"Share {relativePath} contains a relative path; only absolute paths are supported."))); (string Raw, string Alias, string Path) Digest(string share) @@ -388,7 +427,7 @@ namespace slskd return (share, share.Split(new[] { '/', '\\' }).Last(), share); } - var digestedShared = Shared + var digestedShared = Directories .Select(share => Digest(share.TrimEnd('/', '\\'))) .ToHashSet(); @@ -415,6 +454,21 @@ namespace slskd return results; } + + private IEnumerable ValidateFilters() + { + var results = new List(); + + foreach (var filter in Filters) + { + if (!filter.IsValidRegex()) + { + results.Add(new ValidationResult($"Share filter '{filter}' is not a valid regular expression")); + } + } + + return results; + } } /// @@ -644,14 +698,6 @@ namespace slskd /// public class FiltersOptions : IValidatableObject { - /// - /// Gets the list of shared file filters. - /// - [Argument(default, "share-filter")] - [EnvironmentVariable("SHARE_FILTER")] - [Description("regular expressions to filter files from shares")] - public string[] Share { get; init; } = Array.Empty(); - /// /// Gets search filter options. /// -- cgit v1.2.3 From dab9af45aa0d06b882c661fc3cddb6af6f61545e Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 10 Sep 2022 17:37:33 -0500 Subject: add cache type --- config/slskd.example.yml | 3 ++- src/slskd/Core/Options.cs | 47 ++++++++++++++++++++--------------------------- 2 files changed, 22 insertions(+), 28 deletions(-) (limited to 'src/slskd/Core') diff --git a/config/slskd.example.yml b/config/slskd.example.yml index 46033bff..1f628077 100644 --- a/config/slskd.example.yml +++ b/config/slskd.example.yml @@ -19,7 +19,8 @@ # - \.ini$ # - Thumbs.db$ # - \.DS_Store$ -# cache_storage: memory +# cache: +# storage_mode: Memory # rooms: # - ~ # global: diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index 327036aa..2d561e29 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -200,7 +200,6 @@ namespace slskd /// Gets share options. /// [Validate] - [RequiresRestart] public SharesOptions Shares { get; init; } = new SharesOptions(); /// @@ -376,12 +375,26 @@ namespace slskd public string[] Filters { get; init; } = Array.Empty(); /// - /// Gets the type of storage to use for the share cache. + /// Share caching options. /// - [Argument(default, "share-cache-storage")] - [EnvironmentVariable("SHARE_CACHE_STORAGE")] - [Description("the type of storage to use for the cache")] - public StorageType CacheStorage { get; init; } = StorageType.Memory; + [Validate] + public ShareCacheOptions Cache { get; init; } = new ShareCacheOptions(); + + /// + /// Share caching options. + /// + public class ShareCacheOptions + { + /// + /// Gets the type of storage to use for the share cache. + /// + [Argument(default, "share-cache-storage-mode")] + [EnvironmentVariable("SHARE_CACHE_STORAGE_MODE")] + [Description("the type of storage to use for the cache")] + [Enum(typeof(StorageMode))] + [RequiresRestart] + public string StorageMode { get; init; } = slskd.StorageMode.Memory.ToString().ToLowerInvariant(); + } /// /// Extended validation. @@ -696,7 +709,7 @@ namespace slskd /// /// Filter options. /// - public class FiltersOptions : IValidatableObject + public class FiltersOptions { /// /// Gets search filter options. @@ -704,26 +717,6 @@ namespace slskd [Validate] public SearchOptions Search { get; init; } = new SearchOptions(); - /// - /// Extended validation. - /// - /// - /// - public IEnumerable Validate(ValidationContext validationContext) - { - var results = new List(); - - foreach (var filter in Share) - { - if (!filter.IsValidRegex()) - { - results.Add(new ValidationResult($"Share filter '{filter}' is not a valid regular expression")); - } - } - - return results; - } - /// /// Search filter options. /// -- cgit v1.2.3 From 79649ecdc4e49a01de85d099f449662cb78f23df Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 10 Sep 2022 17:38:12 -0500 Subject: StorageType -> StorageMode --- src/slskd/Core/Types/StorageMode.cs | 35 +++++++++++++++++++++++++++++++++++ src/slskd/Core/Types/StorageType.cs | 35 ----------------------------------- 2 files changed, 35 insertions(+), 35 deletions(-) create mode 100644 src/slskd/Core/Types/StorageMode.cs delete mode 100644 src/slskd/Core/Types/StorageType.cs (limited to 'src/slskd/Core') diff --git a/src/slskd/Core/Types/StorageMode.cs b/src/slskd/Core/Types/StorageMode.cs new file mode 100644 index 00000000..aced3050 --- /dev/null +++ b/src/slskd/Core/Types/StorageMode.cs @@ -0,0 +1,35 @@ +// +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see https://www.gnu.org/licenses/. +// + +namespace slskd +{ + /// + /// Storage mode. + /// + public enum StorageMode + { + /// + /// Stored in memory. + /// + Memory = 0, + + /// + /// Stored on disk. + /// + Disk = 1, + } +} diff --git a/src/slskd/Core/Types/StorageType.cs b/src/slskd/Core/Types/StorageType.cs deleted file mode 100644 index 63b19899..00000000 --- a/src/slskd/Core/Types/StorageType.cs +++ /dev/null @@ -1,35 +0,0 @@ -// -// Copyright (c) slskd Team. All rights reserved. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published -// by the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see https://www.gnu.org/licenses/. -// - -namespace slskd -{ - /// - /// Storage type. - /// - public enum StorageType - { - /// - /// Stored in memory. - /// - Memory = 0, - - /// - /// Stored on disk. - /// - Disk = 1, - } -} -- cgit v1.2.3 From bc362491446e4bfa94b7891ac0694d4f9b35df16 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 10 Sep 2022 17:38:37 -0500 Subject: add share backup, remove Filenames --- src/slskd/Core/ConnectionStrings.cs | 1 + src/slskd/Core/Filenames.cs | 30 ------------------------------ 2 files changed, 1 insertion(+), 30 deletions(-) delete mode 100644 src/slskd/Core/Filenames.cs (limited to 'src/slskd/Core') diff --git a/src/slskd/Core/ConnectionStrings.cs b/src/slskd/Core/ConnectionStrings.cs index e5bd4f05..6afab93f 100644 --- a/src/slskd/Core/ConnectionStrings.cs +++ b/src/slskd/Core/ConnectionStrings.cs @@ -24,6 +24,7 @@ namespace slskd { public string Transfers { get; init; } public string Shares { get; init; } + public string SharesBackup { get; init; } public string Search { get; init; } } } diff --git a/src/slskd/Core/Filenames.cs b/src/slskd/Core/Filenames.cs deleted file mode 100644 index 0fc55fc5..00000000 --- a/src/slskd/Core/Filenames.cs +++ /dev/null @@ -1,30 +0,0 @@ -// -// Copyright (c) slskd Team. All rights reserved. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published -// by the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see https://www.gnu.org/licenses/. -// - -namespace slskd -{ - /// - /// Application files. - /// - public static class Filenames - { - public static readonly string TransfersDb = "transfers.db"; - public static readonly string SharesDb = "shares.db"; - public static readonly string SearchDb = "search.db"; - public static readonly string BrowseCache = "browse.cache"; - } -} -- cgit v1.2.3