Skip to content

Commit

Permalink
Fix rubocop offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
deric committed Aug 3, 2022
1 parent 13831b8 commit feac302
Showing 1 changed file with 28 additions and 26 deletions.
54 changes: 28 additions & 26 deletions lib/facter/kmod.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,35 @@

def kmod_load_module_config(kmodule)
if File.exist?('/sys/module')
config = {
'parameters' => {},
'used_by' => [],
}

if File.directory?("/sys/module/#{kmodule}/parameters")
Dir.foreach("/sys/module/#{kmodule}/parameters") do |param|
next if ['.', '..'].include?(param)

next unless File.readable?("/sys/module/#{kmodule}/parameters/#{param}")

begin
config['parameters'][param] = File.read("/sys/module/#{kmodule}/parameters/#{param}").chomp
rescue StandardError
# some kernel parameters are write only
# even though they have the read bit set
# so just ignore read errors
nil
end
config = {
'parameters' => {},
'used_by' => [],
}

if File.directory?("/sys/module/#{kmodule}/parameters")
Dir.foreach("/sys/module/#{kmodule}/parameters") do |param|
next if ['.', '..'].include?(param)

next unless File.readable?("/sys/module/#{kmodule}/parameters/#{param}")

begin
config['parameters'][param] = File.read("/sys/module/#{kmodule}/parameters/#{param}").chomp
rescue StandardError
# some kernel parameters are write only
# even though they have the read bit set
# so just ignore read errors
nil
end
end
end

if File.directory?("/sys/module/#{kmodule}/holders")
Dir.foreach("/sys/module/#{kmodule}/holders") do |used|
next if ['.', '..'].include?(used)
if File.directory?("/sys/module/#{kmodule}/holders")
Dir.foreach("/sys/module/#{kmodule}/holders") do |used|
next if ['.', '..'].include?(used)

config['used_by'] << used
end
config['used_by'] << used
end
end

config
else
Expand All @@ -42,13 +42,14 @@ def kmod_load_module_config(kmodule)
end

Facter.add(:kmods) do
confine :osfamily => %w{Debian}
confine osfamily: %w[Debian]

kmod = {}

setcode do
Dir.foreach('/etc/modules-load.d') do |item|
next if ['.', '..', 'modules.conf'].include?(item)

if item.end_with? '.conf'
config = item[0...-5]
kmod[config] = kmod_load_module_config(config)
Expand All @@ -59,13 +60,14 @@ def kmod_load_module_config(kmodule)
end

Facter.add(:kmods) do
confine :osfamily => %w{RedHat}
confine osfamily: %w[RedHat]

kmod = {}

setcode do
Dir.foreach('/etc/sysconfig/modules') do |item|
next if ['.', '..'].include?(item)

if item.end_with? '.modules'
config = item[0...-8]
kmod[config] = kmod_load_module_config(config)
Expand Down

0 comments on commit feac302

Please sign in to comment.