Sha256: 7e687d02731db6d23bb997ebdb109cdb65dba90ed2ba88a0894807a47a12ef4c

Contents?: true

Size: 1 KB

Versions: 20

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

class Puppet::Settings::FileOrDirectorySetting < Puppet::Settings::FileSetting
  def type
    if Puppet::FileSystem.directory?(value) || @path_ends_with_slash
      :directory
    else
      :file
    end
  end

  # Overrides munge to be able to read the un-munged value (the FileSetting.munch removes trailing slash)
  #
  def munge(value)
    if value.is_a?(String) && value =~ %r{[\\/]$}
      @path_ends_with_slash = true
    end
    super
  end

  # @api private
  #
  # @param option [String] Extra file operation mode information to use
  #   (defaults to read-only mode 'r')
  #   This is the standard mechanism Ruby uses in the IO class, and therefore
  #   encoding may be explicitly like fmode : encoding or fmode : "BOM|UTF-*"
  #   for example, a:ASCII or w+:UTF-8
  def open_file(filename, option = 'r', &block)
    if type == :file
      super
    else
      controlled_access do |mode|
        Puppet::FileSystem.open(filename, mode, option, &block)
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
puppet-8.10.0 lib/puppet/settings/file_or_directory_setting.rb
puppet-8.10.0-x86-mingw32 lib/puppet/settings/file_or_directory_setting.rb
puppet-8.10.0-x64-mingw32 lib/puppet/settings/file_or_directory_setting.rb
puppet-8.10.0-universal-darwin lib/puppet/settings/file_or_directory_setting.rb
puppet-8.9.0 lib/puppet/settings/file_or_directory_setting.rb
puppet-8.9.0-x86-mingw32 lib/puppet/settings/file_or_directory_setting.rb
puppet-8.9.0-x64-mingw32 lib/puppet/settings/file_or_directory_setting.rb
puppet-8.9.0-universal-darwin lib/puppet/settings/file_or_directory_setting.rb
puppet-8.8.1 lib/puppet/settings/file_or_directory_setting.rb
puppet-8.8.1-x86-mingw32 lib/puppet/settings/file_or_directory_setting.rb
puppet-8.8.1-x64-mingw32 lib/puppet/settings/file_or_directory_setting.rb
puppet-8.8.1-universal-darwin lib/puppet/settings/file_or_directory_setting.rb
puppet-8.7.0 lib/puppet/settings/file_or_directory_setting.rb
puppet-8.7.0-x86-mingw32 lib/puppet/settings/file_or_directory_setting.rb
puppet-8.7.0-x64-mingw32 lib/puppet/settings/file_or_directory_setting.rb
puppet-8.7.0-universal-darwin lib/puppet/settings/file_or_directory_setting.rb
puppet-8.6.0 lib/puppet/settings/file_or_directory_setting.rb
puppet-8.6.0-x86-mingw32 lib/puppet/settings/file_or_directory_setting.rb
puppet-8.6.0-x64-mingw32 lib/puppet/settings/file_or_directory_setting.rb
puppet-8.6.0-universal-darwin lib/puppet/settings/file_or_directory_setting.rb