diff options
| author | Aaron Patterson <tenderlove@ruby-lang.org> | 2025-09-11 17:27:02 +0900 |
|---|---|---|
| committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2025-09-16 17:17:32 +0900 |
| commit | ca9c0f91311e01625e10272798ff2cc831bbee60 (patch) | |
| tree | 1b8f6d8e6cf8d5ecd6418189ac7b92fe1bbada1f | |
| parent | 674e1d2a5ffe8bfe4b0b691e151492af8287a558 (diff) | |
[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
| -rw-r--r-- | lib/rubygems/package.rb | 10 |
1 files 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 |
