diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-09-03 02:37:56 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-09-03 02:37:56 +0000 |
commit | ff18e5592467c4b8fe2cedf48cd8f9332e0eff32 (patch) | |
tree | e82086f972e4e432a9b70cda723d85997e7ffc82 | |
parent | 18320ee5144c76de4d1d2c5c0fa27fd719882991 (diff) | |
download | puppet-ff18e5592467c4b8fe2cedf48cd8f9332e0eff32.tar.gz puppet-ff18e5592467c4b8fe2cedf48cd8f9332e0eff32.tar.xz puppet-ff18e5592467c4b8fe2cedf48cd8f9332e0eff32.zip |
Adding support for file purging, as requested in #250. Any unmanaged files in a purge-enabled directory will be removed.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1539 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r-- | lib/puppet/type/pfile.rb | 21 | ||||
-rw-r--r-- | test/types/file.rb | 35 |
2 files changed, 55 insertions, 1 deletions
diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb index 8a12ee32a..ec666497d 100644 --- a/lib/puppet/type/pfile.rb +++ b/lib/puppet/type/pfile.rb @@ -160,6 +160,18 @@ module Puppet defaultto :ignore end + newparam(:purge) do + desc "Whether unmanaged files should be purged. If you have a filebucket + configured the purged files will be uploaded, but if you do not, + this will destroy data. Only use this option for generated + files unless you really know what you are doing. This option only + makes sense when recursively managing directories." + + defaultto :false + + newvalues(:true, :false) + end + autorequire(:file) do cur = [] pary = self[:path].split(File::SEPARATOR) @@ -675,7 +687,14 @@ module Puppet children.each { |file| file = File.basename(file) next if file =~ /^\.\.?$/ # skip . and .. - if child = self.newchild(file, true, :recurse => recurse) + options = {:recurse => recurse} + + if child = self.newchild(file, true, options) + # Mark any unmanaged files for removal if purge is set. + if self[:purge] == :true and child.implicit? + child[:ensure] = :absent + end + unless @children.include?(child) self.push child added.push file diff --git a/test/types/file.rb b/test/types/file.rb index 1d962ee30..3dc296cc0 100644 --- a/test/types/file.rb +++ b/test/types/file.rb @@ -1359,6 +1359,41 @@ class TestFile < Test::Unit::TestCase assert_equal("yayness", File.read(path), "Content did not get set correctly") end + + # Make sure unmanaged files can be purged. + def test_purge + sourcedir = tempfile() + destdir = tempfile() + Dir.mkdir(sourcedir) + Dir.mkdir(destdir) + sourcefile = File.join(sourcedir, "sourcefile") + dsourcefile = File.join(destdir, "sourcefile") + localfile = File.join(destdir, "localfile") + randfile = File.join(destdir, "random") + File.open(sourcefile, "w") { |f| f.puts "funtest" } + # this file should get removed + File.open(randfile, "w") { |f| f.puts "footest" } + + lfobj = Puppet::Type.newfile(:path => localfile, :content => "rahtest") + + destobj = Puppet::Type.newfile(:path => destdir, + :source => sourcedir, + :recurse => true) + + + assert_apply(lfobj, destobj) + + assert(FileTest.exists?(dsourcefile), "File did not get copied") + assert(FileTest.exists?(localfile), "File did not get created") + assert(FileTest.exists?(randfile), "File got prematurely purged") + + assert_nothing_raised { destobj[:purge] = true } + assert_apply(lfobj, destobj) + + assert(FileTest.exists?(dsourcefile), "File got purged") + assert(FileTest.exists?(localfile), "File got purged") + assert(! FileTest.exists?(randfile), "File did not get purged") + end end # $Id$ |