Sha256: c55f65f329fd3ed1ed9f0992bf09bccd25e6d1e9da91bdda54424d10a9d622aa

Contents?: true

Size: 1.18 KB

Versions: 5

Compression:

Stored size: 1.18 KB

Contents

require 'puppet/indirector'
require 'puppet/file_serving'
require 'puppet/file_serving/base'
require 'puppet/file_serving/indirection_hooks'

# A class that handles retrieving file contents.
# It only reads the file when its content is specifically
# asked for.
class Puppet::FileServing::Content < Puppet::FileServing::Base
  extend Puppet::Indirector
  indirects :file_content, :extend => Puppet::FileServing::IndirectionHooks

  attr_writer :content

  def self.supported_formats
    [:raw]
  end

  def self.from_raw(content)
    instance = new("/this/is/a/fake/path")
    instance.content = content
    instance
  end

  # BF: we used to fetch the file content here, but this is counter-productive
  # for puppetmaster streaming of file content. So collect just returns itself
  def collect
    return if stat.ftype == "directory"
    self
  end

  # Read the content of our file in.
  def content
    unless @content
      # This stat can raise an exception, too.
      raise(ArgumentError, "Cannot read the contents of links unless following links") if stat.ftype == "symlink"

      @content = IO.binread(full_path)
    end
    @content
  end

  def to_raw
    File.new(full_path, "rb")
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
puppet-2.7.17 lib/puppet/file_serving/content.rb
puppet-2.7.16 lib/puppet/file_serving/content.rb
puppet-2.7.14 lib/puppet/file_serving/content.rb
puppet-2.7.13 lib/puppet/file_serving/content.rb
puppet-2.7.12 lib/puppet/file_serving/content.rb