Skip to content

Commit

Permalink
Don't return incorrect files when there's a file whose name matches a…
Browse files Browse the repository at this point in the history
… dir
  • Loading branch information
ghiculescu committed Dec 12, 2020
1 parent 573aaf0 commit 8897b31
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/listen/record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ def _sub_tree(rel_path)
if path == rel_path
result.merge!(meta)
else
sub_path = path.sub(%r{\A#{rel_path}/?}, '')
parts = path.split("/")
next unless parts.include?(rel_path)

sub_path = (parts - [rel_path]).join("/")
result[sub_path] = meta
end
end
Expand Down
20 changes: 20 additions & 0 deletions spec/lib/listen/record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,26 @@ def record_tree(record)
end
end

context 'when there is a file with the same name as a dir' do
subject { record.dir_entries('cypress') }

before do
record.update_file('cypress.json', mtime: 1.1)
record.update_file('cypress/README.md', mtime: 1.2)
end
it { should eq('README.md' => { mtime: 1.2 }) }
end

context 'when there is a file with a similar name to a dir' do
subject { record.dir_entries('app') }

before do
record.update_file('appspec.yml', mtime: 1.1)
record.update_file('app/README.md', mtime: 1.2)
end
it { should eq('README.md' => { mtime: 1.2 }) }
end

context 'in subdir /path' do
subject { record.dir_entries('path') }

Expand Down

0 comments on commit 8897b31

Please sign in to comment.