Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completely ignore files older then 'ignore_older' setting #324

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/filewatch/discoverer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ def discover
private

def can_exclude?(watched_file, new_discovery)
if watched_file.file_ignorable?
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If file should be ignored - we should not include it in list of watched files at all

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
Expand Down
14 changes: 13 additions & 1 deletion lib/filewatch/tail_mode/processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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?
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignored files should not be monitored at all

if !watched_file.all_read?
if watched_file.file_open?
# rotated file but original opened file is not fully read
Expand Down
3 changes: 2 additions & 1 deletion lib/filewatch/watched_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down