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
|
# File 'lib/chef/provider/package/pacman.rb', line 33
def load_current_resource
@current_resource = Chef::Resource::Package.new(new_resource.name)
current_resource.package_name(new_resource.package_name)
current_resource.version = []
repos = %w{extra core community}
if ::File.exist?("/etc/pacman.conf")
pacman = ::File.read("/etc/pacman.conf")
repos = pacman.scan(/\[(.+)\]/).flatten
end
repos = Regexp.union(repos)
status = shell_out("pacman", "-Sl")
unless status.exitstatus == 0 || status.exitstatus == 1
raise Chef::Exceptions::Package, "pacman failed - #{status.inspect}!"
end
pkg_db_data = status.stdout
@candidate_version = []
package_name_array.each do |pkg|
pkg_data = pkg_db_data.match(/(#{repos}) #{pkg} (?<candidate>.*?-[0-9]+)(?<installed> \[.*?( (?<current>.*?-[0-9]+))?\])?\n/m)
unless pkg_data
raise Chef::Exceptions::Package, "pacman does not have a version of package #{pkg}"
end
@candidate_version << pkg_data[:candidate]
if pkg_data[:installed]
current_resource.version << (pkg_data[:current] || pkg_data[:candidate])
else
current_resource.version << nil
end
end
current_resource
end
|