Sha256: 67a27f6a815948162dc0cfb7dc67c8fad164f8c5a76d155e15d2905a6f20876e

Contents?: true

Size: 1.23 KB

Versions: 617

Compression:

Stored size: 1.23 KB

Contents

require 'puppet/util/watcher'

# Monitor a given file for changes on a periodic interval. Changes are detected
# by looking for a change in the file ctime.
class Puppet::Util::WatchedFile
  # @!attribute [r] filename
  #   @return [String] The fully qualified path to the file.
  attr_reader :filename

  # @param filename [String] The fully qualified path to the file.
  # @param timer [Puppet::Util::Watcher::Timer] The polling interval for checking for file
  #   changes. Setting the timeout to a negative value will treat the file as
  #   always changed. Defaults to `Puppet[:filetimeout]`
  def initialize(filename, timer = Puppet::Util::Watcher::Timer.new(Puppet[:filetimeout]))
    @filename = filename
    @timer = timer

    @info = Puppet::Util::Watcher::PeriodicWatcher.new(
      Puppet::Util::Watcher::Common.file_ctime_change_watcher(@filename),
      timer)
  end

  # @return [true, false] If the file has changed since it was last checked.
  def changed?
    @info.changed?
  end

  # Allow this to be used as the name of the file being watched in various
  # other methods (such as Puppet::FileSystem.exist?)
  def to_str
    @filename
  end

  def to_s
    "<WatchedFile: filename = #{@filename}, timeout = #{@timer.timeout}>"
  end
end

Version data entries

617 entries across 617 versions & 3 rubygems

Version Path
puppet-6.29.0 lib/puppet/util/watched_file.rb
puppet-6.29.0-x86-mingw32 lib/puppet/util/watched_file.rb
puppet-6.29.0-x64-mingw32 lib/puppet/util/watched_file.rb
puppet-6.29.0-universal-darwin lib/puppet/util/watched_file.rb
puppet-6.28.0 lib/puppet/util/watched_file.rb
puppet-6.28.0-x86-mingw32 lib/puppet/util/watched_file.rb
puppet-6.28.0-x64-mingw32 lib/puppet/util/watched_file.rb
puppet-6.28.0-universal-darwin lib/puppet/util/watched_file.rb
puppet-6.27.0 lib/puppet/util/watched_file.rb
puppet-6.27.0-x86-mingw32 lib/puppet/util/watched_file.rb
puppet-6.27.0-x64-mingw32 lib/puppet/util/watched_file.rb
puppet-6.27.0-universal-darwin lib/puppet/util/watched_file.rb
puppet-6.26.0 lib/puppet/util/watched_file.rb
puppet-6.26.0-x86-mingw32 lib/puppet/util/watched_file.rb
puppet-6.26.0-x64-mingw32 lib/puppet/util/watched_file.rb
puppet-6.26.0-universal-darwin lib/puppet/util/watched_file.rb
puppet-6.25.1 lib/puppet/util/watched_file.rb
puppet-6.25.1-x86-mingw32 lib/puppet/util/watched_file.rb
puppet-6.25.1-x64-mingw32 lib/puppet/util/watched_file.rb
puppet-6.25.1-universal-darwin lib/puppet/util/watched_file.rb