From c4cf3b9d1fe5a90fce8bdea325f36814def29d90 Mon Sep 17 00:00:00 2001 From: Joao Duarte Date: Fri, 3 Jul 2015 17:53:11 +0100 Subject: [PATCH] improve sincedb_path argument handling and documentation Fixes #59 --- lib/logstash/inputs/file.rb | 11 ++++++++--- spec/inputs/file_spec.rb | 11 +++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/logstash/inputs/file.rb b/lib/logstash/inputs/file.rb index a636004..3a2245c 100644 --- a/lib/logstash/inputs/file.rb +++ b/lib/logstash/inputs/file.rb @@ -46,9 +46,10 @@ class LogStash::Inputs::File < LogStash::Inputs::Base # How often (in seconds) we expand globs to discover new files to watch. config :discover_interval, :validate => :number, :default => 15 - # Where to write the sincedb database (keeps track of the current - # position of monitored log files). The default will write - # sincedb files to some path matching `$HOME/.sincedb*` + # Path of the sincedb database file (keeps track of the current + # position of monitored log files) that will be written to disk. + # The default will write sincedb files to some path matching `$HOME/.sincedb*` + # NOTE: it must be a file path and not a directory path config :sincedb_path, :validate => :string # How often (in seconds) to write a since database with the current position of @@ -120,6 +121,10 @@ def register :sincedb_path => @sincedb_path, :path => @path) end + if File.directory?(@sincedb_path) + raise ArgumentError.new("sincedb_path must be a file path, not a directory. Received: \"#{@sincedb_path}\"") + end + @tail_config[:sincedb_path] = @sincedb_path if @start_position == "beginning" diff --git a/spec/inputs/file_spec.rb b/spec/inputs/file_spec.rb index 508347a..17d32a3 100644 --- a/spec/inputs/file_spec.rb +++ b/spec/inputs/file_spec.rb @@ -3,6 +3,7 @@ require "logstash/devutils/rspec/spec_helper" require "tempfile" require "stud/temporary" +require "logstash/inputs/file" describe "inputs/file" do @@ -165,4 +166,14 @@ insist { events[1]["path"] } == "#{tmpfile_path}" insist { events[1]["host"] } == "#{Socket.gethostname.force_encoding(Encoding::UTF_8)}" end + + context "sincedb_path is an existing directory" do + it "should raise exception" do + tmpfile_path = Stud::Temporary.pathname + Stud::Temporary.directory do |sincedb_path| + plugin = LogStash::Inputs::File.new("path" => tmpfile_path, "sincedb_path" => sincedb_path) + expect { plugin.register }.to raise_error(ArgumentError) + end + end + end end