From 0f8bdd0be0045557f42f98255c5ce9d89f384916 Mon Sep 17 00:00:00 2001 From: Holger Just Date: Tue, 17 Sep 2019 19:02:30 +0200 Subject: [PATCH] Open output files with File::SHARE_DELETE to allow logrotates on Windows --- lib/rackstash/adapter/file.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/rackstash/adapter/file.rb b/lib/rackstash/adapter/file.rb index 2fb798a..6d35496 100644 --- a/lib/rackstash/adapter/file.rb +++ b/lib/rackstash/adapter/file.rb @@ -228,11 +228,12 @@ module Rackstash dirname = ::File.dirname(path) FileUtils.mkdir_p(dirname) unless ::File.exist?(dirname) - file = ::File.new( - path, - ::File::WRONLY | ::File::APPEND | ::File::CREAT - ) - file.binmode + mode = ::File::WRONLY | ::File::APPEND | ::File::CREAT + # Allow external processes to delete the log file on Windows. + # This is available since Ruby 2.3.0. + mode |= ::File::SHARE_DELETE if defined?(::File::SHARE_DELETE) + + file = ::File.new(path, mode: mode, binmode: true) file.sync = true @path = path