Sha256: b5c991124aea31b351c76333136ecf6f2024766448e80a15963babc2f819ae3d

Contents?: true

Size: 1.14 KB

Versions: 6

Compression:

Stored size: 1.14 KB

Contents

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

# 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, :terminus_class => :selector

  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 = Puppet::FileSystem::File.new(full_path).binread
    end
    @content
  end

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
puppet-3.4.3 lib/puppet/file_serving/content.rb
puppet-3.4.2 lib/puppet/file_serving/content.rb
puppet-3.4.1 lib/puppet/file_serving/content.rb
puppet-3.4.0 lib/puppet/file_serving/content.rb
puppet-3.4.0.rc2 lib/puppet/file_serving/content.rb
puppet-3.4.0.rc1 lib/puppet/file_serving/content.rb