class SolrWrapper::ChecksumValidator

Attributes

config[R]

Public Class Methods

new(config) click to toggle source
# File lib/solr_wrapper/checksum_validator.rb, line 5
def initialize(config)
  @config = config
end

Public Instance Methods

clean!() click to toggle source
# File lib/solr_wrapper/checksum_validator.rb, line 9
def clean!
  path = checksum_path(algorithm)
  FileUtils.remove_entry(path) if File.exist? path
end
validate!(file) click to toggle source
# File lib/solr_wrapper/checksum_validator.rb, line 19
def validate!(file)
  unless validate? file
    raise "Checksum mismatch" unless config.ignore_checksum
  end
end
validate?(file) click to toggle source
# File lib/solr_wrapper/checksum_validator.rb, line 14
def validate?(file)
  return true if config.validate == false
  Digest.const_get(algorithm.upcase).file(file).hexdigest == expected_sum(algorithm)
end

Private Instance Methods

algorithm() click to toggle source
# File lib/solr_wrapper/checksum_validator.rb, line 55
def algorithm
  return config.static_config.algorithm if config.static_config.algorithm
  return 'sha1' if config.static_config.version =~ /^[1-6]/ || config.static_config.version =~ /^[7]\.[0-4]/

  'sha512'
end
checksum_path(suffix) click to toggle source
# File lib/solr_wrapper/checksum_validator.rb, line 35
def checksum_path(suffix)
  File.join(config.download_dir, File.basename(checksumurl(suffix)))
end
checksumfile(alg) click to toggle source
# File lib/solr_wrapper/checksum_validator.rb, line 47
def checksumfile(alg)
  path = checksum_path(alg)
  unless File.exist? path
    Downloader.fetch_with_progressbar checksumurl(alg), path
  end
  path
end
checksumurl(suffix) click to toggle source
# File lib/solr_wrapper/checksum_validator.rb, line 27
def checksumurl(suffix)
  if config.default_download_url == config.static_config.archive_download_url
    "#{config.default_download_url}.#{suffix}"
  else
    "https://archive.apache.org/dist/lucene/solr/#{config.static_config.version}/solr-#{config.static_config.version}.zip.#{suffix}"
  end
end
expected_sum(alg) click to toggle source
# File lib/solr_wrapper/checksum_validator.rb, line 39
def expected_sum(alg)
  config.checksum || read_file(alg)
end
read_file(alg) click to toggle source
# File lib/solr_wrapper/checksum_validator.rb, line 43
def read_file(alg)
  open(checksumfile(alg)).read.split(" ").first
end