diff options
author | Thom May <thom@may.lt> | 2018-05-14 15:37:07 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-14 15:37:07 +0100 |
commit | 3fd26f9a3d8265dce62937db19bec19a53035a39 (patch) | |
tree | 7246d8e8b4691de97ef3ee830a0cf7131c9817c8 | |
parent | 7360d4720479a6b29974aef61e20c387ca1d66d4 (diff) | |
parent | 030ca69360ebcdbbcc5381c253b1fc85b8dbfa89 (diff) | |
download | chef-3fd26f9a3d8265dce62937db19bec19a53035a39.tar.gz |
Merge pull request #7244 from chef/repo_name
apt_repository: Use the repo_name name property
-rw-r--r-- | lib/chef/provider/apt_repository.rb | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/lib/chef/provider/apt_repository.rb b/lib/chef/provider/apt_repository.rb index 91292929e6..973c10e94a 100644 --- a/lib/chef/provider/apt_repository.rb +++ b/lib/chef/provider/apt_repository.rb @@ -57,6 +57,8 @@ class Chef action :nothing end + cleanup_legacy_file! + repo = build_repo( new_resource.uri, new_resource.distribution, @@ -66,7 +68,7 @@ class Chef new_resource.deb_src ) - declare_resource(:file, "/etc/apt/sources.list.d/#{new_resource.name}.list") do + declare_resource(:file, "/etc/apt/sources.list.d/#{new_resource.repo_name}.list") do owner "root" group "root" mode "0644" @@ -79,9 +81,10 @@ class Chef end action :remove do - if ::File.exist?("/etc/apt/sources.list.d/#{new_resource.name}.list") - converge_by "Removing #{new_resource.name} repository from /etc/apt/sources.list.d/" do - declare_resource(:file, "/etc/apt/sources.list.d/#{new_resource.name}.list") do + cleanup_legacy_file! + if ::File.exist?("/etc/apt/sources.list.d/#{new_resource.repo_name}.list") + converge_by "Removing #{new_resource.repo_name} repository from /etc/apt/sources.list.d/" do + declare_resource(:file, "/etc/apt/sources.list.d/#{new_resource.repo_name}.list") do sensitive new_resource.sensitive action :delete notifies :update, "apt_update[#{new_resource.name}]", :immediately if new_resource.cache_rebuild @@ -93,7 +96,7 @@ class Chef end end else - logger.trace("/etc/apt/sources.list.d/#{new_resource.name}.list does not exist. Nothing to do") + logger.trace("/etc/apt/sources.list.d/#{new_resource.repo_name}.list does not exist. Nothing to do") end end @@ -325,6 +328,23 @@ class Chef repo << "deb-src #{info}\n" if add_src repo end + + # clean up a potentially legacy file from before we fixed the usage of + # new_resource.name vs. new_resource.repo_name. We might have the + # name.list file hanging around and need to clean it up. + # + # @return [void] + def cleanup_legacy_file! + legacy_path = "/etc/apt/sources.list.d/#{new_resource.name}.list" + if new_resource.name != new_resource.repo_name && ::File.exist?(legacy_path) + converge_by "Cleaning up legacy #{legacy_path} repo file" do + declare_resource(:file, legacy_path) do + action :delete + # Not triggering an update since it isn't super likely to be needed. + end + end + end + end end end end |