summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-09-03 02:12:43 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-09-03 02:12:43 +0000
commit18320ee5144c76de4d1d2c5c0fa27fd719882991 (patch)
treeb77910e73ff254b00e0c96d0bcbb3df746819c95
parent7fd5b6f91c207efe26a4d296a03be82ec2cdb03d (diff)
Adding a "force" parameter in files to fix #242. Currently only used when replacing directories with links, but should probably be used in other places.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1538 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r--lib/puppet/type/pfile.rb4
-rw-r--r--lib/puppet/type/pfile/target.rb7
-rw-r--r--test/types/file.rb10
3 files changed, 18 insertions, 3 deletions
diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb
index ab990d67b..8a12ee32a 100644
--- a/lib/puppet/type/pfile.rb
+++ b/lib/puppet/type/pfile.rb
@@ -296,7 +296,9 @@ module Puppet
when String:
newfile = file + backup
# Just move it, since it's a directory.
- if FileTest.exists?(newfile)
+ if FileTest.directory?(newfile)
+ raise Puppet::Error, "Will not replace directory backup; use a filebucket"
+ elsif FileTest.exists?(newfile)
begin
File.unlink(newfile)
rescue => detail
diff --git a/lib/puppet/type/pfile/target.rb b/lib/puppet/type/pfile/target.rb
index 04f2c986e..4a725d652 100644
--- a/lib/puppet/type/pfile/target.rb
+++ b/lib/puppet/type/pfile/target.rb
@@ -28,7 +28,12 @@ module Puppet
case stat.ftype
when "directory":
- FileUtils.rmtree(@parent[:path])
+ if @parent[:force] == :true
+ FileUtils.rmtree(@parent[:path])
+ else
+ notice "Not replacing directory with link; use 'force' to override"
+ return :nochange
+ end
else
File.unlink(@parent[:path])
end
diff --git a/test/types/file.rb b/test/types/file.rb
index 551d96d89..1d962ee30 100644
--- a/test/types/file.rb
+++ b/test/types/file.rb
@@ -1194,10 +1194,18 @@ class TestFile < Test::Unit::TestCase
assert_nothing_raised {
file = Puppet.type(:file).create(
:ensure => path,
- :path => link
+ :path => link,
+ :backup => false
)
}
+ # First run through without :force
+ assert_events([], file)
+
+ assert(FileTest.directory?(link), "Link replaced dir without force")
+
+ assert_nothing_raised { file[:force] = true }
+
assert_events([:link_created], file)
assert(FileTest.symlink?(link), "Link was not created")