Skip to content

Commit

Permalink
Always use fnmatch for target wildcard name match
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
seanmil committed May 21, 2024
1 parent b748ae6 commit 47edb66
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions lib/bolt/inventory/inventory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 47edb66

Please sign in to comment.