From 746ad79fb14487cee8cdd58f60016267d5f147f3 Mon Sep 17 00:00:00 2001 From: joshua stein Date: Thu, 22 Apr 2021 21:34:09 -0500 Subject: [PATCH] BSD: Don't send ignored paths to kqueue kqueue requires a file handle for every file and directory being watched so using Listen in a directory with .git or vendor/bundle quickly eats up all available file handles. Since these paths are being ignored by the silencer anyway, prevent watching these paths to conserve file handles. --- lib/listen/adapter/bsd.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/listen/adapter/bsd.rb b/lib/listen/adapter/bsd.rb index 04a6958d..8d458ebc 100644 --- a/lib/listen/adapter/bsd.rb +++ b/lib/listen/adapter/bsd.rb @@ -45,7 +45,11 @@ def _configure(directory, &callback) @callback = callback # use Record to make a snapshot of dir, so we # can detect new files - _find(directory.to_s) { |path| _watch_file(path, @worker) } + _find(directory.to_s) { |path| + unless @config.silencer.silenced?(Pathname.new(path).relative_path_from(directory), FileTest.directory?(path) ? :dir : :file) + _watch_file(path, @worker) + end + } end def _run