summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-07-23 16:32:50 -0700
committerJames Turnbull <james@lovedthanlost.net>2009-07-24 10:27:11 +1000
commitf6d61455be01a1e81c2f48a720e83fbb646e9ab9 (patch)
tree171930e326afe9bfddfc7e206c256f54e04bb2e8
parentdb82523a0ec12fcd63b4b52173268b1e6c41df36 (diff)
downloadpuppet-f6d61455be01a1e81c2f48a720e83fbb646e9ab9.tar.gz
puppet-f6d61455be01a1e81c2f48a720e83fbb646e9ab9.tar.xz
puppet-f6d61455be01a1e81c2f48a720e83fbb646e9ab9.zip
Fixing #2421 - file renaming errors now propagate
Signed-off-by: Luke Kanies <luke@madstop.com>
-rw-r--r--lib/puppet/type/file.rb2
-rwxr-xr-xspec/unit/type/file.rb11
2 files changed, 12 insertions, 1 deletions
diff --git a/lib/puppet/type/file.rb b/lib/puppet/type/file.rb
index 55d4ec73b..4efd901e5 100644
--- a/lib/puppet/type/file.rb
+++ b/lib/puppet/type/file.rb
@@ -832,7 +832,7 @@ module Puppet
fail_if_checksum_is_wrong(path, checksum) if validate
File.rename(path, self[:path])
rescue => detail
- self.err "Could not rename tmp %s for replacing: %s" % [self[:path], detail]
+ fail "Could not rename temporary file %s to %s : %s" % [path, self[:path], detail]
ensure
# Make sure the created file gets removed
File.unlink(path) if FileTest.exists?(path)
diff --git a/spec/unit/type/file.rb b/spec/unit/type/file.rb
index 58cd4ad23..627cac41a 100755
--- a/spec/unit/type/file.rb
+++ b/spec/unit/type/file.rb
@@ -751,4 +751,15 @@ describe Puppet::Type.type(:file) do
file.finish
end
end
+
+ describe "when writing the file" do
+ it "should propagate failures encountered when renaming the temporary file" do
+ File.stubs(:open)
+
+ File.expects(:rename).raises ArgumentError
+ file = Puppet::Type::File.new(:name => "/my/file", :backup => "puppet")
+
+ lambda { file.write("something", :content) }.should raise_error(Puppet::Error)
+ end
+ end
end