Skip to content

Commit

Permalink
Merge pull request #2353 from fluent/create-dir-for-symlink
Browse files Browse the repository at this point in the history
out_file: Create directory for symlink. fix #2346
  • Loading branch information
repeatedly authored Mar 29, 2019
2 parents 6172d5c + 5188c19 commit 3f37357
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion lib/fluent/plugin/out_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class FileOutput < Output
config_set_default :timekey, DEFAULT_TIMEKEY
end

attr_reader :dir_perm
attr_accessor :last_written_path # for tests

module SymlinkBufferMixin
Expand All @@ -87,7 +88,9 @@ def generate_chunk(metadata)
# These chunks will be enqueued immediately, and will be flushed soon.
latest_metadata = metadata_list.select{|m| m.timekey }.sort_by(&:timekey).last
if chunk.metadata == latest_metadata
FileUtils.ln_sf(chunk.path, @_output_plugin_for_symlink.extract_placeholders(@_symlink_path, chunk))
sym_path = @_output_plugin_for_symlink.extract_placeholders(@_symlink_path, chunk)
FileUtils.mkdir_p(File.dirname(sym_path), mode: @_output_plugin_for_symlink.dir_perm)
FileUtils.ln_sf(chunk.path, sym_path)
end
chunk
end
Expand Down
4 changes: 2 additions & 2 deletions test/plugin/test_out_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -684,11 +684,11 @@ def parse_system(text)
omit "Windows doesn't support symlink" if Fluent.windows?
conf = %[
path #{TMP_DIR}/${tag}/out_file_test
symlink_path #{SYMLINK_PATH}-${tag}
symlink_path #{SYMLINK_PATH}/foo/${tag}
<buffer tag,time>
</buffer>
]
symlink_path = "#{SYMLINK_PATH}-tag"
symlink_path = "#{SYMLINK_PATH}/foo/tag"

d = create_driver(conf)
begin
Expand Down

0 comments on commit 3f37357

Please sign in to comment.