Sha256: d3f18b88d720389fc3b5f89917e41a5f88e65afad92969fe58e7c23bbfeed37c

Contents?: true

Size: 1.99 KB

Versions: 12

Compression:

Stored size: 1.99 KB

Contents

# frozen_string_literal: true

module Facter
  module Resolvers
    module Macosx
      class Mountpoints < BaseResolver
        include Facter::FilesystemHelper
        @semaphore = Mutex.new
        @fact_list ||= {}
        @log = Facter::Log.new(self)
        class << self
          private

          def post_resolve(fact_name)
            @fact_list.fetch(fact_name) { read_mounts }
          end

          def read_mounts # rubocop:disable Metrics/AbcSize
            mounts = {}
            FilesystemHelper.read_mountpoints.each do |fs|
              device = fs.name
              filesystem = fs.mount_type
              path = fs.mount_point
              options = fs.options.split(',').map(&:strip).map { |o| o == 'rootfs' ? 'root' : o }

              next if path =~ %r{^/(proc|sys)} && filesystem != 'tmpfs' || filesystem == 'autofs'

              mounts[path] = read_stats(path).tap do |hash|
                hash[:device] = device
                hash[:filesystem] = filesystem
                hash[:options] = options if options.any?
              end
            end

            @fact_list[:mountpoints] = mounts
          end

          def read_stats(path)
            begin
              stats = FilesystemHelper.read_mountpoint_stats(path)
              size_bytes = stats.bytes_total
              used_bytes = stats.bytes_used
              available_bytes = size_bytes - used_bytes
            rescue Sys::Filesystem::Error
              size_bytes = used_bytes = available_bytes = 0
            end

            {
              size_bytes: size_bytes,
              used_bytes: used_bytes,
              available_bytes: available_bytes,
              capacity: FilesystemHelper.compute_capacity(used_bytes, size_bytes),
              size: Facter::BytesToHumanReadable.convert(size_bytes),
              available: Facter::BytesToHumanReadable.convert(available_bytes),
              used: Facter::BytesToHumanReadable.convert(used_bytes)
            }
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
facter-4.0.18 lib/resolvers/macosx/mountpoints_resolver.rb
facter-4.0.17 lib/resolvers/macosx/mountpoints_resolver.rb
facter-4.0.16 lib/resolvers/macosx/mountpoints_resolver.rb
facter-4.0.15 lib/resolvers/macosx/mountpoints_resolver.rb
facter-4.0.14 lib/resolvers/macosx/mountpoints_resolver.rb
facter-4.0.13 lib/resolvers/macosx/mountpoints_resolver.rb
facter-4.0.12 lib/resolvers/macosx/mountpoints_resolver.rb
facter-4.0.11 lib/resolvers/macosx/mountpoints_resolver.rb
facter-4.0.10.pre lib/resolvers/macosx/mountpoints_resolver.rb
facter-4.0.9.pre lib/resolvers/macosx/mountpoints_resolver.rb
facter-4.0.8.pre lib/resolvers/macosx/mountpoints_resolver.rb
facter-4.0.7.pre lib/resolvers/macosx/mountpoints_resolver.rb