aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Shares
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2022-06-17 17:53:00 -0500
committerJP Dillingham <jp@dillingham.me>2022-06-17 17:53:00 -0500
commit65fd4ac77688f2a9991cbfa42e275daeb49dba88 (patch)
tree011429e457bb3c2b627537fd1e7c65840e42f64d /src/slskd/Shares
parent1ecb866f81258d6a2319482de5dde52a1f96a13f (diff)
downloadslskd-65fd4ac77688f2a9991cbfa42e275daeb49dba88.tar.gz
tweak scanning of files and directories to exclude hidden, system, and inacessible things
Diffstat (limited to 'src/slskd/Shares')
-rw-r--r--src/slskd/Shares/SharedFileCache.cs19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/slskd/Shares/SharedFileCache.cs b/src/slskd/Shares/SharedFileCache.cs
index 5588a4bb..7db79200 100644
--- a/src/slskd/Shares/SharedFileCache.cs
+++ b/src/slskd/Shares/SharedFileCache.cs
@@ -211,12 +211,20 @@ namespace slskd.Shares
Log.Debug("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
{
- return System.IO.Directory.GetDirectories(share.LocalPath, "*", SearchOption.AllDirectories);
+ return System.IO.Directory.GetDirectories(share.LocalPath, "*", new EnumerationOptions()
+ {
+ AttributesToSkip = FileAttributes.Hidden | FileAttributes.System,
+ IgnoreInaccessible = true,
+ RecurseSubdirectories = true,
+ });
}
catch (Exception ex)
{
@@ -252,7 +260,14 @@ namespace slskd.Shares
// filename and with a value of a Soulseek.File object
try
{
- var newFiles = System.IO.Directory.GetFiles(directory, "*", SearchOption.TopDirectoryOnly)
+ // enumerate files in this directory only (no subdirectories)
+ // exclude hidden and system files and anything that can't be accessed due to security restrictions
+ var newFiles = System.IO.Directory.GetFiles(directory, "*", new EnumerationOptions()
+ {
+ AttributesToSkip = FileAttributes.Hidden | FileAttributes.System,
+ IgnoreInaccessible = true,
+ RecurseSubdirectories = false,
+ })
.Select(filename => SoulseekFileFactory.Create(filename, maskedFilename: filename.ReplaceFirst(share.LocalPath, share.RemotePath)))
.ToDictionary(file => file.Filename, file => file);