mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #36340 from jhawthorn/evented_file_checker_symlink
Fix EventedFileUpdateChecker through a symlink
This commit is contained in:
commit
81d1242c77
2 changed files with 43 additions and 20 deletions
|
@ -107,6 +107,7 @@ module ActiveSupport
|
||||||
|
|
||||||
private
|
private
|
||||||
def boot!
|
def boot!
|
||||||
|
normalize_dirs!
|
||||||
Listen.to(*@dtw, &method(:changed)).start
|
Listen.to(*@dtw, &method(:changed)).start
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -114,6 +115,12 @@ module ActiveSupport
|
||||||
Listen.stop
|
Listen.stop
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def normalize_dirs!
|
||||||
|
@dirs.transform_keys! do |dir|
|
||||||
|
dir.exist? ? dir.realpath : dir
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def changed(modified, added, removed)
|
def changed(modified, added, removed)
|
||||||
unless updated?
|
unless updated?
|
||||||
@updated.make_true if (modified + added + removed).any? { |f| watching?(f) }
|
@updated.make_true if (modified + added + removed).any? { |f| watching?(f) }
|
||||||
|
|
|
@ -77,32 +77,48 @@ class EventedFileUpdateCheckerTest < ActiveSupport::TestCase
|
||||||
Process.wait(pid)
|
Process.wait(pid)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "should detect changes through symlink" do
|
||||||
|
actual_dir = File.join(tmpdir, "actual")
|
||||||
|
linked_dir = File.join(tmpdir, "linked")
|
||||||
|
|
||||||
|
Dir.mkdir(actual_dir)
|
||||||
|
FileUtils.ln_s(actual_dir, linked_dir)
|
||||||
|
|
||||||
|
checker = new_checker([], linked_dir => ".rb") { }
|
||||||
|
|
||||||
|
assert_not_predicate checker, :updated?
|
||||||
|
|
||||||
|
FileUtils.touch(File.join(actual_dir, "a.rb"))
|
||||||
|
wait
|
||||||
|
|
||||||
|
assert_predicate checker, :updated?
|
||||||
|
assert checker.execute_if_updated
|
||||||
|
end
|
||||||
|
|
||||||
test "updated should become true when nonexistent directory is added later" do
|
test "updated should become true when nonexistent directory is added later" do
|
||||||
Dir.mktmpdir do |dir|
|
watched_dir = File.join(tmpdir, "app")
|
||||||
watched_dir = File.join(dir, "app")
|
unwatched_dir = File.join(tmpdir, "node_modules")
|
||||||
unwatched_dir = File.join(dir, "node_modules")
|
not_exist_watched_dir = File.join(tmpdir, "test")
|
||||||
not_exist_watched_dir = File.join(dir, "test")
|
|
||||||
|
|
||||||
Dir.mkdir(watched_dir)
|
Dir.mkdir(watched_dir)
|
||||||
Dir.mkdir(unwatched_dir)
|
Dir.mkdir(unwatched_dir)
|
||||||
|
|
||||||
checker = new_checker([], watched_dir => ".rb", not_exist_watched_dir => ".rb") { }
|
checker = new_checker([], watched_dir => ".rb", not_exist_watched_dir => ".rb") { }
|
||||||
|
|
||||||
FileUtils.touch(File.join(watched_dir, "a.rb"))
|
FileUtils.touch(File.join(watched_dir, "a.rb"))
|
||||||
wait
|
wait
|
||||||
assert_predicate checker, :updated?
|
assert_predicate checker, :updated?
|
||||||
assert checker.execute_if_updated
|
assert checker.execute_if_updated
|
||||||
|
|
||||||
Dir.mkdir(not_exist_watched_dir)
|
Dir.mkdir(not_exist_watched_dir)
|
||||||
wait
|
wait
|
||||||
assert_predicate checker, :updated?
|
assert_predicate checker, :updated?
|
||||||
assert checker.execute_if_updated
|
assert checker.execute_if_updated
|
||||||
|
|
||||||
FileUtils.touch(File.join(unwatched_dir, "a.rb"))
|
FileUtils.touch(File.join(unwatched_dir, "a.rb"))
|
||||||
wait
|
wait
|
||||||
assert_not_predicate checker, :updated?
|
assert_not_predicate checker, :updated?
|
||||||
assert_not checker.execute_if_updated
|
assert_not checker.execute_if_updated
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue