summaryrefslogtreecommitdiff
path: root/lib/chef/provider/package/yum/yum_cache.rb
blob: ce46a0fcfdcd1f758241d7a1feda15ce9eea8ecf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93

# Author:: Adam Jacob (<adam@chef.io>)
# Copyright:: Copyright 2008-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require_relative "python_helper"
require_relative "../../package"
require "singleton" unless defined?(Singleton)

#
# These are largely historical APIs, the YumCache object no longer exists and this is a
# fascade over the python helper class.  It should be considered deprecated-lite and
# no new APIs should be added and should be added to the python_helper instead.
#

class Chef
  class Provider
    class Package
      class Yum < Chef::Provider::Package
        class YumCache
          include Singleton

          def refresh
            python_helper.restart
          end

          def reload
            python_helper.restart
          end

          def reload_installed
            python_helper.restart
          end

          def reload_provides
            python_helper.restart
          end

          def reset
            python_helper.restart
          end

          def reset_installed
            python_helper.restart
          end

          def available_version(name, arch = nil)
            p = python_helper.package_query(:whatavailable, name, arch: arch)
            "#{p.version}.#{p.arch}" unless p.version.nil?
          end

          def installed_version(name, arch = nil)
            p = python_helper.package_query(:whatinstalled, name, arch: arch)
            "#{p.version}.#{p.arch}" unless p.version.nil?
          end

          def package_available?(name, arch = nil)
            p = python_helper.package_query(:whatavailable, name, arch: arch)
            !p.version.nil?
          end

          # NOTE that it is the responsibility of the python_helper to get these APIs correct and
          # we do not do any validation here that the e.g. version or arch matches the requested value
          # (because the bigger issue there is a buggy+broken python_helper -- so don't try to fix those
          # kinds of bugs here)
          def version_available?(name, version, arch = nil)
            p = python_helper.package_query(:whatavailable, name, version: version, arch: arch)
            !p.version.nil?
          end

          # @api private
          def python_helper
            @python_helper ||= PythonHelper.instance
          end

        end # YumCache
      end
    end
  end
end