diff --git a/lib/filewatch/discoverer.rb b/lib/filewatch/discoverer.rb index 1072323..beabc34 100644 --- a/lib/filewatch/discoverer.rb +++ b/lib/filewatch/discoverer.rb @@ -36,6 +36,13 @@ def discover private def can_exclude?(watched_file, new_discovery) + if watched_file.file_ignorable? + if new_discovery + logger.trace("skipping file because it is too old", :path => watched_file.path) + end + watched_file.unwatch + return true + end @exclude.each do |pattern| if watched_file.pathname.basename.fnmatch?(pattern) if new_discovery diff --git a/lib/filewatch/tail_mode/processor.rb b/lib/filewatch/tail_mode/processor.rb index 6634dc9..7f3b169 100644 --- a/lib/filewatch/tail_mode/processor.rb +++ b/lib/filewatch/tail_mode/processor.rb @@ -108,12 +108,24 @@ def process_ignored(watched_files) if watched_file.size_changed? watched_file.watch unignore(watched_file) + else + # if file comes from sincedb + if watched_file.file_ignorable? + common_detach(watched_file) + end end end break if watch.quit? end end + # taken from lib/filewatch/read_mode/processor.rb + def common_detach(watched_file) + watched_file.unwatch + add_deletable_path watched_file.path + logger.trace? && logger.trace("removing from collection", :path => watched_file.path) + end + def process_delayed_delete(watched_files) # defer the delete to one loop later to ensure that the stat really really can't find a renamed file # because a `stat` can be called right in the middle of the rotation rename cascade @@ -140,7 +152,7 @@ def process_restat_for_watched_and_active(watched_files) def process_rotation_in_progress(watched_files) logger.trace(__method__.to_s) watched_files.each do |watched_file| - next unless watched_file.rotation_in_progress? + next unless !watched_file.ignored? && watched_file.rotation_in_progress? if !watched_file.all_read? if watched_file.file_open? # rotated file but original opened file is not fully read diff --git a/lib/filewatch/watched_file.rb b/lib/filewatch/watched_file.rb index 5d6876f..153a032 100644 --- a/lib/filewatch/watched_file.rb +++ b/lib/filewatch/watched_file.rb @@ -187,7 +187,8 @@ def initial_completed end def set_accessed_at - @accessed_at = Time.now.to_f + # if files older then specific time should be ignored - take last change time as last access time + @accessed_at = if expiry_ignore_enabled? then File.mtime(@path).to_f else Time.now.to_f end end def initial?