diff --git a/lib/rubygems/util/atomic_file_writer.rb b/lib/rubygems/util/atomic_file_writer.rb index be9bf76e83b8..6f75e38d51f8 100644 --- a/lib/rubygems/util/atomic_file_writer.rb +++ b/lib/rubygems/util/atomic_file_writer.rb @@ -53,9 +53,9 @@ def self.open(file_name) if old_stat # Set correct permissions on new file begin - File.chown(old_stat.uid, old_stat.gid, tmp_path) + temp_file.chown(old_stat.uid, old_stat.gid) # This operation will affect filesystem ACL's - File.chmod(old_stat.mode, tmp_path) + temp_file.chmod(old_stat.mode) rescue Errno::EPERM, Errno::EACCES # Changing file ownership failed, moving on. end @@ -99,9 +99,7 @@ def self.open(file_name) # still be cut mid-character. def self.byteslice_at_char_boundary(string, max_bytesize) sliced = string.byteslice(0, max_bytesize) - if string.valid_encoding? - sliced = sliced.byteslice(0, sliced.bytesize - 1) until sliced.valid_encoding? - end + sliced.scrub!("") if string.valid_encoding? sliced end private_class_method :byteslice_at_char_boundary