From b2efaa856ad06c13c4721699133441bb1af8b060 Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Mon, 19 Dec 2022 13:48:31 +0000 Subject: [PATCH 1/3] Refactor `MUIFileSearcher.AddFiles` --- .../help/MUIFileSearcher.cs | 51 ++++--------------- 1 file changed, 9 insertions(+), 42 deletions(-) diff --git a/src/System.Management.Automation/help/MUIFileSearcher.cs b/src/System.Management.Automation/help/MUIFileSearcher.cs index 1873a341c42..7d950785483 100644 --- a/src/System.Management.Automation/help/MUIFileSearcher.cs +++ b/src/System.Management.Automation/help/MUIFileSearcher.cs @@ -57,6 +57,14 @@ private MUIFileSearcher(string target, Collection searchPaths) /// internal SearchMode SearchMode { get; } = SearchMode.Unique; + private static EnumerationOptions _enumerationOptions = new() + { + IgnoreInaccessible = false, + AttributesToSkip = 0, + MatchType = MatchType.Win32, + MatchCasing = MatchCasing.CaseInsensitive, + }; + private Collection _result = null; /// @@ -113,52 +121,11 @@ private void SearchForFiles() } } - private static string[] GetFiles(string path, string pattern) - { -#if UNIX - // On Linux, file names are case sensitive, so we need to add - // extra logic to select the files that match the given pattern. - var result = new List(); - string[] files = Directory.GetFiles(path); - - var wildcardPattern = WildcardPattern.ContainsWildcardCharacters(pattern) - ? WildcardPattern.Get(pattern, WildcardOptions.IgnoreCase) - : null; - - foreach (string filePath in files) - { - if (filePath.Contains(pattern, StringComparison.OrdinalIgnoreCase)) - { - result.Add(filePath); - break; - } - - if (wildcardPattern != null) - { - string fileName = Path.GetFileName(filePath); - if (wildcardPattern.IsMatch(fileName)) - { - result.Add(filePath); - } - } - } - - return result.ToArray(); -#else - return Directory.GetFiles(path, pattern); -#endif - } - private void AddFiles(string muiDirectory, string directory, string pattern) { if (Directory.Exists(muiDirectory)) { - string[] files = GetFiles(muiDirectory, pattern); - - if (files == null) - return; - - foreach (string file in files) + foreach (string file in Directory.EnumerateFiles(muiDirectory, pattern, _enumerationOptions)) { string path = Path.Combine(muiDirectory, file); From 986cc7fb5757ed4b736138b78b20ae3a4ddcb961 Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Mon, 19 Dec 2022 18:14:38 +0000 Subject: [PATCH 2/3] fix IDE0044 --- src/System.Management.Automation/help/MUIFileSearcher.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System.Management.Automation/help/MUIFileSearcher.cs b/src/System.Management.Automation/help/MUIFileSearcher.cs index 7d950785483..c8fe2057aa3 100644 --- a/src/System.Management.Automation/help/MUIFileSearcher.cs +++ b/src/System.Management.Automation/help/MUIFileSearcher.cs @@ -57,7 +57,7 @@ private MUIFileSearcher(string target, Collection searchPaths) /// internal SearchMode SearchMode { get; } = SearchMode.Unique; - private static EnumerationOptions _enumerationOptions = new() + private static readonly EnumerationOptions _enumerationOptions = new() { IgnoreInaccessible = false, AttributesToSkip = 0, From c059fe821dc3284a76ee5b3d2d57f12d87b4b996 Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Fri, 23 Dec 2022 15:15:46 +0000 Subject: [PATCH 3/3] fix name clash --- src/System.Management.Automation/help/MUIFileSearcher.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System.Management.Automation/help/MUIFileSearcher.cs b/src/System.Management.Automation/help/MUIFileSearcher.cs index c8fe2057aa3..dd437fa90c0 100644 --- a/src/System.Management.Automation/help/MUIFileSearcher.cs +++ b/src/System.Management.Automation/help/MUIFileSearcher.cs @@ -57,7 +57,7 @@ private MUIFileSearcher(string target, Collection searchPaths) /// internal SearchMode SearchMode { get; } = SearchMode.Unique; - private static readonly EnumerationOptions _enumerationOptions = new() + private static readonly System.IO.EnumerationOptions _enumerationOptions = new() { IgnoreInaccessible = false, AttributesToSkip = 0,