Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File system globbing support #247

Merged
merged 2 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/AzureSignTool/AzureSignTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<PackageReference Include="Azure.Identity" Version="1.11.2" />
<PackageReference Include="Azure.Security.KeyVault.Certificates" Version="4.6.0" />
<PackageReference Include="Azure.Security.KeyVault.Keys" Version="4.6.0" />
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="8.0.0" />
<PackageReference Include="XenoAtom.CommandLine" Version="1.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
Expand Down
38 changes: 36 additions & 2 deletions src/AzureSignTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using System.Threading;
using System.Threading.Tasks;
using AzureSign.Core;
using Microsoft.Extensions.FileSystemGlobbing;
using Microsoft.Extensions.FileSystemGlobbing.Abstractions;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Console;
using RSAKeyVaultProvider;
Expand Down Expand Up @@ -89,7 +91,14 @@ internal HashSet<string> AllFiles
{
if (_allFiles is null)
{
_allFiles = new HashSet<string>(Files);
_allFiles = [];
Matcher matcher = new();

foreach (string file in Files)
{
Add(_allFiles, matcher, file);
}

if (!string.IsNullOrWhiteSpace(InputFileList))
{
foreach(string line in File.ReadLines(InputFileList))
Expand All @@ -99,11 +108,36 @@ internal HashSet<string> AllFiles
continue;
}

_allFiles.Add(line);
Add(_allFiles, matcher, line);
}
}

PatternMatchingResult results = matcher.Execute(new DirectoryInfoWrapper(new DirectoryInfo(".")));

if (results.HasMatches)
{
foreach (var result in results.Files)
{
_allFiles.Add(result.Path);
}
}
}

return _allFiles;

static void Add(HashSet<string> collection, Matcher matcher, string item)
{
// We require explicit glob pattern wildcards in order to treat it as a glob. e.g.
// dir/ will not be treated as a directory. It must be explicitly dir/*.exe or dir/**/*.exe, for example.
if (item.Contains('*'))
{
matcher.AddInclude(item);
}
else
{
collection.Add(item);
}
}
}
}

Expand Down