From 5040fab24baf6fbda3c65504d15d44cf9ce267ba Mon Sep 17 00:00:00 2001 From: "reddy.heo" Date: Fri, 17 Sep 2021 09:54:23 +0900 Subject: [PATCH] Fixed issue of re-reading rotated files --- lib/filewatch/sincedb_collection.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/filewatch/sincedb_collection.rb b/lib/filewatch/sincedb_collection.rb index 3694cef..8319058 100644 --- a/lib/filewatch/sincedb_collection.rb +++ b/lib/filewatch/sincedb_collection.rb @@ -85,6 +85,12 @@ def associate(watched_file) logger.trace? && logger.trace("associate: inode and path matched", :filename => watched_file.filename) return true end + if watched_file.path.start_with?(sincedb_value.path_in_sincedb) + # If the path starts with sincedb path, it is considered a rotated file. + handle_association(sincedb_value, watched_file) + logger.trace? && logger.trace("associate: matched but start with same path", :filename => watched_file.filename) + return true + end # the path on disk is different from discovered unassociated path but they have the same key (inode) # treat as a new file, a new value will be added when the file is opened sincedb_value.clear_watched_file