From ca9c0f91311e01625e10272798ff2cc831bbee60 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 11 Sep 2025 17:27:02 +0900 Subject: [rubygems/rubygems] Use File#chmod rather than FileUtils.chmod We already have the open file descriptor, so we can avoid the overhead of resolving the filepath (as well as the overhead inside `FileUtils`) by just calling `chmod` on the file descriptor itself. https://github.com/rubygems/rubygems/commit/60c14bbeee --- lib/rubygems/package.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/rubygems/package.rb b/lib/rubygems/package.rb index c855423ed7..99be691ec7 100644 --- a/lib/rubygems/package.rb +++ b/lib/rubygems/package.rb @@ -451,8 +451,14 @@ EOM end if entry.file? - File.open(destination, "wb") {|out| copy_stream(entry, out) } - FileUtils.chmod file_mode(entry.header.mode) & ~File.umask, destination + File.open(destination, "wb") do |out| + copy_stream(entry, out) + # Flush needs to happen before chmod because there could be data + # in the IO buffer that needs to be written, and that could be + # written after the chmod (on close) which would mess up the perms + out.flush + out.chmod file_mode(entry.header.mode) & ~File.umask + end end verbose destination -- cgit v1.2.3