diff options
author | Xavier Noria <fxn@hashref.com> | 2015-11-10 02:28:14 -0800 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2015-11-10 03:36:25 -0800 |
commit | eda503c836c6cd02937e111b175979c5722677fd (patch) | |
tree | 75b2b95ce3f9679186c04e0b06d0c9e38703677d /activesupport/lib/active_support | |
parent | 8a64824306fd04895f4f6f14e6edb7a82bfe2503 (diff) | |
download | rails-eda503c836c6cd02937e111b175979c5722677fd.tar.gz rails-eda503c836c6cd02937e111b175979c5722677fd.tar.bz2 rails-eda503c836c6cd02937e111b175979c5722677fd.zip |
the evented monitor filters out descendants
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/file_evented_update_checker.rb | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/activesupport/lib/active_support/file_evented_update_checker.rb b/activesupport/lib/active_support/file_evented_update_checker.rb index 41ec12d829..262e801ce3 100644 --- a/activesupport/lib/active_support/file_evented_update_checker.rb +++ b/activesupport/lib/active_support/file_evented_update_checker.rb @@ -17,8 +17,8 @@ module ActiveSupport @updated = false @lcsp = @ph.longest_common_subpath(@dirs.keys) - if (watch_dirs = base_directories).any? - Listen.to(*watch_dirs, &method(:changed)).start + if (dtw = directories_to_watch).any? + Listen.to(*dtw, &method(:changed)).start end end @@ -71,14 +71,15 @@ module ActiveSupport end end - # TODO: Better return a list of non-nested directories. - def base_directories - [].tap do |bd| - bd.concat @files.map {|f| @ph.existing_parent(f.dirname)} - bd.concat @dirs.keys.map {|dir| @ph.existing_parent(dir)} - bd.compact! - bd.uniq! - end + def directories_to_watch + bd = [] + + bd.concat @files.map {|f| @ph.existing_parent(f.dirname)} + bd.concat @dirs.keys.map {|dir| @ph.existing_parent(dir)} + bd.compact! + bd.uniq! + + @ph.filter_out_descendants(bd) end class PathHelper @@ -133,6 +134,31 @@ module ActiveSupport end end end + + # Filters out directories which are descendants of others in the collection (stable). + def filter_out_descendants(directories) + return directories if directories.length < 2 + + sorted = directories.sort_by {|dir| dir.each_filename.to_a.length} + descendants = [] + + until sorted.empty? + directory = sorted.shift + + sorted.each do |candidate_to_descendant| + if candidate_to_descendant.to_path.start_with?(directory.to_path) + dparts = directory.each_filename.to_a + cparts = candidate_to_descendant.each_filename.to_a + + if cparts[0, dparts.length] == dparts + descendants << candidate_to_descendant + end + end + end + end + + directories - descendants + end end end end |