From 18320ee5144c76de4d1d2c5c0fa27fd719882991 Mon Sep 17 00:00:00 2001 From: luke Date: Sun, 3 Sep 2006 02:12:43 +0000 Subject: 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 --- lib/puppet/type/pfile.rb | 4 +++- lib/puppet/type/pfile/target.rb | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'lib') 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 -- cgit