Class: VagrantPlugins::RsyncBlitz::ListenLinux

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-rsync-blitz/listen/listenlinux.rb

Instance Method Summary collapse

Constructor Details

#initialize(paths, ignores, latency, logger, callback) ⇒ ListenLinux

Returns a new instance of ListenLinux.



6
7
8
9
10
11
12
# File 'lib/vagrant-rsync-blitz/listen/listenlinux.rb', line 6

def initialize(paths, ignores, latency, logger, callback)
  @paths = paths
  @ignores = ignores
  @latency = latency
  @logger = logger
  @callback = callback
end

Instance Method Details

#runObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/vagrant-rsync-blitz/listen/listenlinux.rb', line 14

def run
  @logger.info("Listening via: rb-inotify on Linux.")

  notifier = INotify::Notifier.new
  @paths.keys.each do |path|
    notifier.watch(path, :modify, :create, :delete, :recursive) {}
  end

  loop do
    directories = Set.new
    begin
      loop do
        events = []
        events = Timeout::timeout(@latency) {
          notifier.read_events
        }
        events.each { |e| directories << e.absolute_name }
      end
    rescue Timeout::Error
      @logger.info("Breaking out of the loop at #{Time.now.to_s}.")
    end

    @logger.info("Detected changes to #{directories.inspect}.") unless directories.empty?

    @callback.call(@paths, @ignores, directories) unless directories.empty?
  end
end