From 0ac534fc2f337f07c9c9495b9e009eecd042234e Mon Sep 17 00:00:00 2001 From: Dao Heng Liu Date: Thu, 21 Dec 2023 22:15:29 +0000 Subject: [PATCH] allow enumeration of dirents despite not all of them succeeding see #6082 --- .../Graphics/UserInterface/DirectorySelector.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/osu.Framework/Graphics/UserInterface/DirectorySelector.cs b/osu.Framework/Graphics/UserInterface/DirectorySelector.cs index 228e5a7d87..f37b4aa620 100644 --- a/osu.Framework/Graphics/UserInterface/DirectorySelector.cs +++ b/osu.Framework/Graphics/UserInterface/DirectorySelector.cs @@ -11,6 +11,7 @@ using osu.Framework.Bindables; using osu.Framework.Extensions.EnumExtensions; using osu.Framework.Graphics.Containers; +using osu.Framework.Logging; using osu.Framework.Platform; using osuTK; @@ -204,10 +205,19 @@ protected virtual bool TryGetEntriesForPath(DirectoryInfo path, out ICollection< try { - foreach (var dir in path.GetDirectories().OrderBy(d => d.Name)) + foreach (string directoryName in Directory.GetDirectories(path.FullName).OrderBy(d => d)) { - if (ShowHiddenItems.Value || !dir.Attributes.HasFlagFast(FileAttributes.Hidden)) - items.Add(CreateDirectoryItem(dir)); + try + { + DirectoryInfo di = new DirectoryInfo(directoryName); + if (ShowHiddenItems.Value || !di.Attributes.HasFlagFast(FileAttributes.Hidden)) + items.Add(CreateDirectoryItem(di)); + } + catch + { + // Don't fail enumeration if we fail getting attributes for a single entry + Logger.Log($"Directory {directoryName} is inaccessible", LoggingTarget.Information, LogLevel.Debug); + } } return true;