Skip to content

Commit eb83847

Browse files
Eric Delaneypcarlisle
Eric Delaney
authored andcommitted
(PUP-1952) make Puppet::Util.replace_file() consistent
On MRI Ruby File.replace will raise an error if the path is a directory, However on JRuby it removes the directory and replaces it with a file. This detects the directory and raises an error consistent on both.
1 parent fbce129 commit eb83847

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

lib/puppet/util.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,11 @@ def replace_file(file, default_mode, &block)
631631
Puppet::Util::Windows::File.replace_file(FileSystem.path_string(file), tempfile.path)
632632

633633
else
634+
# MRI Ruby checks for this and raises an error, while JRuby removes the directory
635+
# and replaces it with a file. This makes the our version of replace_file() consistent
636+
if Puppet::FileSystem.exist?(file) && Puppet::FileSystem.directory?(file)
637+
raise Errno::EISDIR, _("Is a directory: %{directory}") % { directory: file }
638+
end
634639
File.rename(tempfile.path, Puppet::FileSystem.path_string(file))
635640
end
636641
ensure

0 commit comments

Comments
 (0)