class YumS3Sync::YumRepository

Attributes

metadata[RW]

Public Class Methods

new(downloader) click to toggle source
# File lib/yum_s3_sync/yum_repository.rb, line 12
def initialize(downloader)
  @metadata = {}
  @downloader = downloader

  repomd_file = @downloader.download('repodata/repomd.xml')
  if repomd_file
    doc = Nokogiri::XML(repomd_file)
    doc.xpath("//xmlns:data").each do |file|
      metadata[file['type']] = {
        :href => file.xpath('xmlns:location')[0]['href'],
        :checksum => file.xpath('xmlns:checksum')[0].child.to_s
      }
    end

    @metadata['repomd'] = { :href => 'repodata/repomd.xml' }
  else
    @metadata = { 'primary' => nil }
  end
end

Public Instance Methods

compare(other) click to toggle source
# File lib/yum_s3_sync/yum_repository.rb, line 54
def compare(other)
  diff_packages = []

  if !other.metadata['primary'] || metadata['primary'][:checksum] != other.metadata['primary'][:checksum]
    packages.each do |package, checksum|
      if other.packages[package] != checksum
        diff_packages.push package
      end
    end
  end

  diff_packages
end
exists?() click to toggle source
# File lib/yum_s3_sync/yum_repository.rb, line 68
def exists?
  @metadata['primary']
end
packages() click to toggle source
# File lib/yum_s3_sync/yum_repository.rb, line 50
def packages
  @parsed_packages ||= parse_packages
end
parse_packages() click to toggle source
# File lib/yum_s3_sync/yum_repository.rb, line 32
def parse_packages
  return {} unless @metadata['primary']

  primary_file = @downloader.download(@metadata['primary'][:href])
  return {} unless primary_file

  puts "Parsing #{@metadata['primary'][:href]}"
  gzstream = Zlib::GzipReader.new(primary_file)

  doc = Nokogiri::XML(gzstream)
  packages = {}
  doc.xpath("//xmlns:package").each do |package|
    packages[package.xpath("xmlns:location")[0]['href']] = package.xpath("xmlns:checksum")[0].child.to_s
  end

  packages
end