Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions lib/logstash/outputs/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,21 @@ def open(path)
@logger.info("Opening file", :path => path)

dir = File.dirname(path)
if !Dir.exist?(dir)
@logger.info("Creating directory", :directory => dir)
if @dir_mode != -1
FileUtils.mkdir_p(dir, :mode => @dir_mode)
else
FileUtils.mkdir_p(dir)
directories = dir.split(File::SEPARATOR)
dynamic_path = File::SEPARATOR

# build path one directory at a time
directories.each { |d|
dynamic_path = dynamic_path + File::SEPARATOR + d
if !Dir.exist?(dynamic_path) && !File.symlink?(dynamic_path)
@logger.info("Creating directory", :directory => dynamic_path)
if @dir_mode != -1
FileUtils.mkdir(dynamic_path, :mode => @dir_mode)
else
FileUtils.mkdir(dynamic_path)
end
end
end
}

# work around a bug opening fifos (bug JRUBY-6280)
stat = File.stat(path) rescue nil
Expand Down