Skip to content

Commit

Permalink
Merge pull request #2836 from ganmacs/collect-all-permission-const
Browse files Browse the repository at this point in the history
Collect all dir and file permission into one place
  • Loading branch information
ganmacs committed Feb 26, 2020
2 parents fb45d29 + bb89be7 commit e130ad4
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 32 deletions.
2 changes: 2 additions & 0 deletions lib/fluent/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ module Fluent
DEFAULT_SOCKET_PATH = ENV['FLUENT_SOCKET'] || '/var/run/fluent/fluent.sock'
DEFAULT_BACKUP_DIR = ENV['FLUENT_BACKUP_DIR'] || '/tmp/fluent'
DEFAULT_OJ_OPTIONS = {bigdecimal_load: :float, mode: :compat, use_to_json: true}
DEFAULT_DIR_PERMISSION = 0755
DEFAULT_FILE_PERMISSION = 0644

def self.windows?
ServerEngine.windows?
Expand Down
4 changes: 1 addition & 3 deletions lib/fluent/plugin/buf_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ class FileBuffer < Fluent::Plugin::Buffer
DEFAULT_CHUNK_LIMIT_SIZE = 256 * 1024 * 1024 # 256MB
DEFAULT_TOTAL_LIMIT_SIZE = 64 * 1024 * 1024 * 1024 # 64GB, same with v0.12 (TimeSlicedOutput + buf_file)

DIR_PERMISSION = 0755

desc 'The path where buffer chunks are stored.'
config_param :path, :string, default: nil
desc 'The suffix of buffer chunks'
Expand Down Expand Up @@ -108,7 +106,7 @@ def configure(conf)
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
@dir_permission = system_config.dir_permission || Fluent::DEFAULT_DIR_PERMISSION
end
end

Expand Down
3 changes: 1 addition & 2 deletions lib/fluent/plugin/buf_file_single.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class FileSingleBuffer < Fluent::Plugin::Buffer
DEFAULT_TOTAL_LIMIT_SIZE = 64 * 1024 * 1024 * 1024 # 64GB

PATH_SUFFIX = ".#{Fluent::Plugin::Buffer::FileSingleChunk::PATH_EXT}"
DIR_PERMISSION = 0755

desc 'The path where buffer chunks are stored.'
config_param :path, :string, default: nil
Expand Down Expand Up @@ -128,7 +127,7 @@ def configure(conf)
@dir_permission = if @dir_permission
@dir_permission.to_i(8)
else
system_config.dir_permission || DIR_PERMISSION
system_config.dir_permission || Fluent::DEFAULT_DIR_PERMISSION
end
end

Expand Down
4 changes: 1 addition & 3 deletions lib/fluent/plugin/buffer/file_chunk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,11 @@ class FileChunkError < StandardError; end
# path_prefix: path prefix string, ended with '.'
# path_suffix: path suffix string, like '.log' (or any other user specified)

FILE_PERMISSION = 0644

attr_reader :path, :permission

def initialize(metadata, path, mode, perm: nil, compress: :text)
super(metadata, compress: compress)
perm ||= FILE_PERMISSION
perm ||= Fluent::DEFAULT_FILE_PERMISSION
@permission = perm.is_a?(String) ? perm.to_i(8) : perm
@bytesize = @size = @adding_bytes = @adding_size = 0
@meta = nil
Expand Down
5 changes: 2 additions & 3 deletions lib/fluent/plugin/buffer/file_single_chunk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@ class FileChunkError < StandardError; end
PATH_EXT = 'buf'
PATH_SUFFIX = ".#{PATH_EXT}"
PATH_REGEXP = /\.(b|q)([0-9a-f]+)\.#{PATH_EXT}*\Z/n # //n switch means explicit 'ASCII-8BIT' pattern
FILE_PERMISSION = 0644

attr_reader :path, :permission

def initialize(metadata, path, mode, key, perm: FILE_PERMISSION, compress: :text)
def initialize(metadata, path, mode, key, perm: Fluent::DEFAULT_FILE_PERMISSION, compress: :text)
super(metadata, compress: compress)
@key = key
perm ||= FILE_PERMISSION
perm ||= Fluent::DEFAULT_FILE_PERMISSION
@permission = perm.is_a?(String) ? perm.to_i(8) : perm
@bytesize = @size = @adding_bytes = @adding_size = 0

Expand Down
7 changes: 2 additions & 5 deletions lib/fluent/plugin/in_tail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ def to_s
end
end

FILE_PERMISSION = 0644
DIR_PERMISSION = 0755

def initialize
super
@paths = []
Expand Down Expand Up @@ -168,8 +165,8 @@ def configure(conf)
else
method(:parse_singleline)
end
@file_perm = system_config.file_permission || FILE_PERMISSION
@dir_perm = system_config.dir_permission || DIR_PERMISSION
@file_perm = system_config.file_permission || Fluent::DEFAULT_FILE_PERMISSION
@dir_perm = system_config.dir_permission || Fluent::DEFAULT_DIR_PERMISSION
# parser is already created by parser helper
@parser = parser_create(usage: parser_config['usage'] || @parser_configs.first.usage)
end
Expand Down
7 changes: 2 additions & 5 deletions lib/fluent/plugin/out_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ class FileOutput < Output
gzip: :gzip,
}

FILE_PERMISSION = 0644
DIR_PERMISSION = 0755

DEFAULT_TIMEKEY = 60 * 60 * 24

desc "The Path of the file."
Expand Down Expand Up @@ -182,8 +179,8 @@ def configure(conf)
end
end

@dir_perm = system_config.dir_permission || DIR_PERMISSION
@file_perm = system_config.file_permission || FILE_PERMISSION
@dir_perm = system_config.dir_permission || Fluent::DEFAULT_DIR_PERMISSION
@file_perm = system_config.file_permission || Fluent::DEFAULT_FILE_PERMISSION
@need_lock = system_config.workers > 1
end

Expand Down
6 changes: 2 additions & 4 deletions lib/fluent/plugin/out_secondary_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ module Fluent::Plugin
class SecondaryFileOutput < Output
Fluent::Plugin.register_output("secondary_file", self)

FILE_PERMISSION = 0644
DIR_PERMISSION = 0755
PLACEHOLDER_REGEX = /\${(tag(\[\d+\])?|[\w.@-]+)}/

desc "The directory path of the output file."
Expand Down Expand Up @@ -61,8 +59,8 @@ def configure(conf)
raise Fluent::ConfigError, "out_secondary_file: `#{@directory}` should be writable"
end

@dir_perm = system_config.dir_permission || DIR_PERMISSION
@file_perm = system_config.file_permission || FILE_PERMISSION
@dir_perm = system_config.dir_permission || Fluent::DEFAULT_DIR_PERMISSION
@file_perm = system_config.file_permission || Fluent::DEFAULT_FILE_PERMISSION
end

def multi_workers_ready?
Expand Down
4 changes: 2 additions & 2 deletions test/plugin/test_buf_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def write_metadata(path, chunk_id, metadata, size, ctime, mtime)
assert_equal m1, c1.metadata
assert c1.empty?
assert_equal :unstaged, c1.state
assert_equal Fluent::Plugin::Buffer::FileChunk::FILE_PERMISSION, c1.permission
assert_equal Fluent::DEFAULT_FILE_PERMISSION, c1.permission
assert_equal @bufpath.gsub('.*.', ".b#{Fluent::UniqueId.hex(c1.unique_id)}."), c1.path
assert{ File.stat(c1.path).mode.to_s(8).end_with?('644') }

Expand All @@ -291,7 +291,7 @@ def write_metadata(path, chunk_id, metadata, size, ctime, mtime)
assert_equal m2, c2.metadata
assert c2.empty?
assert_equal :unstaged, c2.state
assert_equal Fluent::Plugin::Buffer::FileChunk::FILE_PERMISSION, c2.permission
assert_equal Fluent::DEFAULT_FILE_PERMISSION, c2.permission
assert_equal @bufpath.gsub('.*.', ".b#{Fluent::UniqueId.hex(c2.unique_id)}."), c2.path
assert{ File.stat(c2.path).mode.to_s(8).end_with?('644') }

Expand Down
4 changes: 2 additions & 2 deletions test/plugin/test_buf_file_single.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def create_driver(conf = TAG_CONF, klass = FluentPluginFileSingleBufferTest::Dum
assert_equal m1, c1.metadata
assert c1.empty?
assert_equal :unstaged, c1.state
assert_equal Fluent::Plugin::Buffer::FileSingleChunk::FILE_PERMISSION, c1.permission
assert_equal Fluent::DEFAULT_FILE_PERMISSION, c1.permission
assert_equal File.join(@bufdir, "fsb.testing.b#{Fluent::UniqueId.hex(c1.unique_id)}.buf"), c1.path
assert{ File.stat(c1.path).mode.to_s(8).end_with?('644') }

Expand All @@ -258,7 +258,7 @@ def create_driver(conf = TAG_CONF, klass = FluentPluginFileSingleBufferTest::Dum
assert_equal m1, c1.metadata
assert c1.empty?
assert_equal :unstaged, c1.state
assert_equal Fluent::Plugin::Buffer::FileSingleChunk::FILE_PERMISSION, c1.permission
assert_equal Fluent::DEFAULT_FILE_PERMISSION, c1.permission
assert_equal File.join(@bufdir, "fsb.foo_bar.b#{Fluent::UniqueId.hex(c1.unique_id)}.buf"), c1.path

c1.purge
Expand Down
4 changes: 2 additions & 2 deletions test/plugin/test_buffer_file_chunk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ def gen_chunk_path(prefix, unique_id)
assert_equal gen_chunk_path('b', @c.unique_id), @c.path

assert File.exist?(gen_chunk_path('b', @c.unique_id))
assert{ File.stat(gen_chunk_path('b', @c.unique_id)).mode.to_s(8).end_with?(@klass.const_get('FILE_PERMISSION').to_s(8)) }
assert{ File.stat(gen_chunk_path('b', @c.unique_id)).mode.to_s(8).end_with?(Fluent::DEFAULT_FILE_PERMISSION.to_s(8)) }

assert File.exist?(gen_chunk_path('b', @c.unique_id) + '.meta')
assert{ File.stat(gen_chunk_path('b', @c.unique_id) + '.meta').mode.to_s(8).end_with?(@klass.const_get('FILE_PERMISSION').to_s(8)) }
assert{ File.stat(gen_chunk_path('b', @c.unique_id) + '.meta').mode.to_s(8).end_with?(Fluent::DEFAULT_FILE_PERMISSION.to_s(8)) }

assert_equal :unstaged, @c.state
assert @c.empty?
Expand Down
2 changes: 1 addition & 1 deletion test/plugin/test_buffer_file_single_chunk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def gen_chunk_path(prefix, unique_id)
assert_equal gen_chunk_path('b', @c.unique_id), @c.path

assert File.exist?(gen_chunk_path('b', @c.unique_id))
assert { File.stat(gen_chunk_path('b', @c.unique_id)).mode.to_s(8).end_with?(@klass.const_get('FILE_PERMISSION').to_s(8)) }
assert { File.stat(gen_chunk_path('b', @c.unique_id)).mode.to_s(8).end_with?(Fluent::DEFAULT_FILE_PERMISSION.to_s(8)) }

assert_equal :unstaged, @c.state
assert @c.empty?
Expand Down

0 comments on commit e130ad4

Please sign in to comment.