Skip to content

Commit

Permalink
issue guard#548: dir_entries now skips non-dir entries entirely
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinDKelley committed Dec 30, 2021
1 parent 0077ed2 commit 6bd5f69
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
14 changes: 8 additions & 6 deletions lib/listen/record.rb
Expand Up @@ -46,16 +46,18 @@ def file_data(rel_path)
end

def dir_entries(rel_path)
subtree = if ['', '.'].include?(rel_path.to_s)
rel_path_s = rel_path.to_s
subtree = if ['', '.'].include?(rel_path_s)
@tree
else
@tree[rel_path.to_s] ||= _auto_hash
@tree[rel_path.to_s]
@tree[rel_path_s] ||= _auto_hash
end

subtree.transform_values do |values|
# only get data for file entries
values.key?(:mtime) ? values : {}
subtree.each_with_object({}) do |(key, values), result|
# only return data for file entries
if values.respond_to?(:has_key?)
result[key] = values.has_key?(:mtime) ? values : {}
end
end
end

Expand Down
10 changes: 9 additions & 1 deletion spec/lib/listen/record_spec.rb
Expand Up @@ -66,7 +66,7 @@ def record_tree(record)
end

context 'with subdir path' do
it 'sets path by spliting dirname and basename' do
it 'sets path by splitting dirname and basename' do
record.update_file('path/file.rb', mtime: 1.1)
expect(record_tree(record)['path']).to eq('file.rb' => { mtime: 1.1 })
end
Expand Down Expand Up @@ -257,6 +257,14 @@ def record_tree(record)
end
it { should be_empty }
end

context 'with path renamed to file' do
before do
record.add_dir('path/subdir')
record.update_file('path', mtime: 1.1)
end
it { should be_empty }
end
end
end

Expand Down

0 comments on commit 6bd5f69

Please sign in to comment.