lib/util/file_helper.rb in facter-4.0.17 vs lib/util/file_helper.rb in facter-4.0.18

- old
+ new

@@ -2,22 +2,31 @@ module Facter module Util class FileHelper @log = Log.new(self) + class << self DEBUG_MESSAGE = 'File at: %s is not accessible.' - def safe_read(path, result_if_not_readable = '') + def safe_read(path, default_return = '') return File.read(path) if File.readable?(path) - result_if_not_readable + log_failed_to_read(path) + default_return end - def safe_readlines(path, result_if_not_readable = []) + def safe_readlines(path, default_return = []) return File.readlines(path) if File.readable?(path) - result_if_not_readable + log_failed_to_read(path) + default_return + end + + private + + def log_failed_to_read(path) + @log.debug(DEBUG_MESSAGE % path) end end end end end