diff --git a/lib/fluent/plugin/buf_file.rb b/lib/fluent/plugin/buf_file.rb index 84a73921ca..4725f5c9fe 100644 --- a/lib/fluent/plugin/buf_file.rb +++ b/lib/fluent/plugin/buf_file.rb @@ -39,8 +39,8 @@ class FileBuffer < Fluent::Plugin::Buffer config_set_default :chunk_limit_size, DEFAULT_CHUNK_LIMIT_SIZE config_set_default :total_limit_size, DEFAULT_TOTAL_LIMIT_SIZE - config_param :file_permission, :string, default: nil # '0644' - config_param :dir_permission, :string, default: nil # '0755' + config_param :file_permission, :string, default: nil # '0644' (Fluent::DEFAULT_FILE_PERMISSION) + config_param :dir_permission, :string, default: nil # '0755' (Fluent::DEFAULT_DIR_PERMISSION) def initialize super diff --git a/lib/fluent/plugin/output.rb b/lib/fluent/plugin/output.rb index 354c6649f3..34e31ec878 100644 --- a/lib/fluent/plugin/output.rb +++ b/lib/fluent/plugin/output.rb @@ -14,6 +14,7 @@ # limitations under the License. # +require 'fluent/env' require 'fluent/error' require 'fluent/plugin/base' require 'fluent/plugin/buffer' @@ -1248,8 +1249,8 @@ def backup_chunk(chunk, using_secondary, delayed_commit) backup_dir = File.dirname(backup_file) log.warn "bad chunk is moved to #{backup_file}" - FileUtils.mkdir_p(backup_dir, mode: system_config.dir_permission || 0755) unless Dir.exist?(backup_dir) - File.open(backup_file, 'ab', system_config.file_permission || 0644) { |f| + FileUtils.mkdir_p(backup_dir, mode: system_config.dir_permission || Fluent::DEFAULT_DIR_PERMISSION) unless Dir.exist?(backup_dir) + File.open(backup_file, 'ab', system_config.file_permission || Fluent::DEFAULT_FILE_PERMISSION) { |f| chunk.write_to(f) } end diff --git a/lib/fluent/plugin/storage_local.rb b/lib/fluent/plugin/storage_local.rb index d17022fe6b..b9e159f671 100644 --- a/lib/fluent/plugin/storage_local.rb +++ b/lib/fluent/plugin/storage_local.rb @@ -14,6 +14,7 @@ # limitations under the License. # +require 'fluent/env' require 'fluent/plugin' require 'fluent/plugin/storage' @@ -25,14 +26,11 @@ module Plugin class LocalStorage < Storage Fluent::Plugin.register_storage('local', self) - DEFAULT_DIR_MODE = 0755 - DEFAULT_FILE_MODE = 0644 - config_param :path, :string, default: nil - config_param :mode, default: DEFAULT_FILE_MODE do |v| + config_param :mode, default: Fluent::DEFAULT_FILE_PERMISSION do |v| v.to_i(8) end - config_param :dir_mode, default: DEFAULT_DIR_MODE do |v| + config_param :dir_mode, default: Fluent::DEFAULT_DIR_PERMISSION do |v| v.to_i(8) end config_param :pretty_print, :bool, default: false diff --git a/lib/fluent/plugin_id.rb b/lib/fluent/plugin_id.rb index 7477327024..87b1bc7ff1 100644 --- a/lib/fluent/plugin_id.rb +++ b/lib/fluent/plugin_id.rb @@ -15,6 +15,7 @@ # require 'set' +require 'fluent/env' require 'fluent/variable_store' module Fluent @@ -76,7 +77,7 @@ def plugin_root_dir # Fluent::Plugin::Base#fluentd_worker_id dir = File.join(system_config.root_dir, "worker#{fluentd_worker_id}", plugin_id) - FileUtils.mkdir_p(dir, mode: system_config.dir_permission || 0755) unless Dir.exist?(dir) + FileUtils.mkdir_p(dir, mode: system_config.dir_permission || Fluent::DEFAULT_DIR_PERMISSION) unless Dir.exist?(dir) @_plugin_root_dir = dir.freeze dir end diff --git a/lib/fluent/supervisor.rb b/lib/fluent/supervisor.rb index 59ef6093ed..c03cde3925 100644 --- a/lib/fluent/supervisor.rb +++ b/lib/fluent/supervisor.rb @@ -544,7 +544,7 @@ def apply_options(format: nil, time_format: nil, log_dir_perm: nil, ignore_repea $log.ignore_same_log_interval = ignore_same_log_interval if ignore_same_log_interval if @path && log_dir_perm - File.chmod(log_dir_perm || 0755, File.dirname(@path)) + File.chmod(log_dir_perm || Fluent::DEFAULT_DIR_PERMISSION, File.dirname(@path)) end end @@ -651,7 +651,7 @@ def run_supervisor(dry_run: false) end else begin - FileUtils.mkdir_p(root_dir, mode: @system_config.dir_permission || 0755) + FileUtils.mkdir_p(root_dir, mode: @system_config.dir_permission || Fluent::DEFAULT_DIR_PERMISSION) rescue => e raise Fluent::InvalidRootDirectory, "failed to create root directory:#{root_dir}, #{e.inspect}" end