diff options
| author | JP Dillingham <jp@dillingham.me> | 2022-06-17 21:37:01 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-17 21:37:01 -0500 |
| commit | 72cd31de4502a5f1226ff337f8d69d26a34765a0 (patch) | |
| tree | 011429e457bb3c2b627537fd1e7c65840e42f64d | |
| parent | 1ecb866f81258d6a2319482de5dde52a1f96a13f (diff) | |
| parent | 65fd4ac77688f2a9991cbfa42e275daeb49dba88 (diff) | |
| download | slskd-72cd31de4502a5f1226ff337f8d69d26a34765a0.tar.gz | |
Merge pull request #521 from slskd/dir-walk
Fix bug causing a share scan to fail if one of the subdirectories within can't be accessed
| -rw-r--r-- | src/slskd/Shares/SharedFileCache.cs | 19 |
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); |
