# class Puppet::Util::LoadedFile

### Attributes

file[R]
statted[R]
tstamp[W]

Provide a hook for setting the timestamp during testing, so we don’t have to depend on the granularity of the filesystem.

### Public Class Methods

new(file) click to toggle source

Create the file. Must be passed the file path.

    # File lib/puppet/util/loadedfile.rb, line 35
    def initialize(file)
      @file = file
      @statted = 0
      @stamp = nil
      @tstamp = stamp
    end

### Public Instance Methods

changed?() click to toggle source

Determine whether the file has changed and thus whether it should be reparsed.

    # File lib/puppet/util/loadedfile.rb, line 17
    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

stamp() click to toggle source

Retrieve the filestamp, but only refresh it if we’re beyond our filetimeout

    # File lib/puppet/util/loadedfile.rb, line 44
    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

to_s() click to toggle source

    # File lib/puppet/util/loadedfile.rb, line 56
    def to_s
      @file
    end