Sha256: 7660ae6ba818bf9a66d86c5c0e05f3b9ad87c76c131657096bf6a5502935c2a4

Contents?: true

Size: 1.04 KB

Versions: 20

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true
class Puppet::Settings::FileOrDirectorySetting < Puppet::Settings::FileSetting

  def initialize(args)
    super
  end

  def type
    if Puppet::FileSystem.directory?(self.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 =~ /[\\\/]$/
      @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.3.0 lib/puppet/settings/file_or_directory_setting.rb
puppet-8.3.0-x86-mingw32 lib/puppet/settings/file_or_directory_setting.rb
puppet-8.3.0-x64-mingw32 lib/puppet/settings/file_or_directory_setting.rb
puppet-8.3.0-universal-darwin lib/puppet/settings/file_or_directory_setting.rb
puppet-8.3.1 lib/puppet/settings/file_or_directory_setting.rb
puppet-8.3.1-x86-mingw32 lib/puppet/settings/file_or_directory_setting.rb
puppet-8.3.1-x64-mingw32 lib/puppet/settings/file_or_directory_setting.rb
puppet-8.3.1-universal-darwin lib/puppet/settings/file_or_directory_setting.rb
puppet-8.2.0 lib/puppet/settings/file_or_directory_setting.rb
puppet-8.2.0-x86-mingw32 lib/puppet/settings/file_or_directory_setting.rb
puppet-8.2.0-x64-mingw32 lib/puppet/settings/file_or_directory_setting.rb
puppet-8.2.0-universal-darwin lib/puppet/settings/file_or_directory_setting.rb
puppet-8.1.0 lib/puppet/settings/file_or_directory_setting.rb
puppet-8.1.0-x86-mingw32 lib/puppet/settings/file_or_directory_setting.rb
puppet-8.1.0-x64-mingw32 lib/puppet/settings/file_or_directory_setting.rb
puppet-8.1.0-universal-darwin lib/puppet/settings/file_or_directory_setting.rb
puppet-8.0.1 lib/puppet/settings/file_or_directory_setting.rb
puppet-8.0.1-x86-mingw32 lib/puppet/settings/file_or_directory_setting.rb
puppet-8.0.1-x64-mingw32 lib/puppet/settings/file_or_directory_setting.rb
puppet-8.0.1-universal-darwin lib/puppet/settings/file_or_directory_setting.rb