class Lexicon::Common::Package::PackageIntegrityValidator

Attributes

shell[R]

@return [ShellExecutor]

Public Class Methods

new(shell:) click to toggle source

@param [ShellExecutor] shell

# File lib/lexicon/common/package/package_integrity_validator.rb, line 8
def initialize(shell:)
  @shell = shell
end

Public Instance Methods

integrity_states(package) click to toggle source

@param [Package] package @return [Hash{String => Boolean}]

# File lib/lexicon/common/package/package_integrity_validator.rb, line 20
        def integrity_states(package)
          sumstr = shell.execute <<~BASH
            (cd "#{package.dir}" && sha256sum -c #{package.checksum_file.basename} 2>/dev/null)
          BASH

          sumstr.scan(/(.*?): (.*?)\n/)
                .to_h
                .transform_values { |value| value == 'OK' }
        end
valid?(package) click to toggle source

@param [Package] package @return [Boolean]

# File lib/lexicon/common/package/package_integrity_validator.rb, line 14
def valid?(package)
  integrity_states(package).values.all? { |v| v == true }
end