Skip to content

Commit

Permalink
Create pos file directory if it doesn't exist
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Malcontenti-Wilson <[email protected]>
  • Loading branch information
adammw committed Dec 5, 2018
1 parent 3dabdc5 commit e568e23
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/fluent/plugin/in_tail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ def start
super

if @pos_file
pos_file_dir = File.dirname(@pos_file)
FileUtils.mkdir_p(pos_file_dir) unless Dir.exist?(pos_file_dir)
@pf_file = File.open(@pos_file, File::RDWR|File::CREAT|File::BINARY, @file_perm)
@pf_file.sync = true
@pf = PositionFile.parse(@pf_file)
Expand Down Expand Up @@ -946,7 +948,7 @@ def initialize(file, file_mutex, seek, pos, inode)
@file = file
@file_mutex = file_mutex
@seek = seek
@pos = pos
@pos = pos
@inode = inode
end

Expand Down
19 changes: 19 additions & 0 deletions test/plugin/test_in_tail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,25 @@ def count_timer_object
end
end

def test_pos_file_dir_creation
config = config_element("", "", {
"tag" => "tail",
"path" => "#{TMP_DIR}/*.txt",
"format" => "none",
"pos_file" => "#{TMP_DIR}/pos/tail.pos",
"read_from_head" => true,
"refresh_interval" => 1
})
d = create_driver(config, false)
d.run(expect_emits: 1, shutdown: false) do
File.open("#{TMP_DIR}/tail.txt", "ab") { |f| f.puts "test3\n" }
end
assert_path_exist("#{TMP_DIR}/pos/tail.pos")
cleanup_directory(TMP_DIR)

d.instance_shutdown
end

def test_z_refresh_watchers
plugin = create_driver(EX_CONFIG, false).instance
sio = StringIO.new
Expand Down

0 comments on commit e568e23

Please sign in to comment.