diff --git a/VisualStudioSolutionSecrets.Tests/Commands/Command.Tests.cs b/VisualStudioSolutionSecrets.Tests/Commands/Command.Tests.cs index 72a574e..bf0b035 100644 --- a/VisualStudioSolutionSecrets.Tests/Commands/Command.Tests.cs +++ b/VisualStudioSolutionSecrets.Tests/Commands/Command.Tests.cs @@ -161,7 +161,12 @@ private void MockRepository() .ReturnsAsync((ISolution solution) => { List<(string name, string? content)> files = new List<(string name, string? content)>(); - string[] filesPath = Directory.GetFiles(Constants.RepositoryFilesPath, "*.json", SearchOption.AllDirectories); + string[] filesPath = Directory.GetFiles(Constants.RepositoryFilesPath, "*.json", new EnumerationOptions + { + IgnoreInaccessible = true, + ReturnSpecialDirectories = false, + RecurseSubdirectories = true + }); foreach (var filePath in filesPath) { string fileName = new FileInfo(filePath).Name; @@ -200,7 +205,12 @@ private void MockRepository() { List<(string name, string? content)> files = new List<(string name, string? content)>(); - string[] filesPath = Directory.GetFiles(Constants.RepositoryFilesPath, "*.json", SearchOption.AllDirectories); + string[] filesPath = Directory.GetFiles(Constants.RepositoryFilesPath, "*.json", new EnumerationOptions + { + IgnoreInaccessible = true, + ReturnSpecialDirectories = false, + RecurseSubdirectories = true + }); foreach (var filePath in filesPath) { string fileName = new FileInfo(filePath).Name; diff --git a/VisualStudioSolutionSecrets/Commands/Abstractions/CommandBase.cs b/VisualStudioSolutionSecrets/Commands/Abstractions/CommandBase.cs index 5f0affb..72337a7 100644 --- a/VisualStudioSolutionSecrets/Commands/Abstractions/CommandBase.cs +++ b/VisualStudioSolutionSecrets/Commands/Abstractions/CommandBase.cs @@ -56,7 +56,12 @@ protected static string[] GetSolutionFiles(string? path, bool all) try { string localDir = Context.Current.IO.GetCurrentDirectory(); - var files = Directory.GetFiles(localDir, fileInfo.Name, SearchOption.AllDirectories); + var files = Directory.GetFiles(localDir, fileInfo.Name, new EnumerationOptions + { + IgnoreInaccessible = true, + ReturnSpecialDirectories = false, + RecurseSubdirectories = true + }); if (files.Length == 1) { return files; @@ -78,7 +83,12 @@ protected static string[] GetSolutionFiles(string? path, bool all) var directory = path ?? Context.Current.IO.GetCurrentDirectory(); try { - var files = Directory.GetFiles(directory, "*.sln", all ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly); + var files = Directory.GetFiles(directory, "*.sln", new EnumerationOptions + { + IgnoreInaccessible = true, + ReturnSpecialDirectories = false, + RecurseSubdirectories = all + }); Array.Sort(files, StringComparer.Ordinal); return files; }