Sha256: 0c9cdede19f37e7a5775ec27b793294d7803e9d5a07d530eb4fcf4c214ef766e

Contents?: true

Size: 1.15 KB

Versions: 68

Compression:

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

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

Version data entries

68 entries across 68 versions & 2 rubygems

Version Path
puppet-retrospec-0.12.2 vendor/gems/puppet-3.7.3/lib/puppet/file_serving/content.rb
puppet-3.8.7 lib/puppet/file_serving/content.rb
puppet-3.8.7-x86-mingw32 lib/puppet/file_serving/content.rb
puppet-3.8.7-x64-mingw32 lib/puppet/file_serving/content.rb
puppet-3.8.6 lib/puppet/file_serving/content.rb
puppet-3.8.6-x86-mingw32 lib/puppet/file_serving/content.rb
puppet-retrospec-0.12.1 vendor/gems/puppet-3.7.3/lib/puppet/file_serving/content.rb
puppet-3.8.6-x64-mingw32 lib/puppet/file_serving/content.rb
puppet-retrospec-0.12.0 vendor/gems/puppet-3.7.3/lib/puppet/file_serving/content.rb
puppet-3.8.5 lib/puppet/file_serving/content.rb
puppet-3.8.5-x86-mingw32 lib/puppet/file_serving/content.rb
puppet-3.8.5-x64-mingw32 lib/puppet/file_serving/content.rb
puppet-3.8.4 lib/puppet/file_serving/content.rb
puppet-3.8.4-x86-mingw32 lib/puppet/file_serving/content.rb
puppet-3.8.4-x64-mingw32 lib/puppet/file_serving/content.rb
puppet-retrospec-0.11.0 vendor/gems/puppet-3.7.3/lib/puppet/file_serving/content.rb
puppet-retrospec-0.10.0 vendor/gems/puppet-3.7.3/lib/puppet/file_serving/content.rb
puppet-retrospec-0.9.1 vendor/gems/puppet-3.7.3/lib/puppet/file_serving/content.rb
puppet-retrospec-0.9.0 vendor/gems/puppet-3.7.3/lib/puppet/file_serving/content.rb
puppet-retrospec-0.8.1 vendor/gems/puppet-3.7.3/lib/puppet/file_serving/content.rb