summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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