Sha256: 40573187df97eb58652137ff4e68c41a5d6c7346643cb2167ddddf5d2b28b4e9

Contents?: true

Size: 1.37 KB

Versions: 27

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

module Facter
  module Util
    module Resolvers
      module FilesystemHelper
        MOUNT_KEYS = %i[device filesystem path options
                        available available_bytes size
                        size_bytes used used_bytes capacity].freeze
        class << self
          def read_mountpoints
            # TODO: this require must be replaced with "require 'sys/filesystem'" when a new release of
            # djberg96/sys-filesystem gem is available
            require_relative '../../patches/sysfilesystem/sys/statvfs.rb'
            force_utf(Sys::Filesystem.mounts)
          end

          def read_mountpoint_stats(path)
            require 'sys/filesystem'
            Sys::Filesystem.stat(path)
          end

          def compute_capacity(used, total)
            if used == total
              '100%'
            elsif used.positive?
              "#{format('%<value>.2f', value: (used / total.to_f * 100))}%"
            else
              '0%'
            end
          end

          private

          def force_utf(mounts)
            mounts.each do |mount|
              mount.name.force_encoding('UTF-8')
              mount.mount_type.force_encoding('UTF-8')
              mount.mount_point.force_encoding('UTF-8')
              mount.options.force_encoding('UTF-8')
            end
          end
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
facter-4.4.1 lib/facter/util/resolvers/filesystem_helper.rb
facter-4.4.0 lib/facter/util/resolvers/filesystem_helper.rb
facter-4.3.1 lib/facter/util/resolvers/filesystem_helper.rb
facter-4.3.0 lib/facter/util/resolvers/filesystem_helper.rb
facter-4.2.14 lib/facter/util/resolvers/filesystem_helper.rb
facter-4.2.13 lib/facter/util/resolvers/filesystem_helper.rb
facter-4.2.12 lib/facter/util/resolvers/filesystem_helper.rb
facter-4.2.11 lib/facter/util/resolvers/filesystem_helper.rb
facter-4.2.10 lib/facter/util/resolvers/filesystem_helper.rb
facter-4.2.9 lib/facter/util/resolvers/filesystem_helper.rb
facter-4.2.8 lib/facter/util/resolvers/filesystem_helper.rb
facter-4.2.7 lib/facter/util/resolvers/filesystem_helper.rb
facter-4.2.6 lib/facter/util/resolvers/filesystem_helper.rb
facter-4.2.5 lib/facter/util/resolvers/filesystem_helper.rb
facter-4.2.4 lib/facter/util/resolvers/filesystem_helper.rb
facter-4.2.3 lib/facter/util/resolvers/filesystem_helper.rb
facter-4.2.2 lib/facter/util/resolvers/filesystem_helper.rb
facter-4.2.1 lib/facter/util/resolvers/filesystem_helper.rb
facter-4.2.0 lib/facter/util/resolvers/filesystem_helper.rb
facter-4.1.1 lib/facter/util/resolvers/filesystem_helper.rb