# File lib/puppet/type/file.rb, line 698
698:   def write(property)
699:     remove_existing(:file)
700: 
701:     use_temporary_file = write_temporary_file?
702:     if use_temporary_file
703:       path = "#{self[:path]}.puppettmp_#{rand(10000)}"
704:       path = "#{self[:path]}.puppettmp_#{rand(10000)}" while File.exists?(path) or File.symlink?(path)
705:     else
706:       path = self[:path]
707:     end
708: 
709:     mode = self.should(:mode) # might be nil
710:     umask = mode ? 000 : 022
711:     mode_int = mode ? mode.to_i(8) : nil
712: 
713:     content_checksum = Puppet::Util.withumask(umask) { File.open(path, 'w', mode_int ) { |f| write_content(f) } }
714: 
715:     # And put our new file in place
716:     if use_temporary_file # This is only not true when our file is empty.
717:       begin
718:         fail_if_checksum_is_wrong(path, content_checksum) if validate_checksum?
719:         File.rename(path, self[:path])
720:       rescue => detail
721:         fail "Could not rename temporary file #{path} to #{self[:path]}: #{detail}"
722:       ensure
723:         # Make sure the created file gets removed
724:         File.unlink(path) if FileTest.exists?(path)
725:       end
726:     end
727: 
728:     # make sure all of the modes are actually correct
729:     property_fix
730: 
731:   end