Skip to content

Commit 6d55552

Browse files
author
Ciprian Badescu
committed
(PUP-10946) Allow -1 value of max_files as string
Since the http handler is transforming only posive values to numbers, we need to accomodate the max_files value of `-1` value as string.
1 parent bb8421d commit 6d55552

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

lib/puppet/file_serving/fileset.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,14 @@ def files
6161
files = perform_recursion
6262
soft_max_files = 1000
6363

64-
if max_files > 0 && files.size > max_files
65-
raise Puppet::Error.new _("The directory '%{path}' contains %{entries} entries, which exceeds the limit of %{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, max_files: max_files }
66-
elsif max_files == 0 && files.size > soft_max_files
67-
Puppet.warning _("The directory '%{path}' contains %{entries} entries, which exceeds the default soft limit %{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, max_files: soft_max_files }
64+
# munged_max_files is needed since puppet http handler is keeping negative numbers as strings
65+
# https://github.com/puppetlabs/puppet/blob/main/lib/puppet/network/http/handler.rb#L196-L197
66+
munged_max_files = max_files == '-1' ? -1 : max_files
67+
68+
if munged_max_files > 0 && files.size > munged_max_files
69+
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 }
70+
elsif munged_max_files == 0 && files.size > soft_max_files
71+
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 }
6872
end
6973

7074
# Now strip off the leading path, so each file becomes relative, and remove

spec/unit/file_serving/fileset_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,14 @@ def directory?
310310
@fileset.files
311311
end
312312

313+
it "does not emit a warning if max_files is `-1`(string)" do
314+
mock_big_dir_structure(@path)
315+
@fileset.recurse = true
316+
@fileset.max_files = '-1'
317+
expect(Puppet).to receive(:warning).never
318+
@fileset.files
319+
end
320+
313321
it "ignores files that match a pattern given as a boolean" do
314322
mock_dir_structure(@path)
315323
@fileset.recurse = true

0 commit comments

Comments
 (0)