Created
December 15, 2018 12:56
-
-
Save matthewd/820e2100f45aa1011746ebec025a3acc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/activesupport/lib/active_support/evented_file_update_checker.rb b/activesupport/lib/active_support/evented_file_update_checker.rb | |
index 97e982eb05..d4c712ea96 100644 | |
--- a/activesupport/lib/active_support/evented_file_update_checker.rb | |
+++ b/activesupport/lib/active_support/evented_file_update_checker.rb | |
@@ -52,7 +52,10 @@ def initialize(files, dirs = {}, &block) | |
@pid = Process.pid | |
@boot_mutex = Mutex.new | |
- if (@dtw = directories_to_watch).any? | |
+ dtw = directories_to_watch | |
+ @dtw, @missing = dtw.partition(&:exist?) | |
+ | |
+ if dtw.any? | |
# Loading listen triggers warnings. These are originated by a legit | |
# usage of attr_* macros for private attributes, but adds a lot of noise | |
# to our test suite. Thus, we lazy load it and disable warnings locally. | |
@@ -68,6 +71,7 @@ def initialize(files, dirs = {}, &block) | |
end | |
def updated? | |
+ if @pid != Process.pid # Unrelated in passing: skip the mutex in the common case | |
@boot_mutex.synchronize do | |
if @pid != Process.pid | |
boot! | |
@@ -75,6 +79,24 @@ def updated? | |
@updated.make_true | |
end | |
end | |
+ end | |
+ | |
+ # Consider only checking this if it's been.. 2 seconds? since we | |
+ # last did | |
+ if @missing.any?(&:exist?) | |
+ @boot_mutex.synchronize do | |
+ appeared, @missing = @missing.partition(&:exist?) | |
+ | |
+ shutdown! # TODO -- alternatively, maybe we add them to the existing Listen setup, but a full reset seems maybe easiest? | |
+ | |
+ @dtw += appeared | |
+ | |
+ boot! | |
+ | |
+ @updated.make_true | |
+ end | |
+ end | |
+ | |
@updated.true? | |
end | |
@@ -123,7 +145,7 @@ def watching?(file) | |
end | |
def directories_to_watch | |
- dtw = (@files + @dirs.keys).map { |f| @ph.existing_parent(f) } | |
+ dtw = @files + @dirs.keys | |
dtw.compact! | |
dtw.uniq! | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment