require 'rubygems'
require 'autotest'
require 'sys/uname'

include Sys

##
# Autotest::FSEvent
#
# == FEATUERS:
# * Use FSEvent (on Mac OS X 10.5 or higher) instead of filesystem polling
#
# == SYNOPSIS:
# ~/.autotest
#   require 'autotest/fsevent'
module Autotest::FSEvent

  GEM_PATH = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))

  ##
  # Use FSEvent if possible
  Autotest.add_hook :waiting do
    if (Uname.sysname == 'Darwin' && Uname.release.to_i >= 9) || %w(Linux).include?(Uname.sysname)
      `#{File.join(GEM_PATH, 'fsevent', Uname.sysname.downcase, 'fsevent_sleep')} '#{Dir.pwd}' 2>&1`
    else
      puts
      puts "autotest-fsevent: platform #{Uname.sysname} #{Uname.release} is not supported"
    end
  end

end

require 'rubygems'
require 'autotest'
require 'sys/uname'

include Sys

##
# Autotest::FSEvent
#
# == FEATUERS:
# * Use FSEvent (on Mac OS X 10.5 or higher) instead of filesystem polling
#
# == SYNOPSIS:
# ~/.autotest
#   require 'autotest/fsevent'
module Autotest::FSEvent

  GEM_PATH = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))

  ##
  # Use FSEvent if possible
  Autotest.add_hook :waiting do
    if (Uname.sysname == 'Darwin' && Uname.release.to_i >= 9) || %w(Linux).include?(Uname.sysname)
      `#{File.join(GEM_PATH, 'fsevent', Uname.sysname.downcase, 'fsevent_sleep')} '#{Dir.pwd}' 2>&1`
    else
      puts
      puts "autotest-fsevent: platform #{Uname.sysname} #{Uname.release} is not supported"
    end
  end

  Autotest.add_hook :initialize do
    class ::Autotest
      def wait_for_changes
        begin
          hook :waiting
          Kernel.sleep self.sleep
        end until find_files_to_test
      end
    end
  end

end

Include the waiting hook in the wait for changed files loop.
Include the waiting hook in the wait for changed files loop.

This fixes the condition where changes to any ignored files caused
fsevent to wake the thread but when autotest ignored the changed file it
went back to using its polling loop. By invoking the waiting hook again
fsevent is able to put the thread back to sleep as expected.

Signed-off-by: Sven Schwyn <84e4dbed99e205d66ece1cbb53e8195d28a06b80@delirium.ch>