From 5f02c39c24453f09f0a09d022e3ba7ec6ece1ffb Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Thu, 15 Feb 2024 12:35:25 +0900 Subject: [PATCH] in_tail: Preserve backward compatiblity for glob This is because square brackets are permitted to use filename in macOS and Windows. So, we need to take care of. Signed-off-by: Hiroshi Hatake --- lib/fluent/plugin/in_tail.rb | 8 +++++++- test/plugin/test_in_tail.rb | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/fluent/plugin/in_tail.rb b/lib/fluent/plugin/in_tail.rb index c9138ed84b..a494b1befb 100644 --- a/lib/fluent/plugin/in_tail.rb +++ b/lib/fluent/plugin/in_tail.rb @@ -64,6 +64,8 @@ def initialize config_param :path, :string desc 'path delimiter used for spliting path config' config_param :path_delimiter, :string, default: ',' + desc 'Use extended glob patterns. Adding a capability to handle [] and ?.' + config_param :use_extended_glob, :bool, default: false desc 'The tag of the event.' config_param :tag, :string desc 'The paths to exclude the files from watcher list.' @@ -286,7 +288,11 @@ def have_read_capability? # Curly braces is not supported for now because the default delimiter of path is ",". # This should be collided for wildcard pattern for curly braces. def use_glob?(path) - path.include?('*') || path.include?('?') || /\[.*\]/.match(path) + if @use_extended_glob + path.include?('*') || path.include?('?') || /\[.*\]/.match(path) + else + path.include?('*') + end end def expand_paths diff --git a/test/plugin/test_in_tail.rb b/test/plugin/test_in_tail.rb index d6cfb36902..5e00df0f17 100644 --- a/test/plugin/test_in_tail.rb +++ b/test/plugin/test_in_tail.rb @@ -1552,6 +1552,7 @@ def test_expand_paths_with_use_glob_p "pos_file" => "#{@tmp_dir}/tail.pos", "read_from_head" => true, "refresh_interval" => 30, + "use_extended_glob" => true, "rotate_wait" => "#{EX_ROTATE_WAIT}s", "follow_inodes" => "#{EX_FOLLOW_INODES}", }) @@ -1568,6 +1569,7 @@ def ex_config_with_brackets "pos_file" => "#{@tmp_dir}/tail.pos", "read_from_head" => true, "refresh_interval" => 30, + "use_extended_glob" => true, "rotate_wait" => "#{EX_ROTATE_WAIT}s", "follow_inodes" => "#{EX_FOLLOW_INODES}", })