-
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
Separate staging from download. #4402
Conversation
9fe31e0
to
272c206
Compare
272c206
to
031a3f7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a general comment it's not clear due to the file change what's been moved as-is and what's been changed. I'd suggest moving to unpack strategy in one PR (or at least one commit) and then making the relevant changes in another.
Library/Homebrew/unpack_strategy.rb
Outdated
magic_number = magic_number(path) | ||
|
||
strategies = [ | ||
JarUnpackStrategy, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be inferred somehow rather than hardcoded? If not, a class level constant feels a bit nicer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a class level constant feels a bit nicer.
Not sure how a constant could replace this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A frozen constant array of classes rather than a variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I thought you were talking about JarUnpackStrategy
.
Library/Homebrew/unpack_strategy.rb
Outdated
def self.from(download:); end | ||
|
||
def self.magic_number(path) | ||
File.binread(path, 252) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A constant explaining what 252
means would be good.
Library/Homebrew/unpack_strategy.rb
Outdated
|
||
# This is so that bad tarballs and zips produce good error messages. | ||
strategy ||= case path.extname | ||
when ".tar.gz", ".tgz", ".tar.bz2", ".tbz" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might want to add .tar.xz
here?
Library/Homebrew/unpack_strategy.rb
Outdated
end | ||
|
||
attr_reader :path, :magic_number | ||
private :magic_number |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's probably nicer to just use the instance variable.
Library/Homebrew/unpack_strategy.rb
Outdated
end | ||
end | ||
end | ||
private :pipe_to_tar |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you order these so you can have a single private
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm trying to follow the new RuboCop rule (which we disabled for now because of false positives). Basically, the private
should be next to the method, so it is much easier to tell if a method is private or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does that rule have an autocorrect? If not I think it's going to prove too painful to implement this consistently across the codebase (and I think remaining consistent for now would be better).
Library/Homebrew/unpack_strategy.rb
Outdated
end | ||
|
||
class UncompressedUnpackStrategy < UnpackStrategy | ||
def self.can_extract?(**) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nicer to avoid **
here I think.
Library/Homebrew/unpack_strategy.rb
Outdated
end | ||
|
||
def extract_to_dir(unpack_dir) | ||
if OS.mac? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use os/extend
(if it's needed, I'm not sure why it is)
Library/Homebrew/unpack_strategy.rb
Outdated
return true if magic_number.match?(/^.{257}ustar/n) | ||
|
||
# Check if `tar` can list the contents, then it can also extract it. | ||
IO.popen(["tar", "-t", "-f", path], err: File::NULL) { |stdout| !stdout.read(1).nil? } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do
form block here
Nothing has been moved as-is, because previously everything was just unpacked in |
031a3f7
to
9484b53
Compare
Sure; I'm suggesting this adaption happen in a future PR (or even separate commits in this one) and this one focuses on trying to just move things as-is. It's very difficult to review what's changed and what hasn't, as-is. |
27d629b
to
2395008
Compare
@@ -45,7 +46,9 @@ def ohai(*args) | |||
# Unpack {#cached_location} into the current working directory, and possibly | |||
# chdir into the newly-unpacked directory. | |||
# Unlike {Resource#stage}, this does not take a block. | |||
def stage; end | |||
def stage | |||
UnpackStrategy.detect(cached_location).extract(basename: basename_without_params) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stick .extract
on a new line, maybe?
@@ -384,7 +344,7 @@ def _fetch | |||
# Useful for installing jars. | |||
class NoUnzipCurlDownloadStrategy < CurlDownloadStrategy | |||
def stage | |||
cp cached_location, basename_without_params, preserve: true | |||
UncompressedUnpackStrategy.new(cached_location).extract(basename: basename_without_params) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stick .extract
on a new line, maybe?
quiet_safe_system cvspath, { quiet_flag: "-Q" }, "-d", @url, "login" if @url.include? "pserver" | ||
quiet_safe_system cvspath, { quiet_flag: "-Q" }, "-d", @url, "checkout", "-d", cache_filename, @module | ||
quiet_safe_system "cvs", { quiet_flag: "-Q" }, "-d", @url, "login" if @url.include? "pserver" | ||
quiet_safe_system "cvs", { quiet_flag: "-Q" }, "-d", @url, "checkout", "-d", cached_location.basename, @module, chdir: cached_location.dirname |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this line be split across a few? It's pretty long.
@@ -0,0 +1,5 @@ | |||
class ZipUnpackStrategy | |||
def extract_to_dir(unpack_dir, **) | |||
safe_system "ditto", "-x", "-k", "--", path, unpack_dir |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What makes this preferable to unzip
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This keeps Finder attributes intact.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's that needed for?
Library/Homebrew/unpack_strategy.rb
Outdated
end | ||
end | ||
end | ||
private :pipe_to_tar |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does that rule have an autocorrect? If not I think it's going to prove too painful to implement this consistently across the codebase (and I think remaining consistent for now would be better).
Library/Homebrew/unpack_strategy.rb
Outdated
path.directory? | ||
end | ||
|
||
def extract_to_dir(unpack_dir, **) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nicer to avoid ** here I think.
Library/Homebrew/unpack_strategy.rb
Outdated
end | ||
|
||
class P7ZipUnpackStrategy < UnpackStrategy | ||
def self.can_extract?(magic_number:, **) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nicer to avoid ** here I think (and everywhere below).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would you avoid these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specify the arguments that would be passed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then RuboCop will complain about unused arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@reitermarkus They can be prefixed with _
and there may be other options depending on the types of arguments (I could be wrong on this, though). I think that's preferable to accepting literally any number of random arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, there is a RuboCop setting to allow unused keyword arguments.
Library/Homebrew/unpack_strategy.rb
Outdated
return true if magic_number.match?(/\A.{257}ustar/n) | ||
|
||
# Check if `tar` can list the contents, then it can also extract it. | ||
IO.popen(["tar", "-t", "-f", path], err: File::NULL) do |stdout| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's go back to tf
here for consistency
Library/Homebrew/unpack_strategy.rb
Outdated
|
||
class ZipUnpackStrategy < UnpackStrategy | ||
def self.can_extract?(magic_number:, **) | ||
magic_number.match?(/\APK(\003\004|\005\006)/n) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels like there's maybe a nicer interface for this given pretty much all the self.can_extract
methods are the same?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't think of any, since some need more than just the magic number.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about the default implementation in UnpackStrategy
being magic_number.match?(magic_regex)
or something and each subclass can define magic_regex
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried it, but it only get's worse.
For example, XzUnpackStrategy < TarUnpackStrategy < FileUnpackStrategy
:
This needs to override the custom can_extract?
in TarUnpackStrategy
, so it will be exactly the same as in FileUnpackStrategy
again, and we also have to add a magic_regex
constant/method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, no worries, thanks for checking.
Library/Homebrew/unpack_strategy.rb
Outdated
return false unless magic_number.match?(/\ASQLite format 3\000/n) | ||
|
||
# Fossil database is made up of artifacts, so the `artifact` table must exist. | ||
Utils.popen_read("sqlite3", path, "select count(*) from sqlite_master where type = 'view' and name = 'artifact'").to_i == 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a long line; can it get split?
8a0b5be
to
8f55a8c
Compare
Library/Homebrew/unpack_strategy.rb
Outdated
path.directory? | ||
end | ||
|
||
def extract_to_dir(unpack_dir, **) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keyword args look good; can this have the final args named _
? Thanks.
Library/Homebrew/unpack_strategy.rb
Outdated
def extract_to_dir(unpack_dir, **) | ||
FileUtils.cp_r path.children, unpack_dir, preserve: true | ||
end | ||
private :extract_to_dir |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would still like to see this be consistent with the rest of Homebrew and, if you feel like it, a general fixup of the RuboCop rule after this is merged and consistent.
ea208f4
to
b0a58cb
Compare
@JCount and @MikeMcQuaid, one last look? |
b0a58cb
to
7d9250d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few nits, none of which is blocking so feel free to disagree with any of them. Nice work 👍
def quiet_safe_system(*args) | ||
safe_system(*expand_safe_system_args(args)) | ||
def basename_without_params | ||
return nil if @url.nil? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return unless @url
?
@@ -960,16 +886,23 @@ def repo_valid? | |||
(cached_location/"CVS").directory? | |||
end | |||
|
|||
def quiet_flag | |||
ARGV.verbose? ? nil : "-Q" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"-Q" if ARGV.verbose?
?
magic_number = if path.directory? | ||
"" | ||
else | ||
File.binread(path, MAX_MAGIC_NUMBER_LENGTH) || "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the ""
fallback in both cases I wonder if:
magic_number = File.binread(path, MAX_MAGIC_NUMBER_LENGTH) if path.directory?
magic_number ||= ""
or similar might be better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried some variations, but I like this version because it is more explicit.
Library/Homebrew/unpack_strategy.rb
Outdated
|
||
def extract_nested_tar(unpack_dir, basename:) | ||
return unless DependencyCollector.tar_needs_xz_dependency? | ||
return unless (children = unpack_dir.children).count == 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no real preference but if .. !=
sometimes reads nicer to me.
7d9250d
to
9b4e323
Compare
Should be ready to go now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, but let’s wait on @MikeMcQuaid before merging.
This has caused some Git checkouts to be unclean that were previously clean. For kubernetes-cli, Before:
After:
This is now causing CI failure for anything that checks that its build info reports a clean not dirty tag. |
This has broken the ability to install cromwell on El Capitan. See https://jenkins.brew.sh/job/Homebrew%20Testing/1023/ and https://jenkins.brew.sh/job/Homebrew%20Core%20Pull%20Requests/27643/
|
brew style
with your changes locally?brew tests
with your changes locally?Separate unpacking the download from download strategies. These unpack strategies should then also used in the
Container
classes used for staging casks.