Skip to content

Commit 1d9d3b4

Browse files
committed
(PUP-11974) Only warn when Ruby's verbose is enabled
In ruby 2.7.x, the rb_file_exists_p and rb_dir_exists_p methods call rb_warning to log that the methods are deprecated[1][2] However, the rb_warning method is a noop if $VERBOSE is nil or false[3] To preserve the same behavior, only warn when $VERBOSE is truthy. Also include the class name and path in the warning so we can identify and fix the issue. [1] https://github.com/ruby/ruby/blob/1f4d4558484b370999954f3ede7e3aa3a3a01ef3/file.c#L1819 [2] https://github.com/ruby/ruby/blob/1f4d4558484b370999954f3ede7e3aa3a3a01ef3/dir.c#L3301 [3] https://github.com/ruby/ruby/blob/1f4d4558484b370999954f3ede7e3aa3a3a01ef3/error.c#L336-L338
1 parent 6f19bb8 commit 1d9d3b4

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/puppet/util/monkey_patches.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def daemonize
3333
unless Dir.singleton_methods.include?(:exists?)
3434
class Dir
3535
def self.exists?(file_name)
36-
warn('exists? is a deprecated name, use exist? instead')
36+
warn("Dir.exists?('#{file_name}') is deprecated, use Dir.exist? instead") if $VERBOSE
3737
Dir.exist?(file_name)
3838
end
3939
end
@@ -42,7 +42,7 @@ def self.exists?(file_name)
4242
unless File.singleton_methods.include?(:exists?)
4343
class File
4444
def self.exists?(file_name)
45-
warn('exists? is a deprecated name, use exist? instead')
45+
warn("File.exists?('#{file_name}') is deprecated, use File.exist? instead") if $VERBOSE
4646
File.exist?(file_name)
4747
end
4848
end

0 commit comments

Comments
 (0)