Skip to content

Commit

Permalink
Use defined constant for consistency
Browse files Browse the repository at this point in the history
Signed-off-by: Kentaro Hayashi <[email protected]>
  • Loading branch information
kenhys committed Oct 5, 2021
1 parent 6a3b221 commit eb4c3f9
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions lib/fluent/plugin/buf_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions lib/fluent/plugin/output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.
#

require 'fluent/env'
require 'fluent/error'
require 'fluent/plugin/base'
require 'fluent/plugin/buffer'
Expand Down Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions lib/fluent/plugin/storage_local.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.
#

require 'fluent/env'
require 'fluent/plugin'
require 'fluent/plugin/storage'

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/fluent/plugin_id.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#

require 'set'
require 'fluent/env'
require 'fluent/variable_store'

module Fluent
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/fluent/supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit eb4c3f9

Please sign in to comment.