summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2017-08-09 16:22:03 -0700
committerTim Smith <tsmith@chef.io>2017-08-09 16:22:03 -0700
commitd9bb471106a5ddbe154fa28bebd719ea9d267c07 (patch)
tree7ff6de5dc537a95281de31374654160bfe76a0d5
parent70eef6e0eea010420de4751d13164c3748a299c1 (diff)
downloadchef-d9bb471106a5ddbe154fa28bebd719ea9d267c07.tar.gz
Avoid extra refresh resource and handle repos with spaceszypper
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/provider/zypper_repository.rb22
1 files changed, 12 insertions, 10 deletions
diff --git a/lib/chef/provider/zypper_repository.rb b/lib/chef/provider/zypper_repository.rb
index b0b6e3aefd..83d3f9982e 100644
--- a/lib/chef/provider/zypper_repository.rb
+++ b/lib/chef/provider/zypper_repository.rb
@@ -20,6 +20,7 @@ require "chef/resource"
require "chef/dsl/declare_resource"
require "chef/mixin/which"
require "chef/provider/noop"
+require "shellwords"
class Chef
class Provider
@@ -35,7 +36,7 @@ class Chef
end
action :create do
- declare_resource(:template, "/etc/zypp/repos.d/#{new_resource.repo_name}.repo") do
+ declare_resource(:template, "/etc/zypp/repos.d/#{escaped_repo_name}.repo") do
if template_available?(new_resource.source)
source new_resource.source
else
@@ -45,29 +46,30 @@ class Chef
sensitive new_resource.sensitive
variables(config: new_resource)
mode new_resource.mode
- notifies :run, "execute[zypper --non-interactive refresh #{new_resource.repo_name}]", :immediately if new_resource.refresh_cache
- end
-
- declare_resource(:execute, "zypper --non-interactive refresh #{new_resource.repo_name}") do
- action :nothing
+ notifies :refresh, new_resource, :immediately if new_resource.refresh_cache
end
end
action :delete do
- declare_resource(:execute, "zypper removerepo #{new_resource.repo_name}") do
- only_if "zypper lr #{new_resource.repo_name}"
+ declare_resource(:execute, "zypper removerepo #{escaped_repo_name}") do
+ only_if "zypper lr #{escaped_repo_name}"
end
end
action :refresh do
- declare_resource(:execute, "zypper refresh #{new_resource.repo_name}") do
- only_if "zypper lr #{new_resource.repo_name}"
+ declare_resource(:execute, "zypper refresh #{escaped_repo_name}") do
+ only_if "zypper lr #{escaped_repo_name}"
end
end
alias_method :action_add, :action_create
alias_method :action_remove, :action_delete
+ # zypper repos are allowed to have spaces in the names
+ def escaped_repo_name
+ Shellwords.escape(new_resource.repo_name)
+ end
+
def template_available?(path)
!path.nil? && run_context.has_template_in_cookbook?(new_resource.cookbook_name, path)
end