Skip to content

Commit 59da953

Browse files
committed
fix the listen watcher listening directories with a path that starts with the same substring than the root path
1 parent 38b1ce3 commit 59da953

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

lib/spring/watcher/listen.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ def changed(modified, added, removed)
4343

4444
def base_directories
4545
([root] +
46-
files.reject { |f| f.start_with? root }.map { |f| File.expand_path("#{f}/..") } +
47-
directories.reject { |d| d.start_with? root }
46+
files.reject { |f| f.start_with? "#{root}/" }.map { |f| File.expand_path("#{f}/..") } +
47+
directories.reject { |d| d.start_with? "#{root}/" }
4848
).uniq
4949
end
5050
end

test/unit/watcher_test.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,27 @@ def watcher_class
184184
FileUtils.rmdir other_dir_2
185185
end
186186
end
187+
188+
test "directories with same subpath" do
189+
begin
190+
other_dir_1 = File.realpath(Dir.mktmpdir)
191+
# same subpath as other_dir_1 but with _other appended
192+
other_dir_2 = "#{other_dir_1}_other"
193+
FileUtils::mkdir_p(other_dir_2)
194+
File.write("#{other_dir_1}/foo", "foo")
195+
File.write("#{other_dir_2}/foo", "foo")
196+
File.write("#{dir}/foo", "foo")
197+
198+
watcher.add "#{other_dir_1}/foo"
199+
watcher.add other_dir_2
200+
watcher.add "#{dir}/foo"
201+
202+
assert_equal [dir, other_dir_1, other_dir_2].sort, watcher.base_directories.sort
203+
ensure
204+
FileUtils.rmdir other_dir_1
205+
FileUtils.rmdir other_dir_2
206+
end
207+
end
187208
end
188209

189210
class PollingWatcherTest < ActiveSupport::TestCase

0 commit comments

Comments
 (0)