From 456eb2069f801167157a3e0fe6730791f4eaf33c Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Wed, 7 Oct 2020 14:28:04 -0400 Subject: [PATCH] Switch to using the listen gem for Mac OSX support --- Gemfile | 2 +- lib/ansible/runner.rb | 27 +++++++++++++-------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Gemfile b/Gemfile index 3eff8edf352..b4c7d958c38 100644 --- a/Gemfile +++ b/Gemfile @@ -46,6 +46,7 @@ gem "inifile", "~>3.0", :require => false gem "inventory_refresh", "~>0.2.0", :require => false gem "kubeclient", "~>4.0", :require => false # For scaling pods at runtime gem "linux_admin", "~>2.0", ">=2.0.1", :require => false +gem "listen", "~>3.2", :require => false gem "log_decorator", "~>0.1", :require => false gem "manageiq-api-client", "~>0.3.4", :require => false gem "manageiq-loggers", "~>0.5.0", :require => false @@ -68,7 +69,6 @@ gem "query_relation", "~>0.1.0", :require => false gem "rails", "~>5.2.4", ">=5.2.4.4" gem "rails-i18n", "~>5.x" gem "rake", ">=12.3.3", :require => false -gem "rb-inotify", "~>0.10.0", :require => false gem "rest-client", "~>2.1.0", :require => false gem "ripper_ruby_parser", "~>1.5.1", :require => false gem "ruby-progressbar", "~>1.7.0", :require => false diff --git a/lib/ansible/runner.rb b/lib/ansible/runner.rb index c6a57bd3028..f6ac3366206 100644 --- a/lib/ansible/runner.rb +++ b/lib/ansible/runner.rb @@ -363,28 +363,27 @@ def pid_file(base_dir) end def wait_for(path) - require "rb-inotify" + require "listen" + require "concurrent" + dir_name = File.dirname(path) file_name = File.basename(path) path_created = Concurrent::Event.new - notifier = INotify::Notifier.new - notifier.watch(dir_name, :moved_to, :create) do |event| - # Once the file we are looking for is created set the concurrent event - path_created.set if event.name == file_name + listener = Listen.to(dir_name, :only => %r{\A#{file_name}\z}) do |modified, added, _removed| + path_created.set if added.include?(path) || modified.include?(path) end - thread = Thread.new { notifier.run } - - res = yield - - # Wait for the target file to exist - path_created.wait + thread = Thread.new { listener.start } - # Shutdown the inotify loop and join the thread - notifier.close - thread.join + begin + res = yield + path_created.wait + ensure + listener.stop + thread.join + end res end