diff options
author | Thom May <thom@chef.io> | 2016-01-21 11:05:21 +0000 |
---|---|---|
committer | Thom May <thom@chef.io> | 2016-01-21 11:05:21 +0000 |
commit | c21a286a4c46b9d30b8945bdd35c4e571b6f1137 (patch) | |
tree | d359cb641ec687c1854fb9263c1d6c6aa3c5ad68 /lib/chef | |
parent | 348d7367fa1d7d7bea0d49137679d3e6d4b77694 (diff) | |
download | chef-c21a286a4c46b9d30b8945bdd35c4e571b6f1137.tar.gz |
Dependency inject file locations
Diffstat (limited to 'lib/chef')
-rw-r--r-- | lib/chef/provider/apt_update.rb | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/lib/chef/provider/apt_update.rb b/lib/chef/provider/apt_update.rb index 05a871d864..d6d79bcf18 100644 --- a/lib/chef/provider/apt_update.rb +++ b/lib/chef/provider/apt_update.rb @@ -21,8 +21,13 @@ require "chef/resource/apt_update" class Chef class Provider class AptUpdate < Chef::Provider + include Chef::DSL::DeclareResource + provides :apt_update, os: "linux" + APT_CONF_DIR = "/etc/apt/apt.conf.d" + STAMP_DIR = "/var/lib/apt/periodic" + def whyrun_supported? true end @@ -30,20 +35,6 @@ class Chef def load_current_resource end - def do_update - %w{/var/lib/apt/periodic /etc/apt/apt.conf.d}.each do |d| - dir = Chef::Resource::Directory.new(d, run_context) - dir.recursive(true) - dir.run_action(:create_if_missing) - new_resource.updated_by_last_action(true) if dir.updated_by_last_action? - end - config = Chef::Resource::File.new("/etc/apt/apt.conf.d/15update-stamp", run_context) - config.content('APT::Update::Post-Invoke-Success {"touch /var/lib/apt/periodic/update-success-stamp 2>/dev/null || true";};') - config.run_action(:create) - new_resource.updated_by_last_action(true) if config.updated_by_last_action? - shell_out!("apt-get -q update") - end - def action_periodic if !apt_up_to_date? converge_by "update new lists of packages" do @@ -63,8 +54,22 @@ class Chef # # @return [Boolean] def apt_up_to_date? - ::File.exist?("/var/lib/apt/periodic/update-success-stamp") && - ::File.mtime("/var/lib/apt/periodic/update-success-stamp") > Time.now - new_resource.frequency + ::File.exist?("#{STAMP_DIR}/update-success-stamp") && + ::File.mtime("#{STAMP_DIR}/update-success-stamp") > Time.now - new_resource.frequency + end + + def do_update + [STAMP_DIR, APT_CONF_DIR].each do |d| + build_resource(:directory, d, caller[0]) do + recursive true + end.run_action(:create) + end + + build_resource(:file, "#{APT_CONF_DIR}/15update-stamp", caller[0]) do + content "APT::Update::Post-Invoke-Success {\"touch #{STAMP_DIR}/update-success-stamp 2>/dev/null || true\";};" + end.run_action(:create_if_missing) + + shell_out!("apt-get -q update") end end |