summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorThom May <thom@chef.io>2016-01-20 17:06:42 +0000
committerThom May <thom@chef.io>2016-01-20 17:06:42 +0000
commit348d7367fa1d7d7bea0d49137679d3e6d4b77694 (patch)
tree14c123a015f23a12c4c67acb45aa0fb66fed0fca /lib
parent354cfa12ce137ef9128fdc6d2fa789e4ad5a60c7 (diff)
downloadchef-348d7367fa1d7d7bea0d49137679d3e6d4b77694.tar.gz
ensure that periodic files are created first
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/provider/apt_update.rb26
1 files changed, 18 insertions, 8 deletions
diff --git a/lib/chef/provider/apt_update.rb b/lib/chef/provider/apt_update.rb
index 498c83a3a6..05a871d864 100644
--- a/lib/chef/provider/apt_update.rb
+++ b/lib/chef/provider/apt_update.rb
@@ -30,17 +30,31 @@ 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
- shell_out!("apt-get -q update")
+ do_update
end
end
end
def action_update
converge_by "force update new lists of packages" do
- shell_out!("apt-get -q update")
+ do_update
end
end
@@ -49,12 +63,8 @@ class Chef
#
# @return [Boolean]
def apt_up_to_date?
- if ::File.exist?("/var/lib/apt/periodic/update-success-stamp") &&
- ::File.mtime("/var/lib/apt/periodic/update-success-stamp") > Time.now - new_resource.frequency
- true
- else
- false
- end
+ ::File.exist?("/var/lib/apt/periodic/update-success-stamp") &&
+ ::File.mtime("/var/lib/apt/periodic/update-success-stamp") > Time.now - new_resource.frequency
end
end