# File lib/fluent/plugin/buf_file.rb, line 26 def initialize(key, path, unique_id, mode="a+", symlink_path = nil) super(key) @path = path @unique_id = unique_id @file = File.open(@path, mode, DEFAULT_FILE_PERMISSION) @file.sync = true @size = @file.stat.size FileUtils.ln_sf(@path, symlink_path) if symlink_path end
# File lib/fluent/plugin/buf_file.rb, line 38 def <<(data) @file.write(data) @size += data.bytesize end
# File lib/fluent/plugin/buf_file.rb, line 51 def close stat = @file.stat @file.close if stat.size == 0 File.unlink(@path) end end
# File lib/fluent/plugin/buf_file.rb, line 47 def empty? @size == 0 end
# File lib/fluent/plugin/buf_file.rb, line 74 def mv(path) File.rename(@path, path) @path = path end
# File lib/fluent/plugin/buf_file.rb, line 69 def open(&block) @file.pos = 0 yield @file end
# File lib/fluent/plugin/buf_file.rb, line 59 def purge @file.close File.unlink(@path) rescue nil # TODO rescue? end
# File lib/fluent/plugin/buf_file.rb, line 64 def read @file.pos = 0 @file.read end
# File lib/fluent/plugin/buf_file.rb, line 43 def size @size end