From 47edb66dae635bfab7de94164e83a6d2487129d8 Mon Sep 17 00:00:00 2001 From: Sean Millichamp Date: Tue, 2 Apr 2024 16:33:25 +0000 Subject: [PATCH] Always use fnmatch for target wildcard name match When resolving a large number of targets from a plan the match_wildcard? regex is compiled on the fly possibly hundreds or thousands (for a large inventory) of times per target name resolution. Switching to File.fnmatch provides a significant speed increase and seems to more accurately reflect the functionality stated in the Bolt documentation with regards to target matching. !feature * **Enable basic glob matching of target strings** Previously, only the '*' wildcard character would match when targets were resolved from areas other than the CLI (such as from within a Plan). With this change wildcard matching is switched to use Ruby's fnmatch with basic glob matching enabled. In addition to providing more wildcard matching options, it also provides a significant performance improvement over the prior implementation. --- lib/bolt/inventory/inventory.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/bolt/inventory/inventory.rb b/lib/bolt/inventory/inventory.rb index 82a688bc7b..54d67b387c 100644 --- a/lib/bolt/inventory/inventory.rb +++ b/lib/bolt/inventory/inventory.rb @@ -119,8 +119,7 @@ def match_wildcard?(wildcard, target_name, ext_glob: false) if ext_glob File.fnmatch(wildcard, target_name, File::FNM_CASEFOLD | File::FNM_EXTGLOB) else - regexp = Regexp.new("^#{Regexp.escape(wildcard).gsub('\*', '.*?')}$", Regexp::IGNORECASE) - target_name =~ regexp + File.fnmatch(wildcard, target_name, File::FNM_CASEFOLD) end end