Class: Chef::Provider::Package::Yum::RPMDb

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/provider/package/yum/rpm_utils.rb

Overview

Simple storage for RPMPackage objects - keeps them unique and sorted

Instance Method Summary collapse

Constructor Details

#initializeRPMDb

Returns a new instance of RPMDb


505
506
507
508
509
510
511
512
513
514
515
516
# File 'lib/chef/provider/package/yum/rpm_utils.rb', line 505

def initialize
  # package name => [ RPMPackage, RPMPackage ] of different versions
  @rpms = {}
  # package nevra => RPMPackage for lookups
  @index = {}
  # provide name (aka feature) => [RPMPackage, RPMPackage] each providing this feature
  @provides = {}
  # RPMPackages listed as available
  @available = Set.new
  # RPMPackages listed as installed
  @installed = Set.new
end

Instance Method Details

#<<(*args) ⇒ Object


576
577
578
# File 'lib/chef/provider/package/yum/rpm_utils.rb', line 576

def <<(*args)
  push(args)
end

#[](package_name) ⇒ Object


518
519
520
# File 'lib/chef/provider/package/yum/rpm_utils.rb', line 518

def [](package_name)
  lookup(package_name)
end

#available?(package) ⇒ Boolean

Returns:

  • (Boolean)

609
610
611
# File 'lib/chef/provider/package/yum/rpm_utils.rb', line 609

def available?(package)
  @available.include?(package)
end

#available_sizeObject


601
602
603
# File 'lib/chef/provider/package/yum/rpm_utils.rb', line 601

def available_size
  @available.size
end

#clearObject


580
581
582
583
584
585
586
# File 'lib/chef/provider/package/yum/rpm_utils.rb', line 580

def clear
  @rpms.clear
  @index.clear
  @provides.clear
  clear_available
  clear_installed
end

#clear_availableObject


588
589
590
# File 'lib/chef/provider/package/yum/rpm_utils.rb', line 588

def clear_available
  @available.clear
end

#clear_installedObject


592
593
594
# File 'lib/chef/provider/package/yum/rpm_utils.rb', line 592

def clear_installed
  @installed.clear
end

#installed?(package) ⇒ Boolean

Returns:

  • (Boolean)

613
614
615
# File 'lib/chef/provider/package/yum/rpm_utils.rb', line 613

def installed?(package)
  @installed.include?(package)
end

#installed_sizeObject


605
606
607
# File 'lib/chef/provider/package/yum/rpm_utils.rb', line 605

def installed_size
  @installed.size
end

#lookup(package_name) ⇒ Object

Lookup package_name and return a descending array of package objects


523
524
525
526
527
528
529
530
# File 'lib/chef/provider/package/yum/rpm_utils.rb', line 523

def lookup(package_name)
  pkgs = @rpms[package_name]
  if pkgs
    return pkgs.sort.reverse
  else
    return nil
  end
end

#lookup_provides(provide_name) ⇒ Object


532
533
534
# File 'lib/chef/provider/package/yum/rpm_utils.rb', line 532

def lookup_provides(provide_name)
  @provides[provide_name]
end

#push(*args) ⇒ Object

Using the package name as a key, and nevra for an index, keep a unique list of packages. The available/installed state can be overwritten for existing packages.


538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
# File 'lib/chef/provider/package/yum/rpm_utils.rb', line 538

def push(*args)
  args.flatten.each do |new_rpm|
    unless new_rpm.is_a?(RPMDbPackage)
      raise ArgumentError, "Expecting an RPMDbPackage object"
    end

    @rpms[new_rpm.n] ||= []

    # we may already have this one, like when the installed list is refreshed
    idx = @index[new_rpm.nevra]
    if idx
      # grab the existing package if it's not
      curr_rpm = idx
    else
      @rpms[new_rpm.n] << new_rpm

      new_rpm.provides.each do |provide|
        @provides[provide.name] ||= []
        @provides[provide.name] << new_rpm
      end

      curr_rpm = new_rpm
    end

    # Track the nevra -> RPMPackage association to avoid having to compare versions
    # with @rpms[new_rpm.n] on the next round
    @index[new_rpm.nevra] = curr_rpm

    # these are overwritten for existing packages
    if new_rpm.available
      @available << curr_rpm
    end
    if new_rpm.installed
      @installed << curr_rpm
    end
  end
end

#sizeObject Also known as: length


596
597
598
# File 'lib/chef/provider/package/yum/rpm_utils.rb', line 596

def size
  @rpms.size
end

#whatprovides(rpmdep) ⇒ Object


617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
# File 'lib/chef/provider/package/yum/rpm_utils.rb', line 617

def whatprovides(rpmdep)
  unless rpmdep.is_a?(RPMDependency)
    raise ArgumentError, "Expecting an RPMDependency object"
  end

  what = []

  packages = lookup_provides(rpmdep.name)
  if packages
    packages.each do |pkg|
      pkg.provides.each do |provide|
        if provide.satisfy?(rpmdep)
          what << pkg
        end
      end
    end
  end

  what
end