From 22537194912964b0084803d27f91a6a819943c15 Mon Sep 17 00:00:00 2001 From: David Wood Date: Sun, 31 Jan 2016 06:08:01 +0000 Subject: [PATCH] in_tail: avoid unnecessary open()s --- lib/fluent/plugin/in_tail.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/fluent/plugin/in_tail.rb b/lib/fluent/plugin/in_tail.rb index 68c3bc476f..ae46483366 100644 --- a/lib/fluent/plugin/in_tail.rb +++ b/lib/fluent/plugin/in_tail.rb @@ -586,8 +586,7 @@ def initialize(path, log, &on_rotate) def on_notify begin - io = FileWrapper.open(@path) - stat = io.stat + stat = FileWrapper.stat(@path) inode = stat.ino fsize = stat.size rescue Errno::ENOENT @@ -599,13 +598,14 @@ def on_notify begin if @inode != inode || fsize < @fsize # rotated or truncated + begin + io = FileWrapper.open(@path) + rescue Errno::ENOENT + end @on_rotate.call(io) - io = nil end @inode = inode @fsize = fsize - ensure - io.close if io end rescue