From 59da953511c3f8acad58e600b0758d2b2f304100 Mon Sep 17 00:00:00 2001 From: Rubem Nakamura Date: Fri, 13 Jun 2014 09:47:28 -0300 Subject: [PATCH 1/2] fix the listen watcher listening directories with a path that starts with the same substring than the root path --- lib/spring/watcher/listen.rb | 4 ++-- test/unit/watcher_test.rb | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/spring/watcher/listen.rb b/lib/spring/watcher/listen.rb index bd5aae50..6bc7c939 100644 --- a/lib/spring/watcher/listen.rb +++ b/lib/spring/watcher/listen.rb @@ -43,8 +43,8 @@ def changed(modified, added, removed) def base_directories ([root] + - files.reject { |f| f.start_with? root }.map { |f| File.expand_path("#{f}/..") } + - directories.reject { |d| d.start_with? root } + files.reject { |f| f.start_with? "#{root}/" }.map { |f| File.expand_path("#{f}/..") } + + directories.reject { |d| d.start_with? "#{root}/" } ).uniq end end diff --git a/test/unit/watcher_test.rb b/test/unit/watcher_test.rb index 93ede27d..e7f12b24 100644 --- a/test/unit/watcher_test.rb +++ b/test/unit/watcher_test.rb @@ -184,6 +184,27 @@ def watcher_class FileUtils.rmdir other_dir_2 end end + + test "directories with same subpath" do + begin + other_dir_1 = File.realpath(Dir.mktmpdir) + # same subpath as other_dir_1 but with _other appended + other_dir_2 = "#{other_dir_1}_other" + FileUtils::mkdir_p(other_dir_2) + File.write("#{other_dir_1}/foo", "foo") + File.write("#{other_dir_2}/foo", "foo") + File.write("#{dir}/foo", "foo") + + watcher.add "#{other_dir_1}/foo" + watcher.add other_dir_2 + watcher.add "#{dir}/foo" + + assert_equal [dir, other_dir_1, other_dir_2].sort, watcher.base_directories.sort + ensure + FileUtils.rmdir other_dir_1 + FileUtils.rmdir other_dir_2 + end + end end class PollingWatcherTest < ActiveSupport::TestCase From ccf0369ea2ca9faddac29003a6411c8e94273fa8 Mon Sep 17 00:00:00 2001 From: Rubem Nakamura Date: Fri, 13 Jun 2014 10:10:48 -0300 Subject: [PATCH 2/2] fixup --- test/unit/watcher_test.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/unit/watcher_test.rb b/test/unit/watcher_test.rb index e7f12b24..448041cd 100644 --- a/test/unit/watcher_test.rb +++ b/test/unit/watcher_test.rb @@ -185,11 +185,12 @@ def watcher_class end end - test "directories with same subpath" do + test "root directories with a root subpath directory" do begin - other_dir_1 = File.realpath(Dir.mktmpdir) - # same subpath as other_dir_1 but with _other appended - other_dir_2 = "#{other_dir_1}_other" + other_dir_1 = "#{dir}_other" + other_dir_2 = "#{dir}_core" + # same subpath as dir but with _other or _core appended + FileUtils::mkdir_p(other_dir_1) FileUtils::mkdir_p(other_dir_2) File.write("#{other_dir_1}/foo", "foo") File.write("#{other_dir_2}/foo", "foo") @@ -197,7 +198,6 @@ def watcher_class watcher.add "#{other_dir_1}/foo" watcher.add other_dir_2 - watcher.add "#{dir}/foo" assert_equal [dir, other_dir_1, other_dir_2].sort, watcher.base_directories.sort ensure