From 9dd5ca3bdfd8a0b21aeb3e0cea8affccddf39da1 Mon Sep 17 00:00:00 2001 From: Kevin Jones Date: Mon, 6 May 2024 13:22:17 -0400 Subject: [PATCH 1/2] File System globbing support --- src/AzureSignTool/AzureSignTool.csproj | 1 + src/AzureSignTool/Program.cs | 36 ++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/AzureSignTool/AzureSignTool.csproj b/src/AzureSignTool/AzureSignTool.csproj index ff1268e..838c1b2 100644 --- a/src/AzureSignTool/AzureSignTool.csproj +++ b/src/AzureSignTool/AzureSignTool.csproj @@ -19,6 +19,7 @@ + diff --git a/src/AzureSignTool/Program.cs b/src/AzureSignTool/Program.cs index 66fb833..da53a94 100644 --- a/src/AzureSignTool/Program.cs +++ b/src/AzureSignTool/Program.cs @@ -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; @@ -89,7 +91,14 @@ internal HashSet AllFiles { if (_allFiles is null) { - _allFiles = new HashSet(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)) @@ -99,11 +108,34 @@ internal HashSet 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 collection, Matcher matcher, string item) + { + if (item.Contains('*')) + { + matcher.AddInclude(item); + } + else + { + collection.Add(item); + } + } } } From dddd746615faf7c3e386e5ea994736ce8f75d276 Mon Sep 17 00:00:00 2001 From: Kevin Jones Date: Mon, 6 May 2024 13:38:15 -0400 Subject: [PATCH 2/2] Add a comment --- src/AzureSignTool/Program.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/AzureSignTool/Program.cs b/src/AzureSignTool/Program.cs index da53a94..193ef92 100644 --- a/src/AzureSignTool/Program.cs +++ b/src/AzureSignTool/Program.cs @@ -127,6 +127,8 @@ internal HashSet AllFiles static void Add(HashSet 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);