summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-02-08 16:38:45 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-02-08 16:38:45 +0000
commit8e4cf2289d7e29b044f3bad2d1e8011c3d0543b4 (patch)
treec025c6bf782a71f7402f856c34c05c8786bfc607
parent58db0ef2ba966334cd65a67a3dc0112af8f8dda2 (diff)
downloadpuppet-8e4cf2289d7e29b044f3bad2d1e8011c3d0543b4.tar.gz
puppet-8e4cf2289d7e29b044f3bad2d1e8011c3d0543b4.tar.xz
puppet-8e4cf2289d7e29b044f3bad2d1e8011c3d0543b4.zip
first bug fixed, where sources were not updating the checksum
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@882 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r--lib/puppet/type/pfile.rb14
-rwxr-xr-xlib/puppet/type/pfile/checksum.rb13
-rwxr-xr-xlib/puppet/type/pfile/source.rb6
-rwxr-xr-xtest/types/filesources.rb22
4 files changed, 48 insertions, 7 deletions
diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb
index 16193578f..2df134c8e 100644
--- a/lib/puppet/type/pfile.rb
+++ b/lib/puppet/type/pfile.rb
@@ -484,6 +484,14 @@ module Puppet
super
end
+ # This method assumes that the checksum types are all correct, and we
+ # just want to carry over the value.
+ def setchecksum(sum)
+ if @states.include? :checksum
+ @states[:checksum].checksum = sum
+ end
+ end
+
def stat(refresh = false)
if @stat.nil? or refresh == true
begin
@@ -565,10 +573,10 @@ module Puppet
# We put all of the states in separate files, because there are so many
# of them. The order these are loaded is important, because it determines
# the order they are in the state list.
- require 'puppet/type/pfile/ensure'
require 'puppet/type/pfile/checksum'
- require 'puppet/type/pfile/content'
- require 'puppet/type/pfile/source'
+ require 'puppet/type/pfile/content' # can create the file
+ require 'puppet/type/pfile/source' # can create the file
+ require 'puppet/type/pfile/ensure' # can create the file
require 'puppet/type/pfile/uid'
require 'puppet/type/pfile/group'
require 'puppet/type/pfile/mode'
diff --git a/lib/puppet/type/pfile/checksum.rb b/lib/puppet/type/pfile/checksum.rb
index eac454908..a71e3d7b8 100755
--- a/lib/puppet/type/pfile/checksum.rb
+++ b/lib/puppet/type/pfile/checksum.rb
@@ -20,6 +20,14 @@ module Puppet
@checktypes[0]
end
+ # Because source and content and whomever else need to set the checksum
+ # and do the updating, we provide a simple mechanism for doing so.
+ def checksum=(value)
+ @is = value
+ @should = [value]
+ self.updatesum
+ end
+
# Checksums need to invert how changes are printed.
def change_to_s
begin
@@ -228,6 +236,7 @@ module Puppet
# Store the new sum to the state db.
def updatesum
+ self.warning "Updating"
result = false
state = nil
unless state = @parent.cached(:checksums)
@@ -240,10 +249,6 @@ module Puppet
error = Puppet::Error.new("%s has invalid checksum" %
@parent.name)
raise error
- #elsif @should == :absent
- # error = Puppet::Error.new("%s has invalid 'should' checksum" %
- # @parent.name)
- # raise error
end
# if we're replacing, vs. updating
diff --git a/lib/puppet/type/pfile/source.rb b/lib/puppet/type/pfile/source.rb
index d6a11dd7a..4244080dd 100755
--- a/lib/puppet/type/pfile/source.rb
+++ b/lib/puppet/type/pfile/source.rb
@@ -275,6 +275,12 @@ module Puppet
[@parent.name, detail]
end
+ if @stats.include? :checksum
+ @parent.setchecksum @stats[:checksum]
+ else
+ raise Puppet::DevError, "We're somehow missing the remote checksum"
+ end
+
if exists
return :file_changed
else
diff --git a/test/types/filesources.rb b/test/types/filesources.rb
index a3fb358a6..51cbddf26 100755
--- a/test/types/filesources.rb
+++ b/test/types/filesources.rb
@@ -562,6 +562,28 @@ class TestFileSources < Test::Unit::TestCase
assert_equal("yee-haw", txt, "Contents do not match")
end
+
+ # Make sure that source-copying updates the checksum on the same run
+ def test_checksumchange
+ source = tempfile()
+ dest = tempfile()
+ File.open(dest, "w") { |f| f.puts "boo" }
+ File.open(source, "w") { |f| f.puts "yay" }
+
+ file = nil
+ assert_nothing_raised {
+ file = Puppet.type(:file).create(
+ :name => dest,
+ :source => source
+ )
+ }
+
+ file.retrieve
+
+ assert_events([:file_changed], file)
+ file.retrieve
+ assert_events([], file)
+ end
end
# $Id$