Sha256: ff89b33905402d2b9cde144a47173916c43be12ef0716e65a2f674315a156fdd

Contents?: true

Size: 1.53 KB

Versions: 80

Compression:

Stored size: 1.53 KB

Contents

# A simple class that tells us when a file has changed and thus whether we
# should reload it

require 'puppet'

module Puppet
  class NoSuchFile < Puppet::Error; end
  class Util::LoadedFile
    attr_reader :file, :statted

    # Provide a hook for setting the timestamp during testing, so we don't
    # have to depend on the granularity of the filesystem.
    attr_writer :tstamp

    # Determine whether the file has changed and thus whether it should
    # be reparsed.
    def changed?
      # Allow the timeout to be disabled entirely.
      return true if Puppet[:filetimeout] < 0
      tmp = stamp

      # We use a different internal variable than the stamp method
      # because it doesn't keep historical state and we do -- that is,
      # we will always be comparing two timestamps, whereas
      # stamp just always wants the latest one.
      if tmp == @tstamp
        return false
      else
        @tstamp = tmp
        return @tstamp
      end
    end

    # Create the file.  Must be passed the file path.
    def initialize(file)
      @file = file
      @statted = 0
      @stamp = nil
      @tstamp = stamp
    end

    # Retrieve the filestamp, but only refresh it if we're beyond our
    # filetimeout
    def stamp
      if @stamp.nil? or (Time.now.to_i - @statted >= Puppet[:filetimeout])
        @statted = Time.now.to_i
        begin
          @stamp = File.stat(@file).ctime
        rescue Errno::ENOENT, Errno::ENOTDIR
          @stamp = Time.now
        end
      end
      @stamp
    end

    def to_s
      @file
    end
  end
end

Version data entries

80 entries across 80 versions & 4 rubygems

Version Path
puppet-parse-0.1.4 lib/vendor/puppet/util/loadedfile.rb
puppet-parse-0.1.3 lib/vendor/puppet/util/loadedfile.rb
puppet-parse-0.1.2 lib/vendor/puppet/util/loadedfile.rb
puppet-parse-0.1.1 lib/vendor/puppet/util/loadedfile.rb
puppet-2.7.26 lib/puppet/util/loadedfile.rb
puppet-2.7.25 lib/puppet/util/loadedfile.rb
puppet-2.7.24 lib/puppet/util/loadedfile.rb
puppet-3.2.4 lib/puppet/util/loadedfile.rb
puppet-2.7.23 lib/puppet/util/loadedfile.rb
puppet-3.2.3 lib/puppet/util/loadedfile.rb
puppet-3.2.3.rc1 lib/puppet/util/loadedfile.rb
puppet-3.2.2 lib/puppet/util/loadedfile.rb
puppet-2.7.22 lib/puppet/util/loadedfile.rb
puppet-3.2.1 lib/puppet/util/loadedfile.rb
puppet-3.2.1.rc1 lib/puppet/util/loadedfile.rb
puppet-3.2.0.rc2 lib/puppet/util/loadedfile.rb
librarian-puppet-0.9.9 vendor/gems/ruby/1.9.1/gems/puppet-3.1.0/lib/puppet/util/loadedfile.rb
puppet-3.2.0.rc1 lib/puppet/util/loadedfile.rb
puppet-parse-0.1.0 lib/vendor/puppet/util/loadedfile.rb
puppet-parse-0.0.6 lib/vendor/puppet/util/loadedfile.rb