diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-09-07 12:06:37 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2026-09-07 12:06:37 -0500 |
| commit | 4fbd0d2a01c2cd225a0ecfb2b1dc4db47154923a (patch) | |
| tree | 0e8340b2de81b9db8069f93c96ef60e6457bb6ba /src/slskd/Shares | |
| parent | f70236b507fb54eff2460d056fcbfbee33a5a5d5 (diff) | |
| download | slskd-4fbd0d2a01c2cd225a0ecfb2b1dc4db47154923a.tar.gz | |
add stripped down IsSubDirectoryOf inline in scanner
Diffstat (limited to 'src/slskd/Shares')
| -rw-r--r-- | src/slskd/Shares/ShareScanner.cs | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/src/slskd/Shares/ShareScanner.cs b/src/slskd/Shares/ShareScanner.cs index 7c93d437..e763438f 100644 --- a/src/slskd/Shares/ShareScanner.cs +++ b/src/slskd/Shares/ShareScanner.cs @@ -199,20 +199,14 @@ namespace slskd.Shares Log.Information("Enumerating shared directories"); swSnapshot = sw.ElapsedMilliseconds; - // derive a list of all directories from all shares. skip hidden and system directories, as well as anything that - // can't be accessed due to security restrictions. it's necessary to enumerate these directories up front so we - // can deduplicate directories and apply exclusions - var unmaskedDirectories = Shares - .SelectMany(share => - { - try - { - var directories = System.IO.Directory.GetDirectories(share.LocalPath, "*", new EnumerationOptions() - { - AttributesToSkip = FileAttributes.Hidden | FileAttributes.System, - IgnoreInaccessible = true, - RecurseSubdirectories = true, - }); + // note: there's a safer version of this in the FileSafety class that checks for traversal and navigates + // case sensitivity for different operating systems. this version is stripped down for speed, and because + // we're not dealing with untrusted data + static bool IsSubDirectoryOf(string subDirectory, string root, StringComparison stringComparison = StringComparison.OrdinalIgnoreCase) + { + return subDirectory.TrimEnd('/', '\\').Equals(root.TrimEnd('/', '\\'), stringComparison) || // subdirectory literally is the root + subDirectory.StartsWith(root.TrimEnd('/', '\\') + Path.DirectorySeparatorChar, stringComparison); + } return directories.Where(directory => !filters.Any(filter => filter.IsMatch(directory))); } |
