utils/gzip: set mtime = 1 when mtime == 0.

This allows us to bottle formulae whose source modified time is indeed
`0`.

Needed for Homebrew/homebrew-core#123724.
This commit is contained in:
Carlo Cabrera 2023-02-20 22:02:58 +08:00
parent a222a5bbc8
commit 55c75618fc
No known key found for this signature in database
GPG Key ID: C74D447FC549A1D0

View File

@ -28,11 +28,11 @@ module Utils
# Zlib::GzipWriter does not properly handle the case of setting mtime = 0:
# https://bugs.ruby-lang.org/issues/16285
#
# This was fixed in https://github.com/ruby/zlib/pull/10. Set mtime to 0 instead
# of raising exception once we are using zlib gem version 1.1.0 or newer.
# This was fixed in https://github.com/ruby/zlib/pull/10. Remove workaround
# once we are using zlib gem version 1.1.0 or newer.
if mtime.to_i.zero?
raise ArgumentError,
"Can't create reproducible gzip file without a valid mtime"
odebug "Setting `mtime = 1` to avoid zlib gem bug when `mtime == 0`."
mtime = 1
end
File.open(path, "rb") do |fp|