summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2013-11-06 16:05:54 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2013-11-11 12:20:56 -0800
commit1eb4ae02a49ba7dfee8e65fcd26777c9098329a7 (patch)
tree5b00458c1000d280f3aa3e9aecac4083817ebadd
parentfdb52d2ea01b232efd9011e4315277c03623115d (diff)
downloadchef-1eb4ae02a49ba7dfee8e65fcd26777c9098329a7.tar.gz
OC-10380: add polymorphism
-rw-r--r--lib/chef/provider/cookbook_file.rb8
-rw-r--r--lib/chef/provider/directory.rb7
-rw-r--r--lib/chef/provider/file.rb28
-rw-r--r--lib/chef/provider/remote_file.rb8
-rw-r--r--lib/chef/provider/template.rb8
-rw-r--r--spec/support/shared/unit/provider/file.rb2
6 files changed, 41 insertions, 20 deletions
diff --git a/lib/chef/provider/cookbook_file.rb b/lib/chef/provider/cookbook_file.rb
index d59950780f..18af70d415 100644
--- a/lib/chef/provider/cookbook_file.rb
+++ b/lib/chef/provider/cookbook_file.rb
@@ -38,6 +38,14 @@ class Chef
super
end
+ private
+
+ def managing_content?
+ return true if @new_resource.checksum
+ return true if !@new_resource.source.nil? && @action != :create_if_missing
+ false
+ end
+
end
end
end
diff --git a/lib/chef/provider/directory.rb b/lib/chef/provider/directory.rb
index e3d2b89f2e..067737b9d4 100644
--- a/lib/chef/provider/directory.rb
+++ b/lib/chef/provider/directory.rb
@@ -123,6 +123,13 @@ class Chef
end
end
end
+
+ private
+
+ def managing_content?
+ false
+ end
+
end
end
end
diff --git a/lib/chef/provider/file.rb b/lib/chef/provider/file.rb
index 12fa97e334..b2127d7c87 100644
--- a/lib/chef/provider/file.rb
+++ b/lib/chef/provider/file.rb
@@ -1,4 +1,4 @@
-
+#
# Author:: Adam Jacob (<adam@opscode.com>)
# Author:: Lamont Granquist (<lamont@opscode.com>)
# Copyright:: Copyright (c) 2008-2013 Opscode, Inc.
@@ -75,7 +75,7 @@ class Chef
@current_resource ||= Chef::Resource::File.new(@new_resource.name)
@current_resource.path(@new_resource.path)
if ::File.exists?(@current_resource.path) && ::File.file?(::File.realpath(@current_resource.path))
- if should_do_checksum?
+ if managing_content?
Chef::Log.debug("#{@new_resource} checksumming file at #{@new_resource.path}.")
@current_resource.checksum(checksum(@current_resource.path))
end
@@ -160,22 +160,12 @@ class Chef
private
- def should_do_checksum?
- if @current_resource.respond_to?(:checksum)
- case
- when @new_resource.checksum
- return true
- when @action == :create_if_missing
- return false
- when @new_resource.respond_to?(:source)
- return true
- when @new_resource.content.nil?
- return false
- else
- return true
- end
- end
- # We may be a File::Provider::Directory
+ # What to check in this resource to see if we're going to be actively managing
+ # content (for things like doing checksums in load_current_resource). Expected to
+ # be overridden in subclasses.
+ def managing_content?
+ return true if @new_resource.checksum
+ return true if !@new_resource.content.nil? && @action != :create_if_missing
false
end
@@ -350,7 +340,7 @@ class Chef
do_backup unless file_created?
deployment_strategy.deploy(tempfile.path, ::File.realpath(@new_resource.path))
Chef::Log.info("#{@new_resource} updated file contents #{@new_resource.path}")
- if should_do_checksum?
+ if managing_content?
@new_resource.checksum(checksum(@new_resource.path)) # for reporting
end
end
diff --git a/lib/chef/provider/remote_file.rb b/lib/chef/provider/remote_file.rb
index d62f4aa13c..ed99c0bb84 100644
--- a/lib/chef/provider/remote_file.rb
+++ b/lib/chef/provider/remote_file.rb
@@ -39,6 +39,14 @@ class Chef
super
end
+ private
+
+ def managing_content?
+ return true if @new_resource.checksum
+ return true if !@new_resource.source.nil? && @action != :create_if_missing
+ false
+ end
+
end
end
end
diff --git a/lib/chef/provider/template.rb b/lib/chef/provider/template.rb
index 217f9e56ec..555f4f14f0 100644
--- a/lib/chef/provider/template.rb
+++ b/lib/chef/provider/template.rb
@@ -52,6 +52,14 @@ class Chef
end
end
+ private
+
+ def managing_content?
+ return true if @new_resource.checksum
+ return true if !@new_resource.source.nil? && @action != :create_if_missing
+ false
+ end
+
end
end
end
diff --git a/spec/support/shared/unit/provider/file.rb b/spec/support/shared/unit/provider/file.rb
index 7efea1dd9e..8753937fc3 100644
--- a/spec/support/shared/unit/provider/file.rb
+++ b/spec/support/shared/unit/provider/file.rb
@@ -404,7 +404,7 @@ shared_examples_for Chef::Provider::File do
:for_reporting => diff_for_reporting )
diff.stub!(:diff).with(resource_path, tempfile_path).and_return(true)
provider.should_receive(:diff).at_least(:once).and_return(diff)
- provider.should_receive(:should_do_checksum?).at_least(:once).and_return(true)
+ provider.should_receive(:managing_content?).at_least(:once).and_return(true)
provider.should_receive(:checksum).with(tempfile_path).and_return(tempfile_sha256)
provider.should_receive(:checksum).with(resource_path).and_return(tempfile_sha256)
provider.deployment_strategy.should_receive(:deploy).with(tempfile_path, normalized_path)