Class: Puppet::FileServing::Fileset Private
- Defined in:
- lib/puppet/file_serving/fileset.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Operate recursively on a path, returning a set of file paths.
Defined Under Namespace
Classes: FileSetEntry
Instance Attribute Summary collapse
- #checksum_type ⇒ Object private
- #ignore ⇒ Object private
- #links ⇒ Object private
- #max_files ⇒ Object private
- #path ⇒ Object readonly private
- #recurse ⇒ Object private
- #recurselimit ⇒ Object private
Class Method Summary collapse
-
.merge(*filesets) ⇒ Object
private
Produce a hash of files, with merged so that earlier files with the same postfix win.
Instance Method Summary collapse
-
#files ⇒ Object
private
Return a list of all files in our fileset.
-
#initialize(path, options = {}) ⇒ Fileset
constructor
private
A new instance of Fileset.
Constructor Details
#initialize(path, options = {}) ⇒ Fileset
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Fileset.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/puppet/file_serving/fileset.rb', line 28 def initialize(path, = {}) if Puppet::Util::Platform.windows? # REMIND: UNC path path = path.chomp(File::SEPARATOR) unless path =~ /^[A-Za-z]:\/$/ else path = path.chomp(File::SEPARATOR) unless path == File::SEPARATOR end raise ArgumentError.new(_("Fileset paths must be fully qualified: %{path}") % { path: path }) unless Puppet::Util.absolute_path?(path) @path = path # Set our defaults. self.ignore = [] self.links = :manage @recurse = false @recurselimit = :infinite @max_files = 0 if .is_a?(Puppet::Indirector::Request) initialize_from_request() else initialize_from_hash() end raise ArgumentError.new(_("Fileset paths must exist")) unless valid?(path) #TRANSLATORS "recurse" and "recurselimit" are parameter names and should not be translated raise ArgumentError.new(_("Fileset recurse parameter must not be a number anymore, please use recurselimit")) if @recurse.is_a?(Integer) end |
Instance Attribute Details
#checksum_type ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
9 10 11 |
# File 'lib/puppet/file_serving/fileset.rb', line 9 def checksum_type @checksum_type end |
#ignore ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
8 9 10 |
# File 'lib/puppet/file_serving/fileset.rb', line 8 def ignore @ignore end |
#links ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
8 9 10 |
# File 'lib/puppet/file_serving/fileset.rb', line 8 def links @links end |
#max_files ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
9 10 11 |
# File 'lib/puppet/file_serving/fileset.rb', line 9 def max_files @max_files end |
#path ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
8 9 10 |
# File 'lib/puppet/file_serving/fileset.rb', line 8 def path @path end |
#recurse ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
9 10 11 |
# File 'lib/puppet/file_serving/fileset.rb', line 9 def recurse @recurse end |
#recurselimit ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
9 10 11 |
# File 'lib/puppet/file_serving/fileset.rb', line 9 def recurselimit @recurselimit end |
Class Method Details
.merge(*filesets) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Produce a hash of files, with merged so that earlier files with the same postfix win. E.g., /dir1/subfile beats /dir2/subfile. It’s a hash because we need to know the relative path of each file, and the base directory.
This will probably only ever be used for searching for plugins.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/puppet/file_serving/fileset.rb', line 16 def self.merge(*filesets) result = {} filesets.each do |fileset| fileset.files.each do |file| result[file] ||= fileset.path end end result end |
Instance Method Details
#files ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return a list of all files in our fileset. This is different from the normal definition of find in that we support specific levels of recursion, which means we need to know when we’re going another level deep, which Find doesn’t do.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/puppet/file_serving/fileset.rb', line 61 def files files = perform_recursion soft_max_files = 1000 # munged_max_files is needed since puppet http handler is keeping negative numbers as strings # https://github.com/puppetlabs/puppet/blob/main/lib/puppet/network/http/handler.rb#L196-L197 munged_max_files = max_files == '-1' ? -1 : max_files if munged_max_files > 0 && files.size > munged_max_files raise Puppet::Error.new _("The directory '%{path}' contains %{entries} entries, which exceeds the limit of %{munged_max_files} specified by the max_files parameter for this resource. The limit may be increased, but be aware that large number of file resources can result in excessive resource consumption and degraded performance. Consider using an alternate method to manage large directory trees") % { path: path, entries: files.size, munged_max_files: munged_max_files } elsif munged_max_files == 0 && files.size > soft_max_files Puppet.warning _("The directory '%{path}' contains %{entries} entries, which exceeds the default soft limit %{soft_max_files} and may cause excessive resource consumption and degraded performance. To remove this warning set a value for `max_files` parameter or consider using an alternate method to manage large directory trees") % { path: path, entries: files.size, soft_max_files: soft_max_files } end # Now strip off the leading path, so each file becomes relative, and remove # any slashes that might end up at the beginning of the path. result = files.collect { |file| file.sub(%r{^#{Regexp.escape(@path)}/*}, '') } # And add the path itself. result.unshift(".") result end |