From 6d31408606bde5a9fc2c85f5b3360095d7f887b7 Mon Sep 17 00:00:00 2001 From: Bo Anderson Date: Wed, 5 May 2021 02:16:26 +0100 Subject: [PATCH] dev-cmd/bottle: make gzip creation consistent across platforms --- Library/Homebrew/dev-cmd/bottle.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb index 9acf1ee059..2608ae5931 100644 --- a/Library/Homebrew/dev-cmd/bottle.rb +++ b/Library/Homebrew/dev-cmd/bottle.rb @@ -10,6 +10,7 @@ require "cli/parser" require "utils/inreplace" require "erb" require "archive" +require "zlib" BOTTLE_ERB = <<-EOS bottle do @@ -29,6 +30,7 @@ BOTTLE_ERB = <<-EOS EOS MAXIMUM_STRING_MATCHES = 100 +GZIP_BUFFER_SIZE = 64 * 1024 module Homebrew extend T::Sig @@ -440,9 +442,14 @@ module Homebrew mv tar_path, relocatable_tar_path # Use gzip, faster to compress than bzip2, faster to uncompress than bzip2 # or an uncompressed tarball (and more bandwidth friendly). - safe_system "gzip", "-f", relocatable_tar_path + gz = Zlib::GzipWriter.open(bottle_path) + gz.mtime = tab.source_modified_time + gz.orig_name = relocatable_tar_path + File.open(relocatable_tar_path, "rb") do |tarfile| + gz.write(tarfile.read(GZIP_BUFFER_SIZE)) until tarfile.eof? + end + gz.close sudo_purge - mv "#{relocatable_tar_path}.gz", bottle_path end ohai "Detecting if #{local_filename} is relocatable..." if bottle_path.size > 1 * 1024 * 1024