Skip to content

Commit

Permalink
Fixed directory scanning in case one directory is inaccessible.
Browse files Browse the repository at this point in the history
  • Loading branch information
ernstc committed Jul 21, 2023
1 parent 8208811 commit 8e7a56e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
14 changes: 12 additions & 2 deletions VisualStudioSolutionSecrets.Tests/Commands/Command.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 12 additions & 2 deletions VisualStudioSolutionSecrets/Commands/Abstractions/CommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down

0 comments on commit 8e7a56e

Please sign in to comment.