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

fix: Avoid scanning and building entries for silenced directories #542

Merged
merged 1 commit into from Aug 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/listen/adapter/base.rb
Expand Up @@ -51,7 +51,7 @@ def configure
# TODO: separate config per directory (some day maybe)
change_config = Change::Config.new(config.queue, config.silencer)
config.directories.each do |dir|
record = Record.new(dir)
record = Record.new(dir, config.silencer)
snapshot = Change.new(change_config, record)
@snapshots[dir] = snapshot
end
Expand Down
5 changes: 4 additions & 1 deletion lib/listen/record.rb
Expand Up @@ -11,9 +11,10 @@ class Record

attr_reader :root

def initialize(directory)
def initialize(directory, silencer)
@tree = _auto_hash
@root = directory.to_s
@silencer = silencer
end

def add_dir(rel_path)
Expand Down Expand Up @@ -98,6 +99,8 @@ def _fast_unset_path(dirname, basename)

def _fast_build_dir(remaining, symlink_detector)
entry = remaining.pop
return if @silencer.silenced?(entry.record_dir_key, :dir)

children = entry.children # NOTE: children() implicitly tests if dir
symlink_detector.verify_unwatched!(entry)
children.each { |child| remaining << child }
Expand Down
7 changes: 5 additions & 2 deletions spec/lib/listen/record_spec.rb
Expand Up @@ -2,7 +2,8 @@

RSpec.describe Listen::Record do
let(:dir) { instance_double(Pathname, to_s: '/dir') }
let(:record) { Listen::Record.new(dir) }
let(:silencer) { Listen::Silencer.new }
let(:record) { Listen::Record.new(dir, silencer) }

def dir_entries_for(hash)
hash.each do |dir, entries|
Expand Down Expand Up @@ -308,9 +309,11 @@ def record_tree(record)

context 'with subdir containing files' do
before do
real_directory('/dir' => %w[dir1 dir2])
real_directory('/dir' => %w[dir1 dir2 .git])
real_directory('/dir/.git' => %w[FETCH_HEAD])
real_directory('/dir/dir1' => %w[foo])
real_directory('/dir/dir1/foo' => %w[bar])
lstat(file('/dir/.git/FETCH_HEAD'))
lstat(file('/dir/dir1/foo/bar'))
real_directory('/dir/dir2' => [])
end
Expand Down