Sha256: 6108f9a1a00212278939919facd75c5343f793e1cc6b9b173bfcded96494bdd4

Contents?: true

Size: 1.11 KB

Versions: 54

Compression:

Stored size: 1.11 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 = IO.binread(full_path)
    end
    @content
  end

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

Version data entries

54 entries across 54 versions & 3 rubygems

Version Path
puppet-parse-0.1.4 lib/vendor/puppet/file_serving/content.rb
puppet-parse-0.1.3 lib/vendor/puppet/file_serving/content.rb
puppet-parse-0.1.2 lib/vendor/puppet/file_serving/content.rb
puppet-parse-0.1.1 lib/vendor/puppet/file_serving/content.rb
puppet-2.7.26 lib/puppet/file_serving/content.rb
puppet-2.7.25 lib/puppet/file_serving/content.rb
puppet-2.7.24 lib/puppet/file_serving/content.rb
puppet-3.3.2 lib/puppet/file_serving/content.rb
puppet-3.3.1 lib/puppet/file_serving/content.rb
puppet-3.3.1.rc3 lib/puppet/file_serving/content.rb
puppet-3.3.1.rc2 lib/puppet/file_serving/content.rb
puppet-3.3.1.rc1 lib/puppet/file_serving/content.rb
puppet-3.3.0 lib/puppet/file_serving/content.rb
puppet-3.3.0.rc3 lib/puppet/file_serving/content.rb
puppet-3.3.0.rc2 lib/puppet/file_serving/content.rb
puppet-3.2.4 lib/puppet/file_serving/content.rb
puppet-2.7.23 lib/puppet/file_serving/content.rb
puppet-3.2.3 lib/puppet/file_serving/content.rb
puppet-3.2.3.rc1 lib/puppet/file_serving/content.rb
puppet-3.2.2 lib/puppet/file_serving/content.rb