summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoah Kantrowitz <noah@coderanger.net>2018-05-13 14:34:07 -0400
committerNoah Kantrowitz <noah@coderanger.net>2018-05-13 14:34:07 -0400
commit030ca69360ebcdbbcc5381c253b1fc85b8dbfa89 (patch)
treeef3a07db509857d804a2ca42e408fdea85e67249
parente4b4eeb7c3fa248daa577a5f7e6574ce90bde5ad (diff)
downloadchef-repo_name.tar.gz
Make sure we clean up legacy repo file if it exists.repo_name
Signed-off-by: Noah Kantrowitz <noah@coderanger.net>
-rw-r--r--lib/chef/provider/apt_repository.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/chef/provider/apt_repository.rb b/lib/chef/provider/apt_repository.rb
index fa76ded26c..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,
@@ -79,6 +81,7 @@ class Chef
end
action :remove 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
@@ -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