diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-09-03 01:49:17 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-09-03 01:49:17 +0000 |
commit | 42812f8512493d319b71bcc749e1760443ee8ecc (patch) | |
tree | f304f6eacfec2383f9378073ed5f365fb9fc8754 | |
parent | fd864286ab88ae674de45fbbb0717f2b7c2182c4 (diff) | |
download | puppet-42812f8512493d319b71bcc749e1760443ee8ecc.tar.gz puppet-42812f8512493d319b71bcc749e1760443ee8ecc.tar.xz puppet-42812f8512493d319b71bcc749e1760443ee8ecc.zip |
Applying the patch from #253 plus tests.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1533 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r-- | lib/puppet/type/pfile.rb | 7 | ||||
-rwxr-xr-x | lib/puppet/type/pfile/source.rb | 9 | ||||
-rwxr-xr-x | test/types/filesources.rb | 40 |
3 files changed, 55 insertions, 1 deletions
diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb index a6892c88e..3dd201baa 100644 --- a/lib/puppet/type/pfile.rb +++ b/lib/puppet/type/pfile.rb @@ -113,6 +113,13 @@ module Puppet end end + newparam(:replace) do + desc "Whether or not to replace a file that is + sourced but exists. This is useful for using file sources + purely for initialization." + defaultto true + end + newparam(:ignore) do desc "A parameter which omits action on files matching specified patterns during recursion. Uses Ruby's builtin globbing diff --git a/lib/puppet/type/pfile/source.rb b/lib/puppet/type/pfile/source.rb index c0bfab310..1d00f7a3d 100755 --- a/lib/puppet/type/pfile/source.rb +++ b/lib/puppet/type/pfile/source.rb @@ -132,7 +132,14 @@ module Puppet self.info "File does not have checksum" @is = :absent end - + # if replace => false then fake the checksum so that the file + # is not overwritten. + unless @is == :absent + unless @parent[:replace] + info "Not replacing existing file" + @is = @stats[:checksum] + end + end @should = [@stats[:checksum]] # If we're a directory, then do not copy anything, and instead just # create the directory using the 'create' state. diff --git a/test/types/filesources.rb b/test/types/filesources.rb index fa4d015ab..009d1a35a 100755 --- a/test/types/filesources.rb +++ b/test/types/filesources.rb @@ -607,6 +607,46 @@ class TestFileSources < Test::Unit::TestCase assert(FileTest.exists?(newpath), "Did not create file") assert_equal("yayness\n", File.read(newpath)) end + + # Make sure files aren't replaced when replace is false, but otherwise + # are. + def test_replace + source = tempfile() + File.open(source, "w") { |f| f.puts "yayness" } + + dest = tempfile() + file = Puppet::Type.newfile( + :path => dest, + :source => source, + :recurse => true + ) + + + assert_apply(file) + + assert(FileTest.exists?(dest), "Did not create file") + assert_equal("yayness\n", File.read(dest)) + + # Now set :replace + assert_nothing_raised { + file[:replace] = false + } + + File.open(source, "w") { |f| f.puts "funtest" } + assert_apply(file) + + # Make sure it doesn't change. + assert_equal("yayness\n", File.read(dest)) + + # Now set it to true and make sure it does change. + assert_nothing_raised { + file[:replace] = true + } + assert_apply(file) + + # Make sure it doesn't change. + assert_equal("funtest\n", File.read(dest)) + end end # $Id$ |