Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Feb 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions Library/Homebrew/utils/gzip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ def compress_with_options(path, mtime: ENV["SOURCE_DATE_EPOCH"].to_i, orig_name:
# 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.
Comment on lines 28 to +32
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing worth considering here: making this change might mean that this is a workaround we'll have to carry around forever, since changing this will change the checksum of some bottles (and hence bottling would not be reproducible).

However, this might be a property of any workaround we try, so I'm not sure what the right thing to do is.

If the above is correct, then the comment will need to be amended accordingly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How many bottles does this affect in practice? If it's just one or two that's getting (semi-)frequent bottle updates anyway then it's probably ok.

I hope we're not stuck with Ruby 2.6 for that long (Ruby 2.7 has the bugfix) but I guess we'll see come June.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far that I know of? Only one at Homebrew/homebrew-core#123724. But throwing an error here is relatively new, so there could be more. Presumably @alebcay spotted some others which is what prompted throwing an error here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@carlocab Does this change the checksum of any existing bottles?

I hope we're not stuck with Ruby 2.6 for that long (Ruby 2.7 has the bugfix) but I guess we'll see come June.

I think we could bump the requirement for CI/dev-cmd before that but probably want to assume end-users may be running it for a while longer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far that I know of? Only one at Homebrew/homebrew-core#123724. But throwing an error here is relatively new, so there could be more. Presumably @alebcay spotted some others which is what prompted throwing an error here.

I noticed this because my initial sanity testing with GzipWriter (in brew irb) was with mtime of 0. That's how I discovered the corner case.

I actually didn't know of any actual need we had for setting mtime of 0, this is the first I'm hearing of it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@carlocab Does this change the checksum of any existing bottles?

If it does, it would be because their checksums were not reproducible. @alebcay also points this out. Making this change will make their checksums reproducible (as long as we never remove the bit that does mtime = 1 if mtime.zero?).

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|
Expand Down