Skip to content

Commit 89bff9f

Browse files
authored
File system globbing support (#247)
2 parents bc05080 + dddd746 commit 89bff9f

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

src/AzureSignTool/AzureSignTool.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<PackageReference Include="Azure.Identity" Version="1.11.2" />
2020
<PackageReference Include="Azure.Security.KeyVault.Certificates" Version="4.6.0" />
2121
<PackageReference Include="Azure.Security.KeyVault.Keys" Version="4.6.0" />
22+
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="8.0.0" />
2223
<PackageReference Include="XenoAtom.CommandLine" Version="1.0.0" />
2324
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
2425
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />

src/AzureSignTool/Program.cs

+36-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
using System.Threading;
99
using System.Threading.Tasks;
1010
using AzureSign.Core;
11+
using Microsoft.Extensions.FileSystemGlobbing;
12+
using Microsoft.Extensions.FileSystemGlobbing.Abstractions;
1113
using Microsoft.Extensions.Logging;
1214
using Microsoft.Extensions.Logging.Console;
1315
using RSAKeyVaultProvider;
@@ -89,7 +91,14 @@ internal HashSet<string> AllFiles
8991
{
9092
if (_allFiles is null)
9193
{
92-
_allFiles = new HashSet<string>(Files);
94+
_allFiles = [];
95+
Matcher matcher = new();
96+
97+
foreach (string file in Files)
98+
{
99+
Add(_allFiles, matcher, file);
100+
}
101+
93102
if (!string.IsNullOrWhiteSpace(InputFileList))
94103
{
95104
foreach(string line in File.ReadLines(InputFileList))
@@ -99,11 +108,36 @@ internal HashSet<string> AllFiles
99108
continue;
100109
}
101110

102-
_allFiles.Add(line);
111+
Add(_allFiles, matcher, line);
112+
}
113+
}
114+
115+
PatternMatchingResult results = matcher.Execute(new DirectoryInfoWrapper(new DirectoryInfo(".")));
116+
117+
if (results.HasMatches)
118+
{
119+
foreach (var result in results.Files)
120+
{
121+
_allFiles.Add(result.Path);
103122
}
104123
}
105124
}
125+
106126
return _allFiles;
127+
128+
static void Add(HashSet<string> collection, Matcher matcher, string item)
129+
{
130+
// We require explicit glob pattern wildcards in order to treat it as a glob. e.g.
131+
// dir/ will not be treated as a directory. It must be explicitly dir/*.exe or dir/**/*.exe, for example.
132+
if (item.Contains('*'))
133+
{
134+
matcher.AddInclude(item);
135+
}
136+
else
137+
{
138+
collection.Add(item);
139+
}
140+
}
107141
}
108142
}
109143

0 commit comments

Comments
 (0)