123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- $OpenBSD: patch-lib_facter_util_partitions_openbsd_rb,v 1.5 2015/09/01 07:23:35 jasper Exp $
- Cache df/mount output to prevent running these programs 3 times for every partition found.
- https://github.com/puppetlabs/facter/pull/1119
- --- lib/facter/util/partitions/openbsd.rb.orig Tue May 19 18:41:15 2015
- +++ lib/facter/util/partitions/openbsd.rb Mon Aug 31 19:03:46 2015
- @@ -1,9 +1,26 @@
- module Facter::Util::Partitions
- module OpenBSD
- + @df_output = nil
- + @mount_output = nil
- +
- def self.list
- - Facter::Core::Execution.exec('df').scan(/\/dev\/(\S+)/).flatten
- + @df_output ||= run_df
- + @df_output.scan(/\/dev\/(\S+)/).flatten
- end
-
- + def self.flushable?
- + true
- + end
- +
- + def self.flush!
- + @df_output = nil
- + @mount_output = nil
- + end
- +
- + def self.flushed?
- + !@df_output
- + end
- +
- # On OpenBSD partitions don't have a UUID; disks have DUID but that's not
- # compatible.
- def self.uuid(partition)
- @@ -22,19 +39,29 @@ module Facter::Util::Partitions
- def self.filesystem(partition)
- scan_mount(/\/dev\/#{partition}\son\s\S+\stype\s(\S+)/)
- end
- -
- +
- # On OpenBSD there are no labels for partitions
- def self.label(partition)
- nil
- end
-
- private
- + def self.run_mount
- + Facter::Core::Execution.exec('mount')
- + end
- +
- + def self.run_df
- + Facter::Core::Execution.exec('df -k')
- + end
- +
- def self.scan_mount(scan_regex)
- - Facter::Core::Execution.exec('mount').scan(scan_regex).flatten.first
- + @mount_output ||= run_mount
- + @mount_output.scan(scan_regex).flatten.first
- end
-
- def self.scan_df(scan_regex)
- - Facter::Core::Execution.exec('df -k').scan(scan_regex).flatten.first
- + @df_output ||= run_df
- + @df_output.scan(scan_regex).flatten.first
- end
- end
- end
|