From 49f4c30c2f382845533e3f4c2e4ae107d996e749 Mon Sep 17 00:00:00 2001 From: TAGOMORI Satoshi Date: Tue, 10 Jan 2017 12:08:20 +0900 Subject: [PATCH 1/3] ensure to provide utf-8 string values for configuration params defined as string --- lib/fluent/config/types.rb | 4 ++-- test/config/test_types.rb | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/fluent/config/types.rb b/lib/fluent/config/types.rb index 774854d390..a8739f9d15 100644 --- a/lib/fluent/config/types.rb +++ b/lib/fluent/config/types.rb @@ -64,7 +64,7 @@ def self.bool_value(str) end end - STRING_TYPE = Proc.new { |val, opts| val } + STRING_TYPE = Proc.new { |val, opts| val.to_s.encode(Encoding::UTF_8) } ENUM_TYPE = Proc.new { |val, opts| s = val.to_sym list = opts[:list] @@ -85,7 +85,7 @@ def self.bool_value(str) value else case type - when :string then value.to_s + when :string then value.to_s.encode(Encoding::UTF_8) when :integer then value.to_i when :float then value.to_f when :size then Config.size_value(value) diff --git a/test/config/test_types.rb b/test/config/test_types.rb index 6d826f4eec..350b7b32c7 100644 --- a/test/config/test_types.rb +++ b/test/config/test_types.rb @@ -66,6 +66,7 @@ class TestConfigTypes < ::Test::Unit::TestCase assert_equal 'test', Config::STRING_TYPE.call('test', {}) assert_equal '1', Config::STRING_TYPE.call('1', {}) assert_equal ' ', Config::STRING_TYPE.call(' ', {}) + assert_equal Encoding::UTF_8, Config::STRING_TYPE.call('test', {}).encoding end test 'enum' do From 85615b78e22a7c45652a672129aac4511da8c09a Mon Sep 17 00:00:00 2001 From: TAGOMORI Satoshi Date: Tue, 10 Jan 2017 12:41:39 +0900 Subject: [PATCH 2/3] permission should be read as string, and re-parsed as octet integer --- lib/fluent/plugin/buf_file.rb | 4 +++- lib/fluent/plugin/buffer/file_chunk.rb | 4 ++-- test/plugin/test_buf_file.rb | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/fluent/plugin/buf_file.rb b/lib/fluent/plugin/buf_file.rb index 3f04ae952e..3f33906676 100644 --- a/lib/fluent/plugin/buf_file.rb +++ b/lib/fluent/plugin/buf_file.rb @@ -89,7 +89,9 @@ def configure(conf) end end - unless @dir_permission + if @dir_permission + @dir_permission = @dir_permission.to_i(8) if @dir_permission.is_a?(String) + else @dir_permission = system_config.dir_permission || DIR_PERMISSION end end diff --git a/lib/fluent/plugin/buffer/file_chunk.rb b/lib/fluent/plugin/buffer/file_chunk.rb index 3232bf2d46..811e04de39 100644 --- a/lib/fluent/plugin/buffer/file_chunk.rb +++ b/lib/fluent/plugin/buffer/file_chunk.rb @@ -42,12 +42,12 @@ class FileChunk < Chunk def initialize(metadata, path, mode, perm: system_config.file_permission || FILE_PERMISSION, compress: :text) super(metadata, compress: compress) - @permission = perm + @permission = perm.is_a?(String) ? perm.to_i(8) : perm @bytesize = @size = @adding_bytes = @adding_size = 0 @meta = nil case mode - when :create then create_new_chunk(path, perm) + when :create then create_new_chunk(path, @permission) when :staged then load_existing_staged_chunk(path) when :queued then load_existing_enqueued_chunk(path) else diff --git a/test/plugin/test_buf_file.rb b/test/plugin/test_buf_file.rb index 468707e985..27f69b4017 100644 --- a/test/plugin/test_buf_file.rb +++ b/test/plugin/test_buf_file.rb @@ -141,7 +141,7 @@ def write_metadata(path, chunk_id, metadata, size, ctime, mtime) FileUtils.rm_r bufdir if File.exist?(bufdir) assert !File.exist?(bufdir) - plugin.configure(config_element('buffer', '', {'path' => bufpath, 'dir_permission' => 0700})) + plugin.configure(config_element('buffer', '', {'path' => bufpath, 'dir_permission' => '0700'})) assert !File.exist?(bufdir) plugin.start @@ -215,7 +215,7 @@ def write_metadata(path, chunk_id, metadata, size, ctime, mtime) FileUtils.rm_r bufdir if File.exist?(bufdir) assert !File.exist?(bufdir) - plugin.configure(config_element('buffer', '', {'path' => bufpath, 'file_permission' => 0600})) + plugin.configure(config_element('buffer', '', {'path' => bufpath, 'file_permission' => '0600'})) assert !File.exist?(bufdir) plugin.start From d56eaa9475471ff6cdd10ef3247043d6e2fa07d7 Mon Sep 17 00:00:00 2001 From: TAGOMORI Satoshi Date: Tue, 10 Jan 2017 12:55:35 +0900 Subject: [PATCH 3/3] Overwrite parameter definitions by subclass sections correctly. --- lib/fluent/config/configure_proxy.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fluent/config/configure_proxy.rb b/lib/fluent/config/configure_proxy.rb index 85fa8d3cd6..c77c42a062 100644 --- a/lib/fluent/config/configure_proxy.rb +++ b/lib/fluent/config/configure_proxy.rb @@ -126,7 +126,7 @@ def merge(other) # self is base class, other is subclass merged.configured_in_section = self.configured_in_section || other.configured_in_section merged.argument = other.argument || self.argument - merged.params = other.params.merge(self.params) + merged.params = self.params.merge(other.params) merged.defaults = self.defaults.merge(other.defaults) merged.sections = {} (self.sections.keys + other.sections.keys).uniq.each do |section_key|