language stringclasses 1
value | owner stringlengths 2 15 | repo stringlengths 2 21 | sha stringlengths 45 45 | message stringlengths 7 36.3k | path stringlengths 1 199 | patch stringlengths 15 102k | is_multipart bool 2
classes |
|---|---|---|---|---|---|---|---|
Other | Homebrew | brew | a6f25419aaaeb5fae3eb743d961ed7892ae86075.json | Update vendored gems
- backports to 3.11.4
- plist to 3.4.0 | Library/Homebrew/vendor/bundle-standalone/ruby/2.3.0/gems/plist-3.4.0/lib/plist/version.rb | @@ -1,5 +1,5 @@
# encoding: utf-8
module Plist
- VERSION = '3.3.0'.freeze
+ VERSION = '3.4.0'.freeze
end | true |
Other | Homebrew | brew | d44290571931b5c83934b31d97b58b8e2bc32c06.json | Upgrade: implement linkage repair
After upgrading existing kegs, we now search and upgrade their
dependents as well. If any are detected that have broken linkage, they
are reinstalled from source.
If there are any formulae in the dependents tree that are pinned, they
are only reinstalled if they're not outdated; in all cases, a suitable
message is printed detailing the kegs that will be acted upon. | Library/Homebrew/cmd/reinstall.rb | @@ -7,6 +7,7 @@
require "formula_installer"
require "development_tools"
require "messages"
+require "reinstall"
module Homebrew
module_function
@@ -26,59 +27,4 @@ def reinstall
end
Homebrew.messages.display_messages
end
-
- def reinstall_formula(f)
- if f.opt_prefix.directory?
- keg = Keg.new(f.opt_prefix.resolved_path)
- keg_had_linked_opt = true
- keg_was_linked = keg.linked?
- backup keg
- end
-
- build_options = BuildOptions.new(Options.create(ARGV.flags_only), f.options)
- options = build_options.used_options
- options |= f.build.used_options
- options &= f.options
-
- fi = FormulaInstaller.new(f)
- fi.options = options
- fi.invalid_option_names = build_options.invalid_option_names
- fi.build_bottle = ARGV.build_bottle? || (!f.bottled? && f.build.bottle?)
- fi.interactive = ARGV.interactive?
- fi.git = ARGV.git?
- fi.link_keg ||= keg_was_linked if keg_had_linked_opt
- fi.prelude
-
- oh1 "Reinstalling #{Formatter.identifier(f.full_name)} #{options.to_a.join " "}"
-
- fi.install
- fi.finish
- rescue FormulaInstallationAlreadyAttemptedError
- nil
- rescue Exception # rubocop:disable Lint/RescueException
- ignore_interrupts { restore_backup(keg, keg_was_linked) }
- raise
- else
- backup_path(keg).rmtree if backup_path(keg).exist?
- end
-
- def backup(keg)
- keg.unlink
- keg.rename backup_path(keg)
- end
-
- def restore_backup(keg, keg_was_linked)
- path = backup_path(keg)
-
- return unless path.directory?
-
- Pathname.new(keg).rmtree if keg.exist?
-
- path.rename keg
- keg.link if keg_was_linked
- end
-
- def backup_path(path)
- Pathname.new "#{path}.reinstall"
- end
end | true |
Other | Homebrew | brew | d44290571931b5c83934b31d97b58b8e2bc32c06.json | Upgrade: implement linkage repair
After upgrading existing kegs, we now search and upgrade their
dependents as well. If any are detected that have broken linkage, they
are reinstalled from source.
If there are any formulae in the dependents tree that are pinned, they
are only reinstalled if they're not outdated; in all cases, a suitable
message is printed detailing the kegs that will be acted upon. | Library/Homebrew/cmd/upgrade.rb | @@ -21,6 +21,7 @@
#: are pinned; see `pin`, `unpin`).
require "install"
+require "reinstall"
require "formula_installer"
require "cleanup"
require "development_tools"
@@ -80,6 +81,16 @@ def upgrade
puts formulae_upgrades.join(", ")
end
+ upgrade_formulae(formulae_to_install)
+
+ check_dependents(formulae_to_install)
+
+ Homebrew.messages.display_messages
+ end
+
+ def upgrade_formulae(formulae_to_install)
+ return if formulae_to_install.empty?
+
# Sort keg_only before non-keg_only formulae to avoid any needless conflicts
# with outdated, non-keg_only versions of formulae being upgraded.
formulae_to_install.sort! do |a, b|
@@ -104,7 +115,6 @@ def upgrade
onoe "#{f}: #{e}"
end
end
- Homebrew.messages.display_messages
end
def upgrade_formula(f)
@@ -171,4 +181,189 @@ def upgrade_formula(f)
nil
end
end
+
+ def upgradable_dependents(kegs, formulae)
+ formulae_to_upgrade = Set.new
+ formulae_pinned = Set.new
+
+ formulae.each do |formula|
+ descendants = Set.new
+
+ dependents = kegs.select do |keg|
+ keg.runtime_dependencies
+ .any? { |d| d["full_name"] == formula.full_name }
+ end
+
+ next if dependents.empty?
+
+ dependent_formulae = dependents.map(&:to_formula)
+
+ dependent_formulae.each do |f|
+ next if formulae_to_upgrade.include?(f)
+ next if formulae_pinned.include?(f)
+
+ if f.outdated?(fetch_head: ARGV.fetch_head?)
+ if f.pinned?
+ formulae_pinned << f
+ else
+ formulae_to_upgrade << f
+ end
+ end
+
+ descendants << f
+ end
+
+ upgradable_descendants, pinned_descendants = upgradable_dependents(kegs, descendants)
+
+ formulae_to_upgrade.merge upgradable_descendants
+ formulae_pinned.merge pinned_descendants
+ end
+
+ [formulae_to_upgrade, formulae_pinned]
+ end
+
+ def broken_dependents(kegs, formulae)
+ formulae_to_reinstall = Set.new
+ formulae_pinned_and_outdated = Set.new
+
+ CacheStoreDatabase.use(:linkage) do |db|
+ formulae.each do |formula|
+ descendants = Set.new
+
+ dependents = kegs.select do |keg|
+ keg.runtime_dependencies
+ .any? { |d| d["full_name"] == formula.full_name }
+ end
+
+ next if dependents.empty?
+
+ dependents.each do |keg|
+ f = keg.to_formula
+
+ next if formulae_to_reinstall.include?(f)
+ next if formulae_pinned_and_outdated.include?(f)
+
+ checker = LinkageChecker.new(keg, cache_db: db)
+
+ if checker.broken_library_linkage?
+ if f.outdated?(fetch_head: ARGV.fetch_head?)
+ # Outdated formulae = pinned formulae (see function above)
+ formulae_pinned_and_outdated << f
+ else
+ formulae_to_reinstall << f
+ end
+ end
+
+ descendants << f
+ end
+
+ descendants_to_reinstall, descendants_pinned = broken_dependents(kegs, descendants)
+
+ formulae_to_reinstall.merge descendants_to_reinstall
+ formulae_pinned_and_outdated.merge descendants_pinned
+ end
+ end
+
+ [formulae_to_reinstall, formulae_pinned_and_outdated]
+ end
+
+ # @private
+ def depends_on(a, b)
+ if a.opt_or_installed_prefix_keg
+ .runtime_dependencies
+ .any? { |d| d["full_name"] == b.full_name }
+ 1
+ else
+ a <=> b
+ end
+ end
+
+ # @private
+ def formulae_with_runtime_dependencies
+ Formula.installed
+ .map(&:opt_or_installed_prefix_keg)
+ .reject(&:nil?)
+ .reject { |f| f.runtime_dependencies.to_a.empty? }
+ end
+
+ def check_dependents(formulae)
+ return if formulae.empty?
+
+ # First find all the outdated dependents.
+ kegs = formulae_with_runtime_dependencies
+
+ return if kegs.empty?
+
+ oh1 "Checking dependents for outdated formulae" if ARGV.verbose?
+ upgradable, pinned = upgradable_dependents(kegs, formulae).map(&:to_a)
+
+ upgradable.sort! { |a, b| depends_on(a, b) }
+
+ pinned.sort! { |a, b| depends_on(a, b) }
+
+ # Print the pinned dependents.
+ unless pinned.empty?
+ ohai "Not upgrading #{Formatter.pluralize(pinned.length, "pinned dependent")}:"
+ puts pinned.map { |f| "#{f.full_specified_name} #{f.pkg_version}" } * ", "
+ end
+
+ # Print the upgradable dependents.
+ if upgradable.empty?
+ ohai "No dependents to upgrade" if ARGV.verbose?
+ else
+ ohai "Upgrading #{Formatter.pluralize(upgradable.length, "dependent")}:"
+ formulae_upgrades = upgradable.map do |f|
+ if f.optlinked?
+ "#{f.full_specified_name} #{Keg.new(f.opt_prefix).version} -> #{f.pkg_version}"
+ else
+ "#{f.full_specified_name} #{f.pkg_version}"
+ end
+ end
+ puts formulae_upgrades.join(", ")
+ end
+
+ upgrade_formulae(upgradable)
+
+ # Assess the dependents tree again.
+ kegs = formulae_with_runtime_dependencies
+
+ oh1 "Checking dependents for broken library links" if ARGV.verbose?
+ reinstallable, pinned = broken_dependents(kegs, formulae).map(&:to_a)
+
+ reinstallable.sort! { |a, b| depends_on(a, b) }
+
+ pinned.sort! { |a, b| depends_on(a, b) }
+
+ # Print the pinned dependents.
+ unless pinned.empty?
+ onoe "Not reinstalling #{Formatter.pluralize(pinned.length, "broken and outdated, but pinned dependent")}:"
+ $stderr.puts pinned.map { |f| "#{f.full_specified_name} #{f.pkg_version}" } * ", "
+ end
+
+ # Print the broken dependents.
+ if reinstallable.empty?
+ ohai "No broken dependents to reinstall" if ARGV.verbose?
+ else
+ ohai "Reinstalling #{Formatter.pluralize(reinstallable.length, "broken dependent")} from source:"
+ puts reinstallable.map(&:full_specified_name).join(", ")
+ end
+
+ reinstallable.each do |f|
+ begin
+ reinstall_formula(f, build_from_source: true)
+ rescue FormulaInstallationAlreadyAttemptedError
+ # We already attempted to reinstall f as part of the dependency tree of
+ # another formula. In that case, don't generate an error, just move on.
+ nil
+ rescue CannotInstallFormulaError => e
+ ofail e
+ rescue BuildError => e
+ e.dump
+ puts
+ Homebrew.failed = true
+ rescue DownloadError => e
+ ofail e
+ end
+ end
+ end
end | true |
Other | Homebrew | brew | d44290571931b5c83934b31d97b58b8e2bc32c06.json | Upgrade: implement linkage repair
After upgrading existing kegs, we now search and upgrade their
dependents as well. If any are detected that have broken linkage, they
are reinstalled from source.
If there are any formulae in the dependents tree that are pinned, they
are only reinstalled if they're not outdated; in all cases, a suitable
message is printed detailing the kegs that will be acted upon. | Library/Homebrew/reinstall.rb | @@ -0,0 +1,63 @@
+require "formula_installer"
+require "development_tools"
+require "messages"
+
+module Homebrew
+ module_function
+
+ def reinstall_formula(f, build_from_source: false)
+ if f.opt_prefix.directory?
+ keg = Keg.new(f.opt_prefix.resolved_path)
+ keg_had_linked_opt = true
+ keg_was_linked = keg.linked?
+ backup keg
+ end
+
+ build_options = BuildOptions.new(Options.create(ARGV.flags_only), f.options)
+ options = build_options.used_options
+ options |= f.build.used_options
+ options &= f.options
+
+ fi = FormulaInstaller.new(f)
+ fi.options = options
+ fi.invalid_option_names = build_options.invalid_option_names
+ fi.build_bottle = ARGV.build_bottle? || (!f.bottled? && f.build.bottle?)
+ fi.interactive = ARGV.interactive?
+ fi.git = ARGV.git?
+ fi.link_keg ||= keg_was_linked if keg_had_linked_opt
+ fi.build_from_source = true if build_from_source
+ fi.prelude
+
+ oh1 "Reinstalling #{Formatter.identifier(f.full_name)} #{options.to_a.join " "}"
+
+ fi.install
+ fi.finish
+ rescue FormulaInstallationAlreadyAttemptedError
+ nil
+ rescue Exception # rubocop:disable Lint/RescueException
+ ignore_interrupts { restore_backup(keg, keg_was_linked) }
+ raise
+ else
+ backup_path(keg).rmtree if backup_path(keg).exist?
+ end
+
+ def backup(keg)
+ keg.unlink
+ keg.rename backup_path(keg)
+ end
+
+ def restore_backup(keg, keg_was_linked)
+ path = backup_path(keg)
+
+ return unless path.directory?
+
+ Pathname.new(keg).rmtree if keg.exist?
+
+ path.rename keg
+ keg.link if keg_was_linked
+ end
+
+ def backup_path(path)
+ Pathname.new "#{path}.reinstall"
+ end
+end | true |
Other | Homebrew | brew | d44290571931b5c83934b31d97b58b8e2bc32c06.json | Upgrade: implement linkage repair
After upgrading existing kegs, we now search and upgrade their
dependents as well. If any are detected that have broken linkage, they
are reinstalled from source.
If there are any formulae in the dependents tree that are pinned, they
are only reinstalled if they're not outdated; in all cases, a suitable
message is printed detailing the kegs that will be acted upon. | Library/Homebrew/test/cmd/upgrade_spec.rb | @@ -7,4 +7,14 @@
expect(HOMEBREW_CELLAR/"testball/0.1").to be_a_directory
end
+
+ it "upgrades a Formula and cleans up old versions" do
+ setup_test_formula "testball"
+ (HOMEBREW_CELLAR/"testball/0.0.1/foo").mkpath
+
+ expect { brew "upgrade", "--cleanup" }.to be_a_success
+
+ expect(HOMEBREW_CELLAR/"testball/0.1").to be_a_directory
+ expect(HOMEBREW_CELLAR/"testball/0.0.1").not_to exist
+ end
end | true |
Other | Homebrew | brew | e6409f6a096bc458e97ebed216dc19ddddaa3edf.json | Increase the unit test coverage of messages.rb
This increases the messages.rb unit test coverage to 100%. | Library/Homebrew/test/messages_spec.rb | @@ -2,49 +2,109 @@
require "spec_helper"
describe Messages do
- before do
- @m = Messages.new
- f_foo = formula("foo") do
- url "https://example.com/foo-0.1.tgz"
- end
- f_bar = formula("bar") do
- url "https://example.com/bar-0.1.tgz"
- end
- f_baz = formula("baz") do
- url "https://example.com/baz-0.1.tgz"
- end
- @m.formula_installed(f_foo, 1.1)
- @m.record_caveats(f_foo, "Zsh completions were installed")
- @m.formula_installed(f_bar, 2.2)
- @m.record_caveats(f_bar, "Keg-only formula")
- @m.formula_installed(f_baz, 3.3)
- @m.record_caveats(f_baz, "A valid GOPATH is required to use the go command")
- end
+ let(:messages) { Messages.new }
+ let(:test_formula) { formula("foo") { url("https://example.com/foo-0.1.tgz") } }
+ let(:elapsed_time) { 1.1 }
- it "has the right installed-formula count" do
- expect(@m.formula_count).to equal(3)
+ describe "#record_caveats" do
+ it "adds a caveat" do
+ expect {
+ messages.record_caveats(test_formula, "Zsh completions were installed")
+ }.to change { messages.caveats.count }.by(1)
+ end
end
- it "has recorded caveats" do
- expect(@m.caveats).to_not be_empty
- end
+ describe "#formula_installed" do
+ it "increases the formula count" do
+ expect {
+ messages.formula_installed(test_formula, elapsed_time)
+ }.to change { messages.formula_count }.by(1)
+ end
- it "maintained the order of recorded caveats" do
- caveats_formula_order = @m.caveats.map { |x| x[:formula] }
- expect(caveats_formula_order).to eq(["foo", "bar", "baz"])
+ it "adds to install_times" do
+ expect {
+ messages.formula_installed(test_formula, elapsed_time)
+ }.to change { messages.install_times.count }.by(1)
+ end
end
- it "has recorded installation times" do
- expect(@m.install_times).to_not be_empty
- end
+ describe "#display_messages" do
+ context "when formula_count is less than two" do
+ before do
+ messages.record_caveats(test_formula, "Zsh completions were installed")
+ messages.formula_installed(test_formula, elapsed_time)
+ end
- it "maintained the order of install times" do
- formula_order = @m.install_times.map { |x| x[:formula] }
- expect(formula_order).to eq(["foo", "bar", "baz"])
- end
+ it "doesn't print caveat details" do
+ expect { messages.display_messages }.not_to output.to_stdout
+ end
+ end
+
+ context "when caveats is empty" do
+ before do
+ messages.formula_installed(test_formula, elapsed_time)
+ end
+
+ it "doesn't print caveat details" do
+ expect { messages.display_messages }.not_to output.to_stdout
+ end
+ end
- it "recorded the right install times" do
- times = @m.install_times.map { |x| x[:time] }
- expect(times).to eq([1.1, 2.2, 3.3])
+ context "when formula_count is greater than one and caveats are present" do
+ let(:test_formula2) { formula("bar") { url("https://example.com/bar-0.1.tgz") } }
+
+ before do
+ messages.record_caveats(test_formula, "Zsh completions were installed")
+ messages.formula_installed(test_formula, elapsed_time)
+ messages.formula_installed(test_formula2, elapsed_time)
+ end
+
+ it "prints caveat details" do
+ expect { messages.display_messages }.to output(
+ <<~EOS
+ ==> Caveats
+ ==> foo
+ Zsh completions were installed
+ EOS
+ ).to_stdout
+ end
+ end
+
+ context "when the --display-times argument is present" do
+ before do
+ allow(ARGV).to receive(:include?).with("--display-times").and_return(true)
+ end
+
+ context "when install_times is empty" do
+ it "doesn't print any output" do
+ expect { messages.display_messages }.not_to output.to_stdout
+ end
+ end
+
+ context "when install_times is present" do
+ before do
+ messages.formula_installed(test_formula, elapsed_time)
+ end
+
+ it "prints installation times" do
+ expect { messages.display_messages }.to output(
+ <<~EOS
+ ==> Installation times
+ foo 1.100 s
+ EOS
+ ).to_stdout
+ end
+ end
+ end
+
+ context "when the --display-times argument isn't present" do
+ before do
+ allow(ARGV).to receive(:include?).with("--display-times").and_return(false)
+ end
+
+ it "doesn't print installation times" do
+ expect { messages.display_messages }.not_to output.to_stdout
+ end
+ end
end
end | false |
Other | Homebrew | brew | a9d363fdfed53803955903374ae2cc8bf76251bd.json | docs/Maintainer-Guidelines: retire lead maintainer position in Febuary. | docs/Maintainer-Guidelines.md | @@ -152,3 +152,22 @@ In the same way that Homebrew maintainers are expected to be spending more of th
Individual Homebrew repositories should not have formal lead maintainers (although those who do the most work will have the loudest voices).
Maintainers should feel even more free to pleasantly disagree with the work and decisions of the lead maintainer: with greater authority comes greater responsibility to handle and moderate technical disagreements.
+
+Homebrew's last lead maintainer will be Mike McQuaid. On February 1st, Mike will step down as lead maintainer of Homebrew and his responsibilities will be passed on to the project leadership committee and/or a new, technical steering committee and/or something else.
+
+Some food for thought and discussion before those dates:
+
+- [How the Apache Software Foundation Works](https://www.apache.org/foundation/how-it-works.html)
+- [Debian Project Leader documentation]()
+- [Debian Technical Committee documentation](https://www.debian.org/devel/tech-ctte)
+- [Debian's Organizational Structure](https://www.debian.org/intro/organization)
+- [QEMU SFC PLC documentation](https://wiki.qemu.org/Conservancy)
+- [libgit2 SFC PLC creation discussion](https://github.com/libgit2/discussions/issues/9)
+
+Some essential TODO before these dates:
+
+- Decide how to spend more of Homebrew's money to be useful for the project
+- Decide how technical and non-technical decisions are reached and conflicts resolved
+- Move Homebrew to a new CI system which does not require ideally any manual system administration
+- Onboard as many new maintainers as possible
+- Generally hand off and document any other responsibilities that are (and always have been) done by Mike McQuaid alone onto other groups of people | false |
Other | Homebrew | brew | 769d89deaddfa95bf9ea4a9ef977c8c68101a6e3.json | Resolve formulae in `brew cleanup`. | Library/Homebrew/cleanup.rb | @@ -166,7 +166,7 @@ def clean!
else
args.each do |arg|
formula = begin
- Formula[arg]
+ Formulary.resolve(arg)
rescue FormulaUnavailableError, TapFormulaAmbiguityError, TapFormulaWithOldnameAmbiguityError
nil
end | true |
Other | Homebrew | brew | 769d89deaddfa95bf9ea4a9ef977c8c68101a6e3.json | Resolve formulae in `brew cleanup`. | Library/Homebrew/extend/ARGV.rb | @@ -54,35 +54,7 @@ def formulae
def resolved_formulae
require "formula"
@resolved_formulae ||= (downcased_unique_named - casks).map do |name|
- if name.include?("/") || File.exist?(name)
- f = Formulary.factory(name, spec)
- if f.any_version_installed?
- tab = Tab.for_formula(f)
- resolved_spec = spec(nil) || tab.spec
- f.active_spec = resolved_spec if f.send(resolved_spec)
- f.build = tab
- if f.head? && tab.tabfile
- k = Keg.new(tab.tabfile.parent)
- f.version.update_commit(k.version.version.commit) if k.version.head?
- end
- end
- else
- rack = Formulary.to_rack(name)
- alias_path = Formulary.factory(name).alias_path
- f = Formulary.from_rack(rack, spec(nil), alias_path: alias_path)
- end
-
- # If this formula was installed with an alias that has since changed,
- # then it was specified explicitly in ARGV. (Using the alias would
- # instead have found the new formula.)
- #
- # Because of this, the user is referring to this specific formula,
- # not any formula targetted by the same alias, so in this context
- # the formula shouldn't be considered outdated if the alias used to
- # install it has changed.
- f.follow_installed_alias = false
-
- f
+ Formulary.resolve(name, spec: spec(nil))
end.uniq(&:name)
end
| true |
Other | Homebrew | brew | 769d89deaddfa95bf9ea4a9ef977c8c68101a6e3.json | Resolve formulae in `brew cleanup`. | Library/Homebrew/formulary.rb | @@ -47,6 +47,38 @@ def self.load_formula_from_path(name, path)
cache[path] = klass
end
+ def self.resolve(name, spec: nil)
+ if name.include?("/") || File.exist?(name)
+ f = factory(name, *spec)
+ if f.any_version_installed?
+ tab = Tab.for_formula(f)
+ resolved_spec = spec || tab.spec
+ f.active_spec = resolved_spec if f.send(resolved_spec)
+ f.build = tab
+ if f.head? && tab.tabfile
+ k = Keg.new(tab.tabfile.parent)
+ f.version.update_commit(k.version.version.commit) if k.version.head?
+ end
+ end
+ else
+ rack = to_rack(name)
+ alias_path = factory(name).alias_path
+ f = from_rack(rack, *spec, alias_path: alias_path)
+ end
+
+ # If this formula was installed with an alias that has since changed,
+ # then it was specified explicitly in ARGV. (Using the alias would
+ # instead have found the new formula.)
+ #
+ # Because of this, the user is referring to this specific formula,
+ # not any formula targetted by the same alias, so in this context
+ # the formula shouldn't be considered outdated if the alias used to
+ # install it has changed.
+ f.follow_installed_alias = false
+
+ f
+ end
+
def self.ensure_utf8_encoding(io)
io.set_encoding(Encoding::UTF_8)
end | true |
Other | Homebrew | brew | b46852da4c87256a4114b7bb0e28e0a102e622f3.json | components_order_cop: add more components | Library/Homebrew/rubocops/components_order_cop.rb | @@ -33,6 +33,7 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
[{ name: :conflicts_with, type: :method_call }],
[{ name: :skip_clean, type: :method_call }],
[{ name: :cxxstdlib_check, type: :method_call }],
+ [{ name: :link_overwrite, type: :method_call }],
[{ name: :fails_with, type: :method_call }, { name: :fails_with, type: :block_call }],
[{ name: :go_resource, type: :block_call }, { name: :resource, type: :block_call }],
[{ name: :patch, type: :method_call }, { name: :patch, type: :block_call }], | false |
Other | Homebrew | brew | a1264f5adad20be663ca28ab3ef11c5be54694aa.json | components_order_cop: add more components | Library/Homebrew/rubocops/components_order_cop.rb | @@ -22,6 +22,7 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
[{ name: :head, type: :method_call }],
[{ name: :stable, type: :block_call }],
[{ name: :bottle, type: :block_call }],
+ [{ name: :pour_bottle?, type: :block_call }],
[{ name: :devel, type: :block_call }],
[{ name: :head, type: :block_call }],
[{ name: :bottle, type: :method_call }],
@@ -31,6 +32,7 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
[{ name: :depends_on, type: :method_call }],
[{ name: :conflicts_with, type: :method_call }],
[{ name: :skip_clean, type: :method_call }],
+ [{ name: :cxxstdlib_check, type: :method_call }],
[{ name: :fails_with, type: :method_call }, { name: :fails_with, type: :block_call }],
[{ name: :go_resource, type: :block_call }, { name: :resource, type: :block_call }],
[{ name: :patch, type: :method_call }, { name: :patch, type: :block_call }], | false |
Other | Homebrew | brew | dc7b73171c0fa2bcced8ae32413af47dd1ab7a84.json | cmd/update: follow GitHub API redirects.
Fixes #4867 | Library/Homebrew/cmd/update.sh | @@ -482,7 +482,7 @@ EOS
fi
UPSTREAM_SHA_HTTP_CODE="$("$HOMEBREW_CURL" --silent --max-time 3 \
- --output /dev/null --write-out "%{http_code}" \
+ --location --output /dev/null --write-out "%{http_code}" \
--dump-header "$DIR/.git/GITHUB_HEADERS" \
--user-agent "$HOMEBREW_USER_AGENT_CURL" \
--header "Accept: $GITHUB_API_ACCEPT" \ | false |
Other | Homebrew | brew | cc620dbecb25efbc2e664c9dde9fc5f02b78a2fa.json | docs/Maintainer-Guidelines: address more comments. | docs/Maintainer-Guidelines.md | @@ -7,7 +7,7 @@ definitely not a beginner’s guide.
Maybe you were looking for the [Formula Cookbook](Formula-Cookbook.md)?
-This document is a work in progress. If you wish to change or discuss any of the below: open a PR to suggest a change.
+This document is current practice. If you wish to change or discuss any of the below: open a PR to suggest a change.
## Quick checklist
@@ -108,14 +108,14 @@ of modification that is not whitespace in it. But be careful about
making changes to inline patches—make sure they still apply.
### Adding or updating formulae
-Only one maintainer is necessary to approve and merge the addition of a new or updated formula which passes CI. However, if the formula addition or update is controversial the maintainer who adds it will be expected to fix issues that arise with it in future.
+Any one maintainer is necessary to approve and merge the addition of a new or updated formula which passes CI. However, if the formula addition or update proves controversial the maintainer who adds it will be expected to answer requests and fix problems that arise with it in future.
### Removing formulae
Formulae that:
- work on at least 2/3 of our supported macOS versions in the default Homebrew prefix
- do not require patches rejected by upstream to work
-- do not have known security vulnerabilities/CVEs for the version we package
+- do not have known security vulnerabilities or CVEs for the version we package
- are shown to be still installed by users in our analytics with a `BuildError` rate of <25%
@@ -151,4 +151,4 @@ In the same way that Homebrew maintainers are expected to be spending more of th
Individual Homebrew repositories should not have formal lead maintainers (although those who do the most work will have the loudest voices).
-Maintainers should feel even more free to pleasantly disagree with the work and decisions of the lead maintainer. With greater authority comes greater responsibility to handle and moderate technical disagreements.
+Maintainers should feel even more free to pleasantly disagree with the work and decisions of the lead maintainer: with greater authority comes greater responsibility to handle and moderate technical disagreements. | false |
Other | Homebrew | brew | 28061369dc4f11b3fcbbf790c95858f53e1c3e21.json | Cask: show previous verison in cask upgrade | Library/Homebrew/cask/cmd/upgrade.rb | @@ -28,7 +28,14 @@ def run
ohai "Casks with `auto_updates` or `version :latest` will not be upgraded" if args.empty? && !greedy?
oh1 "Upgrading #{Formatter.pluralize(outdated_casks.length, "outdated package")}, with result:"
- puts outdated_casks.map { |f| "#{f.full_name} #{f.version}" } * ", "
+ cask_upgrades = outdated_casks.map do |f|
+ if f.installed_caskfile.nil?
+ "#{f.full_name} #{f.version}"
+ else
+ "#{f.full_name} #{CaskLoader.load(f.installed_caskfile).version} -> #{f.version}"
+ end
+ end
+ puts cask_upgrades.join(", ")
outdated_casks.each do |old_cask|
odebug "Started upgrade process for Cask #{old_cask}" | false |
Other | Homebrew | brew | 6c3b8e100f0f3dc23fe6c77cfd049ba126e58e8c.json | components_order_cop: add all components | Library/Homebrew/rubocops/components_order_cop.rb | @@ -27,9 +27,14 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
[{ name: :bottle, type: :method_call }],
[{ name: :keg_only, type: :method_call }],
[{ name: :option, type: :method_call }],
+ [{ name: :deprecated_option, type: :method_call }],
[{ name: :depends_on, type: :method_call }],
[{ name: :conflicts_with, type: :method_call }],
+ [{ name: :skip_clean, type: :method_call }],
+ [{ name: :fails_with, type: :method_call }, { name: :fails_with, type: :block_call }],
[{ name: :go_resource, type: :block_call }, { name: :resource, type: :block_call }],
+ [{ name: :patch, type: :method_call }, { name: :patch, type: :block_call }],
+ [{ name: :needs, type: :method_call }],
[{ name: :install, type: :method_definition }],
[{ name: :post_install, type: :method_definition }],
[{ name: :caveats, type: :method_definition }], | false |
Other | Homebrew | brew | 5f18f0bb03c72af19952e2573db6881eb84257f0.json | Determine remote_url using git config | Library/Homebrew/dev-cmd/bump-formula-pr.rb | @@ -325,7 +325,11 @@ def bump_formula_pr
odie "Unable to fork: #{e.message}!"
end
- remote_url = response.fetch("clone_url")
+ if system("git", "config", "--local", "--get-regexp", "remote\..*\.url", "git@github.com:.*")
+ remote_url = response.fetch("ssh_url")
+ else
+ remote_url = response.fetch("clone_url")
+ end
username = response.fetch("owner").fetch("login")
safe_system "git", "fetch", "--unshallow", "origin" if shallow | false |
Other | Homebrew | brew | 53b95c62604fb902425c93aa01d68dc873067635.json | Cask: use native chmod to set write permissions
Ruby chmod follows symlinks, which can point to non-existent files. This
should fix quarantining Casks e.g. disk-inventory-x. | Library/Homebrew/cask/quarantine.rb | @@ -121,7 +121,7 @@ def propagate(from: nil, to: nil)
resolved_paths = Pathname.glob(to/"**/*", File::FNM_DOTMATCH)
- FileUtils.chmod "u+w", resolved_paths
+ system_command!("/bin/chmod", args: ["-R", "u+w", to])
quarantiner = system_command("/usr/bin/xargs",
args: [ | false |
Other | Homebrew | brew | 18d38d7b7699a4fd6750cc9c38609ada6ecf0fd7.json | Add brew shellenv - see #4780 | Library/Homebrew/cmd/shellenv.rb | @@ -0,0 +1,16 @@
+#: * `shellenv`:
+#: Prints export statements - run them in a shell and this installation of
+#: Homebrew will be included into your PATH, MANPATH, and INFOPATH.
+#: Tip: have your dotfiles eval the output of this command
+
+module Homebrew
+ module_function
+
+ def shellenv
+ puts <<~EOS
+ export PATH="#{HOMEBREW_PREFIX}/bin:#{HOMEBREW_PREFIX}/sbin:$PATH"
+ export MANPATH="#{HOMEBREW_PREFIX}/share/man:$MANPATH"
+ export INFOPATH="#{HOMEBREW_PREFIX}/share/info:$INFOPATH"
+ EOS
+ end
+end | true |
Other | Homebrew | brew | 18d38d7b7699a4fd6750cc9c38609ada6ecf0fd7.json | Add brew shellenv - see #4780 | Library/Homebrew/test/cmd/shellenv_spec.rb | @@ -0,0 +1,8 @@
+describe "brew shellenv", :integration_test do
+ it "doesn't fail" do
+ expect { brew "shellenv" }
+ .to output(%r{#{HOMEBREW_PREFIX}/bin}).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+end | true |
Other | Homebrew | brew | 18d38d7b7699a4fd6750cc9c38609ada6ecf0fd7.json | Add brew shellenv - see #4780 | docs/Manpage.md | @@ -441,6 +441,11 @@ With `--verbose` or `-v`, many commands print extra debugging information. Note
If `--env=std` is passed, use the standard `PATH` instead of superenv's.
+ * `shellenv`:
+ Prints export statements - run them in a shell and this installation of
+ Homebrew will be included into your PATH, MANPATH, and INFOPATH.
+ Tip: have your dotfiles eval the output of this command
+
* `style` [`--fix`] [`--display-cop-names`] [`--only-cops=``cops`|`--except-cops=``cops`] [`files`|`taps`|`formulae`]:
Check formulae or files for conformance to Homebrew style guidelines.
| true |
Other | Homebrew | brew | 18d38d7b7699a4fd6750cc9c38609ada6ecf0fd7.json | Add brew shellenv - see #4780 | manpages/brew.1 | @@ -404,6 +404,9 @@ If \fB\-\-desc\fR is passed, search formulae with a description matching \fItext
If \fB\-\-env=std\fR is passed, use the standard \fBPATH\fR instead of superenv\'s\.
.
.IP "\(bu" 4
+\fBshellenv\fR: Prints export statements \- run them in a shell and this installation of Homebrew will be included into your PATH, MANPATH, and INFOPATH\. Tip: have your dotfiles eval the output of this command
+.
+.IP "\(bu" 4
\fBstyle\fR [\fB\-\-fix\fR] [\fB\-\-display\-cop\-names\fR] [\fB\-\-only\-cops=\fR\fIcops\fR|\fB\-\-except\-cops=\fR\fIcops\fR] [\fIfiles\fR|\fItaps\fR|\fIformulae\fR]: Check formulae or files for conformance to Homebrew style guidelines\.
.
.IP | true |
Other | Homebrew | brew | 9d8b101ede241df5973b1d4ec5290a7fbc0d56dc.json | docs/Maintainer-Guidelines: address maintainer feedback. | docs/Maintainer-Guidelines.md | @@ -107,9 +107,8 @@ is a good opportunity to do it) provided the line itself has some kind
of modification that is not whitespace in it. But be careful about
making changes to inline patches—make sure they still apply.
-### Adding formulae
-Only one maintainer is necessary to approve and merge the addition of a new formula which passes CI. However, if the formula addition
-is controversial the maintainer who adds it will be expected to fix issues that arise with it in future.
+### Adding or update formulae
+Only one maintainer is necessary to approve and merge the addition of a new or updated formula which passes CI. However, if the formula addition or update is controversial the maintainer who adds it will be expected to fix issues that arise with it in future.
### Removing formulae
Formulae that:
@@ -123,12 +122,12 @@ Formulae that:
should not be removed from Homebrew. The exception to this rule are [versioned formulae](Versions.md) for which there are higher standards of usage and a maximum number of versions for a given formula.
### Closing issues/PRs
-Maintainers (including the lead maintainer) should not close issues or pull requests opened by other maintainers unless they are stale (i.e. have seen no updates for 28 days) in which case they can be closed by any maintainer. If the close is undesirable: no big deal, they can be reopened when additional work will be done.
+Maintainers (including the lead maintainer) should not close issues or pull requests opened by other maintainers unless they are stale (i.e. have seen no updates for 28 days) in which case they can be closed by any maintainer. Any maintainer is encouraged to reopen a closed issue when they wish to do additional work on the issue.
-Any maintainer can merge any PR passing CI that has been opened by any other maintainer. If you do not wish to have other maintainers merge your PRs: please use the `do not merge` label to indicate that until you're ready to merge it yourself.
+Any maintainer can merge any PR they have carefully reviewed and is passing CI that has been opened by any other maintainer. If you do not wish to have other maintainers merge your PRs: please use the `do not merge` label to indicate that until you're ready to merge it yourself.
## Reverting PRs
-Any maintainer can revert a PR created by another maintainer after a user submitted issue or CI failure that results. The maintainer who created the original PR should be given an hour to fix the issue themselves or decide to revert the PR themselves if they would rather.
+Any maintainer can revert a PR created by another maintainer after a user submitted issue or CI failure that results. The maintainer who created the original PR should be given no less than an hour to fix the issue themselves or decide to revert the PR themselves if they would rather.
## Communication
Maintainers have a variety of ways to communicate with each other:
@@ -143,7 +142,7 @@ This makes it easier for other maintainers, contributors and users to follow alo
All maintainers (and lead maintainer) communication through any medium is bound by [Homebrew's Code of Conduct](CODE_OF_CONDUCT.md#code-of-conduct). Abusive behaviour towards other maintainers, contributors or users will not be tolerated; the maintainer will be given a warning and if their behaviour continues they will be removed as a maintainer.
-Healthy, friendly, technical disagreement between maintainers is actively encouraged and should occur in public on the issue tracker. Off-topic discussions on the issue tracker, [bike-shedding](https://en.wikipedia.org/wiki/Law_of_triviality) and personal attacks are forbidden.
+Maintainers should feel free to pleasantly disagree with the work and decisions of other maintainers. Healthy, friendly, technical disagreement between maintainers is actively encouraged and should occur in public on the issue tracker to make the project better. Interpersonal issues should be handled privately in Slack, ideally with moderation. If work or decisions are insufficiently documented or explained any maintainer or contributor should feel free to ask for clarification. No maintainer may ever justify a decision with e.g. "because I say so" or "it was I who did X" alone. Off-topic discussions on the issue tracker, [bike-shedding](https://en.wikipedia.org/wiki/Law_of_triviality) and personal attacks are forbidden.
## Lead maintainer guidelines
There should be one lead maintainer for Homebrew. Decisions are determined by a consensus of the maintainers. When a consensus is not reached, the lead maintainer has the final say in determining the outcome of any decision (though this power should be used sparingly). They should also be seen as the product manager for Homebrew itself and ensuring that changes made to the entire Homebrew ecosystem are consistent and providing an increasingly positive experience for Homebrew's users.
@@ -152,4 +151,4 @@ In the same way that Homebrew maintainers are expected to be spending more of th
Individual Homebrew repositories should not have formal lead maintainers (although those who do the most work will have the loudest voices).
-Maintainers should feel free to pleasantly disagree with the work and decisions of the lead maintainer. Constructive criticism is actively solicited and will be iterated upon to make the project better. Technical criticism should occur on the issue tracker and interpersonal criticism should be handled privately in Slack. If work or decisions are insufficiently documented or explained any maintainer or contributor should feel free to ask for clarification. The lead maintainer may never justify a decision with e.g. "because I say so" or "it was I who did X" alone.
+Maintainers should feel even more free to pleasantly disagree with the work and decisions of the lead maintainer. With greater authority comes greater responsibility to handle and moderate technical disagreements. | false |
Other | Homebrew | brew | 7fd22bcda513c4cb1db30de8afccdc31f44d9f73.json | docs: fix typo from #4845. | docs/C++-Standard-Libraries.md | @@ -14,7 +14,7 @@ so Homebrew will refuse to install software if a dependency was built with an
incompatible C++ library. It's recommended that you install the dependency tree
using a compatible compiler.
-**If you've upgraded to or later 10.9 from an earlier version** - because the default C++
+**If you've upgraded to 10.9 or later from an earlier version** - because the default C++
standard library is now libc++, you may not be able to build software using
dependencies that you built on 10.8 or lower. If you're reading this page because
you were directed here by a build error, you can most likely fix the issue if | false |
Other | Homebrew | brew | 7615d3a8121a251dc747ddcbe3e040ddf64963d6.json | Improve writable directory handling
Consolidate the handling of which directories need to exist and which
need to be writable. Additionally, add a fatal check for formula
installations to ensure that any directories that need to be writable
are so before attempting an installation.
Fixes #4626. | Library/Homebrew/cleanup.rb | @@ -271,8 +271,8 @@ def cleanup_path(path)
def cleanup_lockfiles(*lockfiles)
return if dry_run?
- if lockfiles.empty? && HOMEBREW_LOCK_DIR.directory?
- lockfiles = HOMEBREW_LOCK_DIR.children.select(&:file?)
+ if lockfiles.empty? && HOMEBREW_LOCKS.directory?
+ lockfiles = HOMEBREW_LOCKS.children.select(&:file?)
end
lockfiles.each do |file|
@@ -288,11 +288,16 @@ def cleanup_lockfiles(*lockfiles)
end
def rm_ds_store(dirs = nil)
- dirs ||= %w[Caskroom Cellar Frameworks Library bin etc include lib opt sbin share var]
- .map { |path| HOMEBREW_PREFIX/path }
-
+ dirs ||= begin
+ Keg::MUST_EXIST_DIRECTORIES + [
+ HOMEBREW_CELLAR,
+ HOMEBREW_PREFIX/"Caskroom",
+ ]
+ end
dirs.select(&:directory?).each.parallel do |dir|
- system_command "find", args: [dir, "-name", ".DS_Store", "-delete"], print_stderr: false
+ system_command "find",
+ args: [dir, "-name", ".DS_Store", "-delete"],
+ print_stderr: false
end
end
end | true |
Other | Homebrew | brew | 7615d3a8121a251dc747ddcbe3e040ddf64963d6.json | Improve writable directory handling
Consolidate the handling of which directories need to exist and which
need to be writable. Additionally, add a fatal check for formula
installations to ensure that any directories that need to be writable
are so before attempting an installation.
Fixes #4626. | Library/Homebrew/cmd/reinstall.rb | @@ -14,6 +14,8 @@ module Homebrew
def reinstall
FormulaInstaller.prevent_build_flags unless DevelopmentTools.installed?
+ Install.perform_preinstall_checks
+
ARGV.resolved_formulae.each do |f|
if f.pinned?
onoe "#{f.full_name} is pinned. You must unpin it to reinstall." | true |
Other | Homebrew | brew | 7615d3a8121a251dc747ddcbe3e040ddf64963d6.json | Improve writable directory handling
Consolidate the handling of which directories need to exist and which
need to be writable. Additionally, add a fatal check for formula
installations to ensure that any directories that need to be writable
are so before attempting an installation.
Fixes #4626. | Library/Homebrew/config.rb | @@ -24,7 +24,7 @@
HOMEBREW_PINNED_KEGS = HOMEBREW_PREFIX/"var/homebrew/pinned"
# Where we store lock files
-HOMEBREW_LOCK_DIR = HOMEBREW_PREFIX/"var/homebrew/locks"
+HOMEBREW_LOCKS = HOMEBREW_PREFIX/"var/homebrew/locks"
# Where we store built products
HOMEBREW_CELLAR = Pathname.new(ENV["HOMEBREW_CELLAR"]) | true |
Other | Homebrew | brew | 7615d3a8121a251dc747ddcbe3e040ddf64963d6.json | Improve writable directory handling
Consolidate the handling of which directories need to exist and which
need to be writable. Additionally, add a fatal check for formula
installations to ensure that any directories that need to be writable
are so before attempting an installation.
Fixes #4626. | Library/Homebrew/diagnostic.rb | @@ -71,6 +71,12 @@ def inject_file_list(list, string)
end
############# END HELPERS
+ def fatal_install_checks
+ %w[
+ check_access_directories
+ ].freeze
+ end
+
def development_tools_checks
%w[
check_for_installed_developer_tools
@@ -293,115 +299,35 @@ def check_tmpdir_sticky_bit
EOS
end
- def check_access_homebrew_repository
- return if HOMEBREW_REPOSITORY.writable_real?
+ def check_exist_directories
+ not_exist_dirs = Keg::MUST_EXIST_DIRECTORIES.reject(&:exist?)
+ return if not_exist_dirs.empty?
<<~EOS
- #{HOMEBREW_REPOSITORY} is not writable.
+ The following directories do not exist:
+ #{not_exist_dirs.join("\n")}
- You should change the ownership and permissions of #{HOMEBREW_REPOSITORY}
- back to your user account.
- sudo chown -R $(whoami) #{HOMEBREW_REPOSITORY}
+ You should create these directories and change their ownership to your account.
+ sudo mkdir -p #{not_exist_dirs.join(" ")}
+ sudo chown -R $(whoami) #{not_exist_dirs.join(" ")}
EOS
end
- def check_access_prefix_directories
- not_writable_dirs = []
-
- Keg::ALL_TOP_LEVEL_DIRECTORIES.each do |dir|
- path = HOMEBREW_PREFIX/dir
- next unless path.exist?
- next if path.writable_real?
- not_writable_dirs << path
- end
-
+ def check_access_directories
+ not_writable_dirs =
+ Keg::MUST_BE_WRITABLE_DIRECTORIES.select(&:exist?)
+ .reject(&:writable_real?)
return if not_writable_dirs.empty?
<<~EOS
- The following directories are not writable:
+ The following directories are not writable by your user:
#{not_writable_dirs.join("\n")}
- This can happen if you "sudo make install" software that isn't managed
- by Homebrew. If a formula tries to write a file to this directory, the
- install will fail during the link step.
-
- You should change the ownership of these directories to your account.
+ You should change the ownership of these directories to your user.
sudo chown -R $(whoami) #{not_writable_dirs.join(" ")}
EOS
end
- def check_access_site_packages
- return unless Language::Python.homebrew_site_packages.exist?
- return if Language::Python.homebrew_site_packages.writable_real?
-
- <<~EOS
- #{Language::Python.homebrew_site_packages} isn't writable.
- This can happen if you "sudo pip install" software that isn't managed
- by Homebrew. If you install a formula with Python modules, the install
- will fail during the link step.
-
- You should change the ownership and permissions of #{Language::Python.homebrew_site_packages}
- back to your user account.
- sudo chown -R $(whoami) #{Language::Python.homebrew_site_packages}
- EOS
- end
-
- def check_access_lock_dir
- return unless HOMEBREW_LOCK_DIR.exist?
- return if HOMEBREW_LOCK_DIR.writable_real?
-
- <<~EOS
- #{HOMEBREW_LOCK_DIR} isn't writable.
- Homebrew writes lock files to this location.
-
- You should change the ownership and permissions of #{HOMEBREW_LOCK_DIR}
- back to your user account.
- sudo chown -R $(whoami) #{HOMEBREW_LOCK_DIR}
- EOS
- end
-
- def check_access_logs
- return unless HOMEBREW_LOGS.exist?
- return if HOMEBREW_LOGS.writable_real?
-
- <<~EOS
- #{HOMEBREW_LOGS} isn't writable.
- Homebrew writes debugging logs to this location.
-
- You should change the ownership and permissions of #{HOMEBREW_LOGS}
- back to your user account.
- sudo chown -R $(whoami) #{HOMEBREW_LOGS}
- EOS
- end
-
- def check_access_cache
- return unless HOMEBREW_CACHE.exist?
- return if HOMEBREW_CACHE.writable_real?
-
- <<~EOS
- #{HOMEBREW_CACHE} isn't writable.
- This can happen if you run `brew install` or `brew fetch` as another user.
- Homebrew caches downloaded files to this location.
-
- You should change the ownership and permissions of #{HOMEBREW_CACHE}
- back to your user account.
- sudo chown -R $(whoami) #{HOMEBREW_CACHE}
- EOS
- end
-
- def check_access_cellar
- return unless HOMEBREW_CELLAR.exist?
- return if HOMEBREW_CELLAR.writable_real?
-
- <<~EOS
- #{HOMEBREW_CELLAR} isn't writable.
-
- You should change the ownership and permissions of #{HOMEBREW_CELLAR}
- back to your user account.
- sudo chown -R $(whoami) #{HOMEBREW_CELLAR}
- EOS
- end
-
def check_multiple_cellars
return if HOMEBREW_PREFIX.to_s == HOMEBREW_REPOSITORY.to_s
return unless (HOMEBREW_REPOSITORY/"Cellar").exist? | true |
Other | Homebrew | brew | 7615d3a8121a251dc747ddcbe3e040ddf64963d6.json | Improve writable directory handling
Consolidate the handling of which directories need to exist and which
need to be writable. Additionally, add a fatal check for formula
installations to ensure that any directories that need to be writable
are so before attempting an installation.
Fixes #4626. | Library/Homebrew/formula_installer.rb | @@ -205,7 +205,7 @@ def build_bottle_postinstall
def install
start_time = Time.now
if !formula.bottle_unneeded? && !pour_bottle? && DevelopmentTools.installed?
- Homebrew::Install.check_development_tools
+ Homebrew::Install.perform_development_tools_checks
end
# not in initialize so upgrade can unlink the active keg before calling this
@@ -893,7 +893,7 @@ def post_install
sandbox.allow_write_xcode
sandbox.deny_write_homebrew_repository
sandbox.allow_write_cellar(formula)
- Keg::TOP_LEVEL_DIRECTORIES.each do |dir|
+ Keg::KEG_LINK_DIRECTORIES.each do |dir|
sandbox.allow_write_path "#{HOMEBREW_PREFIX}/#{dir}"
end
sandbox.exec(*args) | true |
Other | Homebrew | brew | 7615d3a8121a251dc747ddcbe3e040ddf64963d6.json | Improve writable directory handling
Consolidate the handling of which directories need to exist and which
need to be writable. Additionally, add a fatal check for formula
installations to ensure that any directories that need to be writable
are so before attempting an installation.
Fixes #4626. | Library/Homebrew/install.rb | @@ -17,39 +17,36 @@ def check_ppc
end
end
- def check_writable_install_location
- if HOMEBREW_CELLAR.exist? && !HOMEBREW_CELLAR.writable_real?
- raise "Cannot write to #{HOMEBREW_CELLAR}"
+ def attempt_directory_creation
+ Keg::MUST_BE_WRITABLE_DIRECTORIES.each do |dir|
+ begin
+ FileUtils.mkdir_p(dir) unless dir.exist?
+ rescue
+ nil
+ end
end
- prefix_writable = HOMEBREW_PREFIX.writable_real? || HOMEBREW_PREFIX.to_s == "/usr/local"
- raise "Cannot write to #{HOMEBREW_PREFIX}" unless prefix_writable
end
- def check_development_tools
- checks = Diagnostic::Checks.new
+ def perform_development_tools_checks
+ fatal_checks(:fatal_development_tools_checks)
+ end
+
+ def perform_preinstall_checks
+ check_ppc
+ attempt_directory_creation
+ fatal_checks(:fatal_install_checks)
+ end
+
+ def fatal_checks(type)
+ @checks ||= Diagnostic::Checks.new
failed = false
- checks.fatal_development_tools_checks.each do |check|
- out = checks.send(check)
+ @checks.public_send(type).each do |check|
+ out = @checks.public_send(check)
next if out.nil?
failed ||= true
ofail out
end
exit 1 if failed
end
-
- def check_cellar
- FileUtils.mkdir_p HOMEBREW_CELLAR unless File.exist? HOMEBREW_CELLAR
- rescue
- raise <<~EOS
- Could not create #{HOMEBREW_CELLAR}
- Check you have permission to write to #{HOMEBREW_CELLAR.parent}
- EOS
- end
-
- def perform_preinstall_checks
- check_ppc
- check_writable_install_location
- check_cellar
- end
end
end | true |
Other | Homebrew | brew | 7615d3a8121a251dc747ddcbe3e040ddf64963d6.json | Improve writable directory handling
Consolidate the handling of which directories need to exist and which
need to be writable. Additionally, add a fatal check for formula
installations to ensure that any directories that need to be writable
are so before attempting an installation.
Fixes #4626. | Library/Homebrew/keg.rb | @@ -1,4 +1,5 @@
require "keg_relocate"
+require "language/python"
require "lock_file"
require "ostruct"
@@ -64,18 +65,41 @@ def to_s
# locale-specific directories have the form language[_territory][.codeset][@modifier]
LOCALEDIR_RX = %r{(locale|man)/([a-z]{2}|C|POSIX)(_[A-Z]{2})?(\.[a-zA-Z\-0-9]+(@.+)?)?}
INFOFILE_RX = %r{info/([^.].*?\.info|dir)$}
- TOP_LEVEL_DIRECTORIES = %w[bin etc include lib sbin share var Frameworks].freeze
- ALL_TOP_LEVEL_DIRECTORIES = (TOP_LEVEL_DIRECTORIES + %w[lib/pkgconfig share/locale share/man opt]).freeze
- PRUNEABLE_DIRECTORIES = %w[
- bin etc include lib sbin share opt Frameworks LinkedKegs var/homebrew/linked
- ].map do |dir|
- case dir
- when "LinkedKegs"
- HOMEBREW_LIBRARY/dir
- else
- HOMEBREW_PREFIX/dir
- end
- end
+ KEG_LINK_DIRECTORIES = %w[
+ bin etc include lib sbin share var Frameworks
+ ].freeze
+ # TODO: remove when brew-test-bot no longer uses this
+ TOP_LEVEL_DIRECTORIES = KEG_LINK_DIRECTORIES
+ PRUNEABLE_DIRECTORIES = (
+ KEG_LINK_DIRECTORIES - %w[var] + %w[var/homebrew/linked]
+ ).map { |dir| HOMEBREW_PREFIX/dir }
+
+ # Keep relatively in sync with
+ # https://github.com/Homebrew/install/blob/master/install
+ MUST_EXIST_DIRECTORIES = (
+ (KEG_LINK_DIRECTORIES + %w[
+ opt
+ ]).map { |dir| HOMEBREW_PREFIX/dir }
+ ).freeze
+ MUST_BE_WRITABLE_DIRECTORIES = (
+ (KEG_LINK_DIRECTORIES + %w[
+ opt
+ etc/bash_completion.d lib/pkgconfig
+ share/aclocal share/doc share/info share/locale share/man
+ share/man/man1 share/man/man2 share/man/man3 share/man/man4
+ share/man/man5 share/man/man6 share/man/man7 share/man/man8
+ share/zsh share/zsh/site-functions
+ var/log
+ Caskroom
+ ]).map { |dir| HOMEBREW_PREFIX/dir } + [
+ HOMEBREW_CACHE,
+ HOMEBREW_CELLAR,
+ HOMEBREW_LOCKS,
+ HOMEBREW_LOGS,
+ HOMEBREW_REPOSITORY,
+ Language::Python.homebrew_site_packages,
+ ]
+ ).freeze
# These paths relative to the keg's share directory should always be real
# directories in the prefix, never symlinks.
@@ -291,7 +315,7 @@ def unlink(mode = OpenStruct.new)
dirs = []
- TOP_LEVEL_DIRECTORIES.map { |d| path/d }.each do |dir|
+ KEG_LINK_DIRECTORIES.map { |d| path/d }.each do |dir|
next unless dir.exist?
dir.find do |src|
dst = HOMEBREW_PREFIX + src.relative_path_from(path) | true |
Other | Homebrew | brew | 7615d3a8121a251dc747ddcbe3e040ddf64963d6.json | Improve writable directory handling
Consolidate the handling of which directories need to exist and which
need to be writable. Additionally, add a fatal check for formula
installations to ensure that any directories that need to be writable
are so before attempting an installation.
Fixes #4626. | Library/Homebrew/lock_file.rb | @@ -5,7 +5,7 @@ class LockFile
def initialize(name)
@name = name.to_s
- @path = HOMEBREW_LOCK_DIR/"#{@name}.lock"
+ @path = HOMEBREW_LOCKS/"#{@name}.lock"
@lockfile = nil
end
| true |
Other | Homebrew | brew | 7615d3a8121a251dc747ddcbe3e040ddf64963d6.json | Improve writable directory handling
Consolidate the handling of which directories need to exist and which
need to be writable. Additionally, add a fatal check for formula
installations to ensure that any directories that need to be writable
are so before attempting an installation.
Fixes #4626. | Library/Homebrew/test/cleanup_spec.rb | @@ -27,8 +27,8 @@
end
describe Homebrew::Cleanup do
- let(:ds_store) { Pathname.new("#{HOMEBREW_PREFIX}/Library/.DS_Store") }
- let(:lock_file) { Pathname.new("#{HOMEBREW_LOCK_DIR}/foo") }
+ let(:ds_store) { Pathname.new("#{HOMEBREW_CELLAR}/.DS_Store") }
+ let(:lock_file) { Pathname.new("#{HOMEBREW_LOCKS}/foo") }
around do |example|
begin | true |
Other | Homebrew | brew | 7615d3a8121a251dc747ddcbe3e040ddf64963d6.json | Improve writable directory handling
Consolidate the handling of which directories need to exist and which
need to be writable. Additionally, add a fatal check for formula
installations to ensure that any directories that need to be writable
are so before attempting an installation.
Fixes #4626. | Library/Homebrew/test/diagnostic_spec.rb | @@ -29,64 +29,25 @@
end
end
- specify "#check_access_homebrew_repository" do
+ specify "#check_access_directories" do
begin
- mode = HOMEBREW_REPOSITORY.stat.mode & 0777
- HOMEBREW_REPOSITORY.chmod 0555
-
- expect(subject.check_access_homebrew_repository)
- .to match("#{HOMEBREW_REPOSITORY} is not writable.")
- ensure
- HOMEBREW_REPOSITORY.chmod mode
- end
- end
-
- specify "#check_access_lock_dir" do
- begin
- prev_mode = HOMEBREW_LOCK_DIR.stat.mode
- mode = HOMEBREW_LOCK_DIR.stat.mode & 0777
- HOMEBREW_LOCK_DIR.chmod 0555
- expect(HOMEBREW_LOCK_DIR.stat.mode).not_to eq(prev_mode)
-
- expect(subject.check_access_lock_dir)
- .to match("#{HOMEBREW_LOCK_DIR} isn't writable.")
- ensure
- HOMEBREW_LOCK_DIR.chmod mode
- end
- end
-
- specify "#check_access_logs" do
- begin
- mode = HOMEBREW_LOGS.stat.mode & 0777
- HOMEBREW_LOGS.chmod 0555
-
- expect(subject.check_access_logs)
- .to match("#{HOMEBREW_LOGS} isn't writable.")
- ensure
- HOMEBREW_LOGS.chmod mode
- end
- end
-
- specify "#check_access_cache" do
- begin
- mode = HOMEBREW_CACHE.stat.mode & 0777
- HOMEBREW_CACHE.chmod 0555
- expect(subject.check_access_cache)
- .to match("#{HOMEBREW_CACHE} isn't writable.")
- ensure
- HOMEBREW_CACHE.chmod mode
- end
- end
-
- specify "#check_access_cellar" do
- begin
- mode = HOMEBREW_CELLAR.stat.mode & 0777
- HOMEBREW_CELLAR.chmod 0555
-
- expect(subject.check_access_cellar)
- .to match("#{HOMEBREW_CELLAR} isn't writable.")
+ dirs = [
+ HOMEBREW_CACHE,
+ HOMEBREW_CELLAR,
+ HOMEBREW_REPOSITORY,
+ HOMEBREW_LOGS,
+ HOMEBREW_LOCKS,
+ ]
+ modes = {}
+ dirs.each do |dir|
+ modes[dir] = dir.stat.mode & 0777
+ dir.chmod 0555
+ expect(subject.check_access_directories).to match(dir.to_s)
+ end
ensure
- HOMEBREW_CELLAR.chmod mode
+ modes.each do |dir, mode|
+ dir.chmod mode
+ end
end
end
| true |
Other | Homebrew | brew | 7615d3a8121a251dc747ddcbe3e040ddf64963d6.json | Improve writable directory handling
Consolidate the handling of which directories need to exist and which
need to be writable. Additionally, add a fatal check for formula
installations to ensure that any directories that need to be writable
are so before attempting an installation.
Fixes #4626. | Library/Homebrew/test/spec_helper.rb | @@ -32,7 +32,7 @@
HOMEBREW_CACHE,
HOMEBREW_CACHE_FORMULA,
HOMEBREW_CELLAR,
- HOMEBREW_LOCK_DIR,
+ HOMEBREW_LOCKS,
HOMEBREW_LOGS,
HOMEBREW_TEMP,
].freeze
@@ -134,13 +134,9 @@ def find_files
FileUtils.rm_rf [
TEST_DIRECTORIES.map(&:children),
+ *Keg::MUST_EXIST_DIRECTORIES,
HOMEBREW_LINKED_KEGS,
HOMEBREW_PINNED_KEGS,
- HOMEBREW_PREFIX/".git",
- HOMEBREW_PREFIX/"bin",
- HOMEBREW_PREFIX/"etc",
- HOMEBREW_PREFIX/"share",
- HOMEBREW_PREFIX/"opt",
HOMEBREW_PREFIX/"Caskroom",
HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-cask",
HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-bar", | true |
Other | Homebrew | brew | 7615d3a8121a251dc747ddcbe3e040ddf64963d6.json | Improve writable directory handling
Consolidate the handling of which directories need to exist and which
need to be writable. Additionally, add a fatal check for formula
installations to ensure that any directories that need to be writable
are so before attempting an installation.
Fixes #4626. | Library/Homebrew/test/support/lib/config.rb | @@ -27,7 +27,7 @@
HOMEBREW_CACHE_FORMULA = HOMEBREW_PREFIX.parent/"formula_cache"
HOMEBREW_LINKED_KEGS = HOMEBREW_PREFIX.parent/"linked"
HOMEBREW_PINNED_KEGS = HOMEBREW_PREFIX.parent/"pinned"
-HOMEBREW_LOCK_DIR = HOMEBREW_PREFIX.parent/"locks"
+HOMEBREW_LOCKS = HOMEBREW_PREFIX.parent/"locks"
HOMEBREW_CELLAR = HOMEBREW_PREFIX.parent/"cellar"
HOMEBREW_LOGS = HOMEBREW_PREFIX.parent/"logs"
HOMEBREW_TEMP = HOMEBREW_PREFIX.parent/"temp" | true |
Other | Homebrew | brew | 7615d3a8121a251dc747ddcbe3e040ddf64963d6.json | Improve writable directory handling
Consolidate the handling of which directories need to exist and which
need to be writable. Additionally, add a fatal check for formula
installations to ensure that any directories that need to be writable
are so before attempting an installation.
Fixes #4626. | Library/Homebrew/update_migrator.rb | @@ -341,9 +341,7 @@ def migrate_legacy_repository_if_necessary
EOS
end
- (Keg::ALL_TOP_LEVEL_DIRECTORIES + ["Cellar"]).each do |dir|
- FileUtils.mkdir_p "#{HOMEBREW_PREFIX}/#{dir}"
- end
+ Keg::MUST_EXIST_DIRECTORIES.each { |dir| FileUtils.mkdir_p dir }
src = Pathname.new("#{new_homebrew_repository}/bin/brew")
dst = Pathname.new("#{HOMEBREW_PREFIX}/bin/brew") | true |
Other | Homebrew | brew | 7615d3a8121a251dc747ddcbe3e040ddf64963d6.json | Improve writable directory handling
Consolidate the handling of which directories need to exist and which
need to be writable. Additionally, add a fatal check for formula
installations to ensure that any directories that need to be writable
are so before attempting an installation.
Fixes #4626. | docs/Troubleshooting.md | @@ -11,7 +11,7 @@ Follow these steps to fix common problems:
* Run `brew update` twice.
* Run `brew doctor` and fix all the warnings (**outdated Xcode/CLT and unbrewed dylibs are very likely to cause problems**).
* Check that **Command Line Tools for Xcode (CLT)** and **Xcode** are up to date.
-* If commands fail with permissions errors, check the permissions of `/usr/local`'s subdirectories. If you’re unsure what to do, you can run `cd /usr/local && sudo chown -R $(whoami) bin etc include lib sbin share var Frameworks`.
+* If commands fail with permissions errors, check the permissions of `/usr/local`'s subdirectories. If you’re unsure what to do, you can run `cd /usr/local && sudo chown -R $(whoami) bin etc include lib sbin share var opt Cellar Caskroom Frameworks`.
* Read through the [Common Issues](Common-Issues.md).
## Check to see if the issue has been reported | true |
Other | Homebrew | brew | 9db1feb3da20348828bf16280a8eafa010a80522.json | docs/Maintainer-Guidelines: add more guidelines. | docs/Maintainer-Guidelines.md | @@ -7,6 +7,8 @@ definitely not a beginner’s guide.
Maybe you were looking for the [Formula Cookbook](Formula-Cookbook.md)?
+This document is a work in progress. If you wish to change or discuss any of the below: open a PR to suggest a change.
+
## Quick checklist
This is all that really matters:
@@ -105,6 +107,29 @@ is a good opportunity to do it) provided the line itself has some kind
of modification that is not whitespace in it. But be careful about
making changes to inline patches—make sure they still apply.
+### Adding formulae
+Only one maintainer is necessary to approve and merge the addition of a new formula which passes CI. However, if the formula addition
+is controversial the maintainer who adds it will be expected to fix issues that arise with it in future.
+
+### Removing formulae
+Formulae that:
+
+- work on at least 2/3 of our supported macOS versions in the default Homebrew prefix
+- do not require patches rejected by upstream to work
+- do not have known security vulnerabilities/CVEs for the version we package
+- are shown to be still installed by users in our analytics with a `BuildError` rate of <25%
+
+
+should not be removed from Homebrew. The exception to this rule are [versioned formulae](Versions.md) for which there are higher standards of usage and a maximum number of versions for a given formula.
+
+### Closing issues/PRs
+Maintainers (including the lead maintainer) should not close issues or pull requests opened by other maintainers unless they are stale (i.e. have seen no updates for 28 days) in which case they can be closed by any maintainer. If the close is undesirable: no big deal, they can be reopened when additional work will be done.
+
+Any maintainer can merge any PR passing CI that has been opened by any other maintainer. If you do not wish to have other maintainers merge your PRs: please use the `do not merge` label to indicate that until you're ready to merge it yourself.
+
+## Reverting PRs
+Any maintainer can revert a PR created by another maintainer after a user submitted issue or CI failure that results. The maintainer who created the original PR should be given an hour to fix the issue themselves or decide to revert the PR themselves if they would rather.
+
## Communication
Maintainers have a variety of ways to communicate with each other:
@@ -118,9 +143,13 @@ This makes it easier for other maintainers, contributors and users to follow alo
All maintainers (and lead maintainer) communication through any medium is bound by [Homebrew's Code of Conduct](CODE_OF_CONDUCT.md#code-of-conduct). Abusive behaviour towards other maintainers, contributors or users will not be tolerated; the maintainer will be given a warning and if their behaviour continues they will be removed as a maintainer.
+Healthy, friendly, technical disagreement between maintainers is actively encouraged and should occur in public on the issue tracker. Off-topic discussions on the issue tracker, [bike-shedding](https://en.wikipedia.org/wiki/Law_of_triviality) and personal attacks are forbidden.
+
## Lead maintainer guidelines
There should be one lead maintainer for Homebrew. Decisions are determined by a consensus of the maintainers. When a consensus is not reached, the lead maintainer has the final say in determining the outcome of any decision (though this power should be used sparingly). They should also be seen as the product manager for Homebrew itself and ensuring that changes made to the entire Homebrew ecosystem are consistent and providing an increasingly positive experience for Homebrew's users.
In the same way that Homebrew maintainers are expected to be spending more of their time reviewing and merging contributions from non-maintainer contributors than making their own contributions, the lead maintainer should be spending most of their time reviewing work from and mentoring other maintainers.
Individual Homebrew repositories should not have formal lead maintainers (although those who do the most work will have the loudest voices).
+
+Maintainers should feel free to pleasantly disagree with the work and decisions of the lead maintainer. Constructive criticism is actively solicited and will be iterated upon to make the project better. Technical criticism should occur on the issue tracker and interpersonal criticism should be handled privately in Slack. If work or decisions are insufficiently documented or explained any maintainer or contributor should feel free to ask for clarification. The lead maintainer may never justify a decision with e.g. "because I say so" or "it was I who did X" alone. | false |
Other | Homebrew | brew | c6b6fc678e66668b08d31e7a55950768e0e4d687.json | dev-cmd/edit: simplify project view handling.
The way Homebrew is structured now there’s no need to manually
specify a few different directories here. | Library/Homebrew/dev-cmd/edit.rb | @@ -26,36 +26,15 @@ def edit
end
# If no brews are listed, open the project root in an editor.
- if ARGV.named.empty?
- editor = File.basename which_editor
- if ["atom", "subl", "mate"].include?(editor)
- # If the user is using Atom, Sublime Text or TextMate
- # give a nice project view instead.
- exec_editor HOMEBREW_REPOSITORY/"bin/brew",
- HOMEBREW_REPOSITORY/"README.md",
- HOMEBREW_REPOSITORY/".gitignore",
- *library_folders
- else
- exec_editor HOMEBREW_REPOSITORY
- end
- else
- # Don't use ARGV.formulae as that will throw if the file doesn't parse
- paths = ARGV.named.map do |name|
- path = Formulary.path(name)
+ paths = [HOMEBREW_REPOSITORY] if ARGV.named.empty?
- raise FormulaUnavailableError, name unless path.file? || args.force?
-
- path
- end
- exec_editor(*paths)
+ # Don't use ARGV.formulae as that will throw if the file doesn't parse
+ paths ||= ARGV.named.map do |name|
+ path = Formulary.path(name)
+ raise FormulaUnavailableError, name if !path.file? && !args.force?
+ path
end
- end
- def library_folders
- Dir["#{HOMEBREW_LIBRARY}/*"].reject do |d|
- case File.basename(d)
- when "LinkedKegs", "Aliases" then true
- end
- end
+ exec_editor(*paths)
end
end | false |
Other | Homebrew | brew | 78d4db2755995ff56736582758ad97f8d76c814c.json | Use classes for instance doubles. | Library/Homebrew/test/cache_store_spec.rb | @@ -98,7 +98,7 @@
describe "#close_if_open!" do
context "database open" do
before(:each) do
- subject.instance_variable_set(:@db, instance_double("db", close: nil))
+ subject.instance_variable_set(:@db, instance_double(DBM, close: nil))
end
it "does not raise an error when `close` is called on the database" do | true |
Other | Homebrew | brew | 78d4db2755995ff56736582758ad97f8d76c814c.json | Use classes for instance doubles. | Library/Homebrew/test/cask/artifact/installer_spec.rb | @@ -1,6 +1,6 @@
describe Hbc::Artifact::Installer, :cask do
let(:staged_path) { mktmpdir }
- let(:cask) { instance_double("Cask", staged_path: staged_path, config: nil) }
+ let(:cask) { instance_double(Hbc::Cask, staged_path: staged_path, config: nil) }
subject(:installer) { described_class.new(cask, **args) }
let(:command) { SystemCommand }
| true |
Other | Homebrew | brew | 33ce424399b429be79c8cc6f009fd14530350721.json | Remove redundant namespacing. | Library/Homebrew/cask/audit.rb | @@ -64,27 +64,27 @@ def check_untrusted_pkg
return if tap.nil?
return if tap.user != "Homebrew"
- return unless cask.artifacts.any? { |k| k.is_a?(Hbc::Artifact::Pkg) && k.stanza_options.key?(:allow_untrusted) }
+ return unless cask.artifacts.any? { |k| k.is_a?(Artifact::Pkg) && k.stanza_options.key?(:allow_untrusted) }
add_warning "allow_untrusted is not permitted in official Homebrew Cask taps"
end
def check_stanza_requires_uninstall
odebug "Auditing stanzas which require an uninstall"
- return if cask.artifacts.none? { |k| k.is_a?(Hbc::Artifact::Pkg) || k.is_a?(Hbc::Artifact::Installer) }
- return if cask.artifacts.any? { |k| k.is_a?(Hbc::Artifact::Uninstall) }
+ return if cask.artifacts.none? { |k| k.is_a?(Artifact::Pkg) || k.is_a?(Artifact::Installer) }
+ return if cask.artifacts.any? { |k| k.is_a?(Artifact::Uninstall) }
add_warning "installer and pkg stanzas require an uninstall stanza"
end
def check_single_pre_postflight
odebug "Auditing preflight and postflight stanzas"
- if cask.artifacts.count { |k| k.is_a?(Hbc::Artifact::PreflightBlock) && k.directives.key?(:preflight) } > 1
+ if cask.artifacts.count { |k| k.is_a?(Artifact::PreflightBlock) && k.directives.key?(:preflight) } > 1
add_warning "only a single preflight stanza is allowed"
end
count = cask.artifacts.count do |k|
- k.is_a?(Hbc::Artifact::PostflightBlock) &&
+ k.is_a?(Artifact::PostflightBlock) &&
k.directives.key?(:postflight)
end
return unless count > 1
@@ -95,12 +95,12 @@ def check_single_pre_postflight
def check_single_uninstall_zap
odebug "Auditing single uninstall_* and zap stanzas"
- if cask.artifacts.count { |k| k.is_a?(Hbc::Artifact::Uninstall) } > 1
+ if cask.artifacts.count { |k| k.is_a?(Artifact::Uninstall) } > 1
add_warning "only a single uninstall stanza is allowed"
end
count = cask.artifacts.count do |k|
- k.is_a?(Hbc::Artifact::PreflightBlock) &&
+ k.is_a?(Artifact::PreflightBlock) &&
k.directives.key?(:uninstall_preflight)
end
@@ -109,15 +109,15 @@ def check_single_uninstall_zap
end
count = cask.artifacts.count do |k|
- k.is_a?(Hbc::Artifact::PostflightBlock) &&
+ k.is_a?(Artifact::PostflightBlock) &&
k.directives.key?(:uninstall_postflight)
end
if count > 1
add_warning "only a single uninstall_postflight stanza is allowed"
end
- return unless cask.artifacts.count { |k| k.is_a?(Hbc::Artifact::Zap) } > 1
+ return unless cask.artifacts.count { |k| k.is_a?(Artifact::Zap) } > 1
add_warning "only a single zap stanza is allowed"
end
@@ -276,7 +276,7 @@ def bad_osdn_url?
end
def check_generic_artifacts
- cask.artifacts.select { |a| a.is_a?(Hbc::Artifact::Artifact) }.each do |artifact|
+ cask.artifacts.select { |a| a.is_a?(Artifact::Artifact) }.each do |artifact|
unless artifact.target.absolute?
add_error "target must be absolute path for #{artifact.class.english_name} #{artifact.source}"
end | true |
Other | Homebrew | brew | 33ce424399b429be79c8cc6f009fd14530350721.json | Remove redundant namespacing. | Library/Homebrew/test/support/fixtures/cask/Casks/generic-artifact-absolute-target.rb | @@ -1,3 +1,3 @@
cask 'generic-artifact-absolute-target' do
- artifact 'Caffeine.app', target: "#{Hbc::Config.global.appdir}/Caffeine.app"
+ artifact 'Caffeine.app', target: "#{appdir}/Caffeine.app"
end | true |
Other | Homebrew | brew | 33ce424399b429be79c8cc6f009fd14530350721.json | Remove redundant namespacing. | Library/Homebrew/test/support/fixtures/cask/Casks/with-generic-artifact.rb | @@ -5,5 +5,5 @@
url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
homepage 'https://example.com/with-generic-artifact'
- artifact 'Caffeine.app', target: "#{Hbc::Config.global.appdir}/Caffeine.app"
+ artifact 'Caffeine.app', target: "#{appdir}/Caffeine.app"
end | true |
Other | Homebrew | brew | eac60b0876e69087941d8d3f2189f5e4f646b495.json | Add test for RuboCop `$LOAD_PATH`. | Library/Homebrew/test/rubocop_spec.rb | @@ -0,0 +1,18 @@
+require "open3"
+
+describe "RuboCop" do
+ context "when calling `rubocop` outside of the Homebrew environment" do
+ before do
+ ENV.keys.each do |key|
+ ENV.delete(key) if key.start_with?("HOMEBREW_")
+ end
+
+ ENV["XDG_CACHE_HOME"] = "#{HOMEBREW_CACHE}/style"
+ end
+
+ it "loads all Formula cops without errors" do
+ _, _, status = Open3.capture3("rubocop", TEST_FIXTURE_DIR/"testball.rb")
+ expect(status).to be_a_success
+ end
+ end
+end | false |
Other | Homebrew | brew | 6aa7b47ae194a02f5b6e8cda2ce3c69e161ee5c9.json | scm shim: handle edge case
Since #4748 `HOMEBREW_GIT` is set by the `brew.sh`, whose value is default to be `git`.
As a result, it completely bypasses the logic of the shims/scm/git.
This fixes the issue by checking whether `HOMEBREW_GIT` and
`HOMEBREW_SVN` are set to be `git` and `svn` respectively.
Fixes #4825. | Library/Homebrew/shims/scm/git | @@ -85,10 +85,16 @@ fi
case "$(lowercase "$SCM_FILE")" in
git)
- [[ -n "$HOMEBREW_GIT" ]] && safe_exec "$(type -P "$HOMEBREW_GIT")" "$@"
+ if [[ -n "$HOMEBREW_GIT" && "$HOMEBREW_GIT" != git ]]
+ then
+ safe_exec "$(type -P "$HOMEBREW_GIT")" "$@"
+ fi
;;
svn)
- [[ -n "$HOMEBREW_SVN" ]] && safe_exec "$(type -P "$HOMEBREW_SVN")" "$@"
+ if [[ -n "$HOMEBREW_SVN" && "$HOMEBREW_SVN" != svn ]]
+ then
+ safe_exec "$(type -P "$HOMEBREW_SVN")" "$@"
+ fi
;;
esac
| false |
Other | Homebrew | brew | ed6f2829b18a52b25f57d3317ab63ada1c6f7f86.json | Cask: check support of quarantine's tools
- In some cases (usually old CLT versions) Swift is available but needs an
extra guard to use the quarantine API.
- xattr's native filesystem recursion is an Apple extension which is
not available in Mojave; so let's use xargs.
- Insert a quarantine support check in brew cask doctor.
Fixes Homebrew/homebrew-cask#51554, and fixes Homebrew/homebrew-cask#51538. | Library/Homebrew/cask/cmd/doctor.rb | @@ -22,6 +22,7 @@ def summary_header
def run
check_software_versions
+ check_quarantine_support
check_install_location
check_staging_location
check_taps
@@ -116,6 +117,23 @@ def check_environment_variables
(locale_variables + environment_variables).sort.each(&method(:render_env_var))
end
+ def check_quarantine_support
+ ohai "Gatekeeper support"
+
+ status = Quarantine.check_quarantine_support
+
+ case status
+ when :quarantine_available
+ puts "Enabled"
+ when :no_swift
+ add_error "Swift is not available on this system."
+ when :no_quarantine
+ add_error "This feature requires the macOS 10.10 SDK or higher."
+ else
+ onoe "Unknown support status"
+ end
+ end
+
def user_tilde(path)
self.class.user_tilde(path)
end | true |
Other | Homebrew | brew | ed6f2829b18a52b25f57d3317ab63ada1c6f7f86.json | Cask: check support of quarantine's tools
- In some cases (usually old CLT versions) Swift is available but needs an
extra guard to use the quarantine API.
- xattr's native filesystem recursion is an Apple extension which is
not available in Mojave; so let's use xargs.
- Insert a quarantine support check in brew cask doctor.
Fixes Homebrew/homebrew-cask#51554, and fixes Homebrew/homebrew-cask#51538. | Library/Homebrew/cask/installer.rb | @@ -186,7 +186,7 @@ def extract_primary_container
return unless quarantine?
return unless Quarantine.available?
- Quarantine.propagate(from: @downloaded_path, to: @cask.staged_path, command: @command)
+ Quarantine.propagate(from: @downloaded_path, to: @cask.staged_path)
end
def install_artifacts | true |
Other | Homebrew | brew | ed6f2829b18a52b25f57d3317ab63ada1c6f7f86.json | Cask: check support of quarantine's tools
- In some cases (usually old CLT versions) Swift is available but needs an
extra guard to use the quarantine API.
- xattr's native filesystem recursion is an Apple extension which is
not available in Mojave; so let's use xargs.
- Insert a quarantine support check in brew cask doctor.
Fixes Homebrew/homebrew-cask#51554, and fixes Homebrew/homebrew-cask#51538. | Library/Homebrew/cask/quarantine.rb | @@ -12,10 +12,29 @@ def swift
@swift ||= DevelopmentTools.locate("swift")
end
+ def check_quarantine_support
+ odebug "Checking quarantine support"
+
+ if swift.nil?
+ odebug "Swift is not available on this system."
+ return :no_swift
+ end
+
+ api_check = system_command(swift, args: [QUARANTINE_SCRIPT])
+
+ if api_check.exit_status == 5
+ odebug "This feature requires the macOS 10.10 SDK or higher."
+ return :no_quarantine
+ end
+
+ odebug "Quarantine is available."
+ :quarantine_available
+ end
+
def available?
- status = !swift.nil?
- odebug "Quarantine is #{status ? "available" : "not available"}."
- status
+ @status ||= check_quarantine_support
+
+ @status == :quarantine_available
end
def detect(file)
@@ -30,24 +49,24 @@ def detect(file)
quarantine_status
end
- def status(file, command: SystemCommand)
- command.run("/usr/bin/xattr",
- args: ["-p", QUARANTINE_ATTRIBUTE, file],
- print_stderr: false).stdout.rstrip
+ def status(file)
+ system_command("/usr/bin/xattr",
+ args: ["-p", QUARANTINE_ATTRIBUTE, file],
+ print_stderr: false).stdout.rstrip
end
- def cask(cask: nil, download_path: nil, command: SystemCommand)
+ def cask(cask: nil, download_path: nil)
return if cask.nil? || download_path.nil?
odebug "Quarantining #{download_path}"
- quarantiner = command.run(swift,
- args: [
- QUARANTINE_SCRIPT,
- download_path,
- cask.url.to_s,
- cask.homepage.to_s,
- ])
+ quarantiner = system_command(swift,
+ args: [
+ QUARANTINE_SCRIPT,
+ download_path,
+ cask.url.to_s,
+ cask.homepage.to_s,
+ ])
return if quarantiner.success?
@@ -59,18 +78,29 @@ def cask(cask: nil, download_path: nil, command: SystemCommand)
end
end
- def propagate(from: nil, to: nil, command: SystemCommand)
+ def propagate(from: nil, to: nil)
return if from.nil? || to.nil?
raise CaskError, "#{from} was not quarantined properly." unless detect(from)
odebug "Propagating quarantine from #{from} to #{to}"
- quarantine_status = status(from, command: command)
-
- quarantiner = command.run("/usr/bin/xattr",
- args: ["-w", "-rs", QUARANTINE_ATTRIBUTE, quarantine_status, to],
- print_stderr: false)
+ quarantine_status = status(from)
+
+ resolved_paths = Pathname.glob(to/"**/*", File::FNM_DOTMATCH)
+
+ quarantiner = system_command("/usr/bin/xargs",
+ args: [
+ "-0",
+ "--",
+ "/usr/bin/xattr",
+ "-w",
+ "-s",
+ QUARANTINE_ATTRIBUTE,
+ quarantine_status,
+ ],
+ input: resolved_paths.join("\0"),
+ print_stderr: false)
return if quarantiner.success?
| true |
Other | Homebrew | brew | ed6f2829b18a52b25f57d3317ab63ada1c6f7f86.json | Cask: check support of quarantine's tools
- In some cases (usually old CLT versions) Swift is available but needs an
extra guard to use the quarantine API.
- xattr's native filesystem recursion is an Apple extension which is
not available in Mojave; so let's use xargs.
- Insert a quarantine support check in brew cask doctor.
Fixes Homebrew/homebrew-cask#51554, and fixes Homebrew/homebrew-cask#51538. | Library/Homebrew/cask/utils/quarantine.swift | @@ -7,36 +7,41 @@ struct swifterr: TextOutputStream {
mutating func write(_ string: String) { fputs(string, stderr) }
}
-if (CommandLine.arguments.count < 4) {
- exit(2)
-}
-
-let dataLocationUrl: NSURL = NSURL.init(fileURLWithPath: CommandLine.arguments[1])
-
-var errorBag: NSError?
-
-let quarantineProperties: [String: Any] = [
- kLSQuarantineAgentNameKey as String: "Homebrew Cask",
- kLSQuarantineTypeKey as String: kLSQuarantineTypeWebDownload,
- kLSQuarantineDataURLKey as String: CommandLine.arguments[2],
- kLSQuarantineOriginURLKey as String: CommandLine.arguments[3]
-]
+if #available(macOS 10.10, *) {
+ if (CommandLine.arguments.count < 4) {
+ exit(2)
+ }
-if (dataLocationUrl.checkResourceIsReachableAndReturnError(&errorBag)) {
- do {
- try dataLocationUrl.setResourceValue(
- quarantineProperties as NSDictionary,
- forKey: URLResourceKey.quarantinePropertiesKey
- )
+ let dataLocationUrl: NSURL = NSURL.init(fileURLWithPath: CommandLine.arguments[1])
+
+ var errorBag: NSError?
+
+ let quarantineProperties: [String: Any] = [
+ kLSQuarantineAgentNameKey as String: "Homebrew Cask",
+ kLSQuarantineTypeKey as String: kLSQuarantineTypeWebDownload,
+ kLSQuarantineDataURLKey as String: CommandLine.arguments[2],
+ kLSQuarantineOriginURLKey as String: CommandLine.arguments[3]
+ ]
+
+ if (dataLocationUrl.checkResourceIsReachableAndReturnError(&errorBag)) {
+ do {
+ try dataLocationUrl.setResourceValue(
+ quarantineProperties as NSDictionary,
+ forKey: URLResourceKey.quarantinePropertiesKey
+ )
+ }
+ catch {
+ print(error.localizedDescription, to: &swifterr.stream)
+ exit(1)
+ }
}
- catch {
- print(error.localizedDescription, to: &swifterr.stream)
- exit(1)
+ else {
+ print(errorBag!.localizedDescription, to: &swifterr.stream)
+ exit(3)
}
+
+ exit(0)
}
else {
- print(errorBag!.localizedDescription, to: &swifterr.stream)
- exit(3)
+ exit(5)
}
-
-exit(0) | true |
Other | Homebrew | brew | 367629d2897b839e16cdd4b079bde2a521762c53.json | utils: Use JSON to marshal child errors
Replaces our serialization of child process
errors via Marshal with JSON, preventing
unintentional or malicious code execution outside
of the build sandbox.
Additionally, adds tests for the new behavior. | Library/Homebrew/build.rb | @@ -190,7 +190,20 @@ def fixopt(f)
build = Build.new(formula, options)
build.install
rescue Exception => e # rubocop:disable Lint/RescueException
- Marshal.dump(e, error_pipe)
+ error_hash = JSON.parse e.to_json
+
+ # Special case: need to recreate BuildErrors in full
+ # for proper analytics reporting and error messages.
+ # BuildErrors are specific to build processses and not other
+ # children, which is why we create the necessary state here
+ # and not in Utils.safe_fork.
+ if error_hash["json_class"] == "BuildError"
+ error_hash["cmd"] = e.cmd
+ error_hash["args"] = e.args
+ error_hash["env"] = e.env
+ end
+
+ error_pipe.puts error_hash.to_json
error_pipe.close
exit! 1
end | true |
Other | Homebrew | brew | 367629d2897b839e16cdd4b079bde2a521762c53.json | utils: Use JSON to marshal child errors
Replaces our serialization of child process
errors via Marshal with JSON, preventing
unintentional or malicious code execution outside
of the build sandbox.
Additionally, adds tests for the new behavior. | Library/Homebrew/dev-cmd/test.rb | @@ -93,9 +93,6 @@ def test
exec(*args)
end
end
- rescue ::Test::Unit::AssertionFailedError => e
- ofail "#{f.full_name}: failed"
- puts e.message
rescue Exception => e # rubocop:disable Lint/RescueException
ofail "#{f.full_name}: failed"
puts e, e.backtrace | true |
Other | Homebrew | brew | 367629d2897b839e16cdd4b079bde2a521762c53.json | utils: Use JSON to marshal child errors
Replaces our serialization of child process
errors via Marshal with JSON, preventing
unintentional or malicious code execution outside
of the build sandbox.
Additionally, adds tests for the new behavior. | Library/Homebrew/exceptions.rb | @@ -352,14 +352,16 @@ def initialize(formula)
end
class BuildError < RuntimeError
- attr_reader :formula, :env
- attr_accessor :options
+ attr_reader :cmd, :args, :env
+ attr_accessor :formula, :options
def initialize(formula, cmd, args, env)
@formula = formula
+ @cmd = cmd
+ @args = args
@env = env
- args = args.map { |arg| arg.to_s.gsub " ", "\\ " }.join(" ")
- super "Failed executing: #{cmd} #{args}"
+ pretty_args = args.map { |arg| arg.to_s.gsub " ", "\\ " }.join(" ")
+ super "Failed executing: #{cmd} #{pretty_args}"
end
def issues
@@ -526,12 +528,22 @@ def initialize(cause)
# raised by safe_system in utils.rb
class ErrorDuringExecution < RuntimeError
+ attr_reader :cmd
attr_reader :status
+ attr_reader :output
def initialize(cmd, status:, output: nil)
+ @cmd = cmd
@status = status
+ @output = output
- s = "Failure while executing; `#{cmd.shelljoin.gsub(/\\=/, "=")}` exited with #{status.exitstatus}."
+ exitstatus = if status.respond_to?(:exitstatus)
+ status.exitstatus
+ else
+ status
+ end
+
+ s = "Failure while executing; `#{cmd.shelljoin.gsub(/\\=/, "=")}` exited with #{exitstatus}."
unless [*output].empty?
format_output_line = lambda do |type, line|
@@ -596,3 +608,22 @@ def initialize(bottle_path, formula_path)
EOS
end
end
+
+# Raised when a child process sends us an exception over its error pipe.
+class ChildProcessError < RuntimeError
+ attr_reader :inner
+ attr_reader :inner_class
+
+ def initialize(inner)
+ @inner = inner
+ @inner_class = Object.const_get inner["json_class"]
+
+ super <<~EOS
+ An exception occured within a build process:
+ #{inner_class}: #{inner["m"]}
+ EOS
+
+ # Clobber our real (but irrelevant) backtrace with that of the inner exception.
+ set_backtrace inner["b"]
+ end
+end | true |
Other | Homebrew | brew | 367629d2897b839e16cdd4b079bde2a521762c53.json | utils: Use JSON to marshal child errors
Replaces our serialization of child process
errors via Marshal with JSON, preventing
unintentional or malicious code execution outside
of the build sandbox.
Additionally, adds tests for the new behavior. | Library/Homebrew/formula_installer.rb | @@ -744,14 +744,18 @@ def build
raise "Empty installation"
end
rescue Exception => e # rubocop:disable Lint/RescueException
- e.options = display_options(formula) if e.is_a?(BuildError)
+ if e.is_a? BuildError
+ e.formula = formula
+ e.options = options
+ end
+
ignore_interrupts do
# any exceptions must leave us with nothing installed
formula.update_head_version
formula.prefix.rmtree if formula.prefix.directory?
formula.rack.rmdir_if_possible
end
- raise
+ raise e
end
def link(keg) | true |
Other | Homebrew | brew | 367629d2897b839e16cdd4b079bde2a521762c53.json | utils: Use JSON to marshal child errors
Replaces our serialization of child process
errors via Marshal with JSON, preventing
unintentional or malicious code execution outside
of the build sandbox.
Additionally, adds tests for the new behavior. | Library/Homebrew/global.rb | @@ -1,5 +1,7 @@
require "pathname"
require "English"
+require "json"
+require "json/add/exception"
HOMEBREW_LIBRARY_PATH = Pathname.new(__FILE__).realpath.parent
| true |
Other | Homebrew | brew | 367629d2897b839e16cdd4b079bde2a521762c53.json | utils: Use JSON to marshal child errors
Replaces our serialization of child process
errors via Marshal with JSON, preventing
unintentional or malicious code execution outside
of the build sandbox.
Additionally, adds tests for the new behavior. | Library/Homebrew/postinstall.rb | @@ -15,7 +15,7 @@
formula.extend(Debrew::Formula) if ARGV.debug?
formula.run_post_install
rescue Exception => e # rubocop:disable Lint/RescueException
- Marshal.dump(e, error_pipe)
+ error_pipe.puts e.to_json
error_pipe.close
exit! 1
end | true |
Other | Homebrew | brew | 367629d2897b839e16cdd4b079bde2a521762c53.json | utils: Use JSON to marshal child errors
Replaces our serialization of child process
errors via Marshal with JSON, preventing
unintentional or malicious code execution outside
of the build sandbox.
Additionally, adds tests for the new behavior. | Library/Homebrew/test.rb | @@ -28,7 +28,7 @@
raise "test returned false" if formula.run_test == false
end
rescue Exception => e # rubocop:disable Lint/RescueException
- Marshal.dump(e, error_pipe)
+ error_pipe.puts e.to_json
error_pipe.close
exit! 1
end | true |
Other | Homebrew | brew | 367629d2897b839e16cdd4b079bde2a521762c53.json | utils: Use JSON to marshal child errors
Replaces our serialization of child process
errors via Marshal with JSON, preventing
unintentional or malicious code execution outside
of the build sandbox.
Additionally, adds tests for the new behavior. | Library/Homebrew/test/formula_installer_spec.rb | @@ -4,6 +4,7 @@
require "tab"
require "test/support/fixtures/testball"
require "test/support/fixtures/testball_bottle"
+require "test/support/fixtures/failball"
describe FormulaInstaller do
define_negated_matcher :need_bottle, :be_bottle_unneeded
@@ -28,7 +29,7 @@ def temporary_install(formula)
Tab.clear_cache
expect(Tab.for_keg(keg)).not_to be_poured_from_bottle
- yield formula
+ yield formula if block_given?
ensure
Tab.clear_cache
keg.unlink
@@ -132,4 +133,21 @@ class #{Formulary.class_s(dep_name)} < Formula
fi.check_install_sanity
}.to raise_error(CannotInstallFormulaError)
end
+
+ specify "install fails with BuildError when a system() call fails" do
+ ENV["HOMEBREW_TEST_NO_EXIT_CLEANUP"] = "1"
+ ENV["FAILBALL_BUILD_ERROR"] = "1"
+
+ expect {
+ temporary_install(Failball.new)
+ }.to raise_error(BuildError)
+ end
+
+ specify "install fails with a RuntimeError when #install raises" do
+ ENV["HOMEBREW_TEST_NO_EXIT_CLEANUP"] = "1"
+
+ expect {
+ temporary_install(Failball.new)
+ }.to raise_error(RuntimeError)
+ end
end | true |
Other | Homebrew | brew | 367629d2897b839e16cdd4b079bde2a521762c53.json | utils: Use JSON to marshal child errors
Replaces our serialization of child process
errors via Marshal with JSON, preventing
unintentional or malicious code execution outside
of the build sandbox.
Additionally, adds tests for the new behavior. | Library/Homebrew/test/support/fixtures/failball.rb | @@ -0,0 +1,20 @@
+class Failball < Formula
+ def initialize(name = "failball", path = Pathname.new(__FILE__).expand_path, spec = :stable, alias_path: nil)
+ self.class.instance_eval do
+ stable.url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz"
+ stable.sha256 TESTBALL_SHA256
+ end
+ super
+ end
+
+ def install
+ prefix.install "bin"
+ prefix.install "libexec"
+
+ # This should get marshalled into a BuildError.
+ system "/usr/bin/false" if ENV["FAILBALL_BUILD_ERROR"]
+
+ # This should get marshalled into a RuntimeError.
+ raise "something that isn't a build error happened!"
+ end
+end | true |
Other | Homebrew | brew | 367629d2897b839e16cdd4b079bde2a521762c53.json | utils: Use JSON to marshal child errors
Replaces our serialization of child process
errors via Marshal with JSON, preventing
unintentional or malicious code execution outside
of the build sandbox.
Additionally, adds tests for the new behavior. | Library/Homebrew/test/support/lib/config.rb | @@ -8,7 +8,11 @@
TEST_TMPDIR = ENV.fetch("HOMEBREW_TEST_TMPDIR") do |k|
dir = Dir.mktmpdir("homebrew-tests-", ENV["HOMEBREW_TEMP"] || "/tmp")
- at_exit { FileUtils.remove_entry(dir) }
+ at_exit do
+ # Child processes inherit this at_exit handler, but we don't want them
+ # to clean TEST_TMPDIR up prematurely (i.e., when they exit early for a test).
+ FileUtils.remove_entry(dir) unless ENV["HOMEBREW_TEST_NO_EXIT_CLEANUP"]
+ end
ENV[k] = dir
end
| true |
Other | Homebrew | brew | 367629d2897b839e16cdd4b079bde2a521762c53.json | utils: Use JSON to marshal child errors
Replaces our serialization of child process
errors via Marshal with JSON, preventing
unintentional or malicious code execution outside
of the build sandbox.
Additionally, adds tests for the new behavior. | Library/Homebrew/test/utils/fork_spec.rb | @@ -0,0 +1,21 @@
+require "utils/fork"
+
+describe Utils do
+ describe "#safe_fork" do
+ it "raises a RuntimeError on an error that isn't ErrorDuringExecution" do
+ expect {
+ described_class.safe_fork do
+ raise "this is an exception in the child"
+ end
+ }.to raise_error(RuntimeError)
+ end
+
+ it "raises an ErrorDuringExecution on one in the child" do
+ expect {
+ described_class.safe_fork do
+ safe_system "/usr/bin/false"
+ end
+ }.to raise_error(ErrorDuringExecution)
+ end
+ end
+end | true |
Other | Homebrew | brew | 367629d2897b839e16cdd4b079bde2a521762c53.json | utils: Use JSON to marshal child errors
Replaces our serialization of child process
errors via Marshal with JSON, preventing
unintentional or malicious code execution outside
of the build sandbox.
Additionally, adds tests for the new behavior. | Library/Homebrew/utils/fork.rb | @@ -2,6 +2,26 @@
require "socket"
module Utils
+ def self.rewrite_child_error(child_error)
+ error = if child_error.inner_class == ErrorDuringExecution
+ ErrorDuringExecution.new(child_error.inner["cmd"],
+ status: child_error.inner["status"],
+ output: child_error.inner["output"])
+ elsif child_error.inner_class == BuildError
+ # We fill `BuildError#formula` and `BuildError#options` in later,
+ # when we rescue this in `FormulaInstaller#build`.
+ BuildError.new(nil, child_error.inner["cmd"],
+ child_error.inner["args"], child_error.inner["env"])
+ else
+ # Everything other error in the child just becomes a RuntimeError.
+ RuntimeError.new(child_error.message)
+ end
+
+ error.set_backtrace child_error.backtrace
+
+ error
+ end
+
def self.safe_fork(&_block)
Dir.mktmpdir("homebrew", HOMEBREW_TEMP) do |tmpdir|
UNIXServer.open("#{tmpdir}/socket") do |server|
@@ -15,7 +35,18 @@ def self.safe_fork(&_block)
write.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
yield
rescue Exception => e # rubocop:disable Lint/RescueException
- Marshal.dump(e, write)
+ error_hash = JSON.parse e.to_json
+
+ # Special case: We need to recreate ErrorDuringExecutions
+ # for proper error messages and because other code expects
+ # to rescue them further down.
+ if e.is_a?(ErrorDuringExecution)
+ error_hash["cmd"] = e.cmd
+ error_hash["status"] = e.status.exitstatus
+ error_hash["output"] = e.output
+ end
+
+ write.puts error_hash.to_json
write.close
exit!
else
@@ -33,10 +64,20 @@ def self.safe_fork(&_block)
socket.close
end
write.close
- data = read.read
+ # Each line on the error pipe contains a JSON-serialized exception.
+ # We read the first, since only one is necessary for a failure.
+ data = read.gets
read.close
Process.wait(pid) unless socket.nil?
- raise Marshal.load(data) unless data.nil? || data.empty? # rubocop:disable Security/MarshalLoad
+
+ if data && !data.empty?
+ error_hash = JSON.parse(data) unless data.nil? || data.empty?
+
+ e = ChildProcessError.new(error_hash)
+
+ raise rewrite_child_error(e)
+ end
+
raise Interrupt if $CHILD_STATUS.exitstatus == 130
raise "Forked child process failed: #{$CHILD_STATUS}" unless $CHILD_STATUS.success?
end | true |
Other | Homebrew | brew | 6a38b0189c2a321580ede867870bf10b79dc365c.json | docs/Formula-Cookbook: preach what we practise | docs/Formula-Cookbook.md | @@ -396,12 +396,7 @@ system "make", "target", "VAR2=value1", "VAR2=value2", "VAR3=values can have spa
```
```ruby
-args = %W[
- CC=#{ENV.cc}
- PREFIX=#{prefix}
-]
-
-system "make", *args
+system "make", "CC=#{ENV.cc}", "PREFIX=#{prefix}"
```
Note that values *can* contain unescaped spaces if you use the multiple-argument form of `system`. | false |
Other | Homebrew | brew | 6db4b7220094205424e4174c43319be273a4b9de.json | tap: fix GitHub naming. | Library/Homebrew/tap.rb | @@ -3,9 +3,9 @@
# a {Tap} is used to extend the formulae provided by Homebrew core.
# Usually, it's synced with a remote git repository. And it's likely
-# a Github repository with the name of `user/homebrew-repo`. In such
+# a GitHub repository with the name of `user/homebrew-repo`. In such
# case, `user/repo` will be used as the {#name} of this {Tap}, where
-# {#user} represents Github username and {#repo} represents repository
+# {#user} represents GitHub username and {#repo} represents repository
# name without leading `homebrew-`.
class Tap
extend Cachable
@@ -52,7 +52,7 @@ def self.default_cask_tap
extend Enumerable
- # The user name of this {Tap}. Usually, it's the Github username of
+ # The user name of this {Tap}. Usually, it's the GitHub username of
# this #{Tap}'s remote repository.
attr_reader :user
| false |
Other | Homebrew | brew | 32ad22395bddf3eda906b70c2b3d814e5af2a498.json | Remove some `#popen_read`s. | Library/Homebrew/extend/os/mac/system_config.rb | @@ -6,12 +6,11 @@ def describe_java
# java_home doesn't exist on all macOSs; it might be missing on older versions.
return "N/A" unless File.executable? "/usr/libexec/java_home"
- java_xml = Utils.popen_read("/usr/libexec/java_home", "--xml", "--failfast", err: :close)
- return "N/A" unless $CHILD_STATUS.success?
+ out, _, status = system_command("/usr/libexec/java_home", args: ["--xml", "--failfast"], print_stderr: false)
+ return "N/A" unless status.success?
javas = []
- REXML::XPath.each(
- REXML::Document.new(java_xml), "//key[text()='JVMVersion']/following-sibling::string"
- ) do |item|
+ xml = REXML::Document.new(out)
+ REXML::XPath.each(xml, "//key[text()='JVMVersion']/following-sibling::string") do |item|
javas << item.text
end
javas.uniq.join(", ") | true |
Other | Homebrew | brew | 32ad22395bddf3eda906b70c2b3d814e5af2a498.json | Remove some `#popen_read`s. | Library/Homebrew/readall.rb | @@ -73,21 +73,20 @@ def valid_tap?(tap, options = {})
private
def syntax_errors_or_warnings?(rb)
- # Retrieve messages about syntax errors/warnings printed to `$stderr`, but
- # discard a `Syntax OK` printed to `$stdout` (in absence of syntax errors).
- messages = Utils.popen_read("#{RUBY_PATH} -c -w #{rb} 2>&1 >/dev/null")
+ # Retrieve messages about syntax errors/warnings printed to `$stderr`.
+ _, err, status = system_command(RUBY_PATH, args: ["-c", "-w", rb], print_stderr: false)
# Ignore unnecessary warning about named capture conflicts.
# See https://bugs.ruby-lang.org/issues/12359.
- messages = messages.lines
- .grep_v(/named capture conflicts a local variable/)
- .join
+ messages = err.lines
+ .grep_v(/named capture conflicts a local variable/)
+ .join
$stderr.print messages
# Only syntax errors result in a non-zero status code. To detect syntax
# warnings we also need to inspect the output to `$stderr`.
- !$CHILD_STATUS.success? || !messages.chomp.empty?
+ !status.success? || !messages.chomp.empty?
end
end
end | true |
Other | Homebrew | brew | 32ad22395bddf3eda906b70c2b3d814e5af2a498.json | Remove some `#popen_read`s. | Library/Homebrew/requirements/java_requirement.rb | @@ -122,7 +122,7 @@ def oracle_java_os
end
def satisfies_version(java)
- java_version_s = Utils.popen_read(java, "-version", err: :out)[/\d+.\d/]
+ java_version_s = system_command(java, args: ["-version"], print_stderr: false).stderr[/\d+.\d/]
return false unless java_version_s
java_version = Version.create(java_version_s)
needed_version = Version.create(version_without_plus) | true |
Other | Homebrew | brew | 32ad22395bddf3eda906b70c2b3d814e5af2a498.json | Remove some `#popen_read`s. | Library/Homebrew/system_command.rb | @@ -30,16 +30,16 @@ def self.run!(command, **options)
def run!
puts command.shelljoin.gsub(/\\=/, "=") if verbose? || ARGV.debug?
- @merged_output = []
+ @output = []
each_output_line do |type, line|
case type
when :stdout
$stdout << line if print_stdout?
- @merged_output << [:stdout, line]
+ @output << [:stdout, line]
when :stderr
$stderr << line if print_stderr?
- @merged_output << [:stderr, line]
+ @output << [:stderr, line]
end
end
@@ -100,7 +100,7 @@ def assert_success
return if @status.success?
raise ErrorDuringExecution.new(command,
status: @status,
- output: @merged_output)
+ output: @output)
end
def expanded_args
@@ -128,7 +128,7 @@ def each_output_line(&b)
@status = raw_wait_thr.value
rescue SystemCallError => e
@status = $CHILD_STATUS
- @merged_output << [:stderr, e.message]
+ @output << [:stderr, e.message]
end
def write_input_to(raw_stdin)
@@ -158,22 +158,29 @@ def each_line_from(sources)
end
def result
- output = @merged_output.each_with_object(stdout: "", stderr: "") do |(type, line), hash|
- hash[type] << line
- end
-
- Result.new(command, output[:stdout], output[:stderr], @status)
+ Result.new(command, @output, @status)
end
class Result
- attr_accessor :command, :stdout, :stderr, :status, :exit_status
-
- def initialize(command, stdout, stderr, status)
- @command = command
- @stdout = stdout
- @stderr = stderr
- @status = status
- @exit_status = status.exitstatus
+ attr_accessor :command, :status, :exit_status
+
+ def initialize(command, output, status)
+ @command = command
+ @output = output
+ @status = status
+ @exit_status = status.exitstatus
+ end
+
+ def stdout
+ @stdout ||= @output.select { |type,| type == :stdout }
+ .map { |_, line| line }
+ .join
+ end
+
+ def stderr
+ @stderr ||= @output.select { |type,| type == :stderr }
+ .map { |_, line| line }
+ .join
end
def success? | true |
Other | Homebrew | brew | 32ad22395bddf3eda906b70c2b3d814e5af2a498.json | Remove some `#popen_read`s. | Library/Homebrew/system_config.rb | @@ -79,9 +79,9 @@ def kernel
def describe_java
return "N/A" unless which "java"
- java_version = Utils.popen_read("java", "-version")
- return "N/A" unless $CHILD_STATUS.success?
- java_version[/java version "([\d\._]+)"/, 1] || "N/A"
+ _, err, status = system_command("java", args: ["-version"], print_stderr: false)
+ return "N/A" unless status.success?
+ err[/java version "([\d\._]+)"/, 1] || "N/A"
end
def describe_git
@@ -90,12 +90,13 @@ def describe_git
end
def describe_curl
- curl_version_output = Utils.popen_read("#{curl_executable} --version", err: :close)
- curl_version_output =~ /^curl ([\d\.]+)/
- curl_version = Regexp.last_match(1)
- "#{curl_version} => #{curl_executable}"
- rescue
- "N/A"
+ out, = system_command(curl_executable, args: ["--version"])
+
+ if /^curl (?<curl_version>[\d\.]+)/ =~ out
+ "#{curl_version} => #{curl_executable}"
+ else
+ "N/A"
+ end
end
def dump_verbose_config(f = $stdout) | true |
Other | Homebrew | brew | 32ad22395bddf3eda906b70c2b3d814e5af2a498.json | Remove some `#popen_read`s. | Library/Homebrew/test/cask/pkg_spec.rb | @@ -150,7 +150,7 @@
"/usr/sbin/pkgutil",
args: ["--pkg-info-plist", pkg_id],
).and_return(
- SystemCommand::Result.new(nil, pkg_info_plist, nil, instance_double(Process::Status, exitstatus: 0)),
+ SystemCommand::Result.new(nil, [[:stdout, pkg_info_plist]], instance_double(Process::Status, exitstatus: 0)),
)
info = pkg.info | true |
Other | Homebrew | brew | 32ad22395bddf3eda906b70c2b3d814e5af2a498.json | Remove some `#popen_read`s. | Library/Homebrew/test/java_requirement_spec.rb | @@ -55,7 +55,7 @@
def setup_java_with_version(version)
IO.write java, <<~SH
#!/bin/sh
- echo 'java version "#{version}"'
+ echo 'java version "#{version}"' 1>&2
SH
FileUtils.chmod "+x", java
end | true |
Other | Homebrew | brew | 32ad22395bddf3eda906b70c2b3d814e5af2a498.json | Remove some `#popen_read`s. | Library/Homebrew/test/support/helper/cask/fake_system_command.rb | @@ -52,7 +52,7 @@ def self.run(command_string, options = {})
if response.respond_to?(:call)
response.call(command_string, options)
else
- SystemCommand::Result.new(command, response, "", OpenStruct.new(exitstatus: 0))
+ SystemCommand::Result.new(command, [[:stdout, response]], OpenStruct.new(exitstatus: 0))
end
end
| true |
Other | Homebrew | brew | 32ad22395bddf3eda906b70c2b3d814e5af2a498.json | Remove some `#popen_read`s. | Library/Homebrew/test/system_command_result_spec.rb | @@ -2,8 +2,14 @@
describe SystemCommand::Result do
describe "#to_ary" do
+ let(:output) {
+ [
+ [:stdout, "output"],
+ [:stderr, "error"],
+ ]
+ }
subject(:result) {
- described_class.new([], "output", "error", instance_double(Process::Status, exitstatus: 0, success?: true))
+ described_class.new([], output, instance_double(Process::Status, exitstatus: 0, success?: true))
}
it "can be destructed like `Open3.capture3`" do
@@ -16,7 +22,9 @@
end
describe "#plist" do
- subject { described_class.new(command, stdout, "", instance_double(Process::Status, exitstatus: 0)).plist }
+ subject {
+ described_class.new(command, [[:stdout, stdout]], instance_double(Process::Status, exitstatus: 0)).plist
+ }
let(:command) { ["true"] }
let(:garbage) { | true |
Other | Homebrew | brew | 86b964745038eebff6218e97735e6344b6f3e42a.json | utils: Use JSON to marshal child errors
Replaces our serialization of child process
errors via Marshal with JSON, preventing
unintentional or malicious code execution outside
of the build sandbox.
Additionally, adds tests for the new behavior. | Library/Homebrew/build.rb | @@ -190,7 +190,20 @@ def fixopt(f)
build = Build.new(formula, options)
build.install
rescue Exception => e # rubocop:disable Lint/RescueException
- Marshal.dump(e, error_pipe)
+ error_hash = JSON.parse e.to_json
+
+ # Special case: need to recreate BuildErrors in full
+ # for proper analytics reporting and error messages.
+ # BuildErrors are specific to build processses and not other
+ # children, which is why we create the necessary state here
+ # and not in Utils.safe_fork.
+ if error_hash["json_class"] == "BuildError"
+ error_hash["cmd"] = e.cmd
+ error_hash["args"] = e.args
+ error_hash["env"] = e.env
+ end
+
+ error_pipe.puts error_hash.to_json
error_pipe.close
exit! 1
end | true |
Other | Homebrew | brew | 86b964745038eebff6218e97735e6344b6f3e42a.json | utils: Use JSON to marshal child errors
Replaces our serialization of child process
errors via Marshal with JSON, preventing
unintentional or malicious code execution outside
of the build sandbox.
Additionally, adds tests for the new behavior. | Library/Homebrew/dev-cmd/test.rb | @@ -93,9 +93,6 @@ def test
exec(*args)
end
end
- rescue ::Test::Unit::AssertionFailedError => e
- ofail "#{f.full_name}: failed"
- puts e.message
rescue Exception => e # rubocop:disable Lint/RescueException
ofail "#{f.full_name}: failed"
puts e, e.backtrace | true |
Other | Homebrew | brew | 86b964745038eebff6218e97735e6344b6f3e42a.json | utils: Use JSON to marshal child errors
Replaces our serialization of child process
errors via Marshal with JSON, preventing
unintentional or malicious code execution outside
of the build sandbox.
Additionally, adds tests for the new behavior. | Library/Homebrew/exceptions.rb | @@ -352,14 +352,16 @@ def initialize(formula)
end
class BuildError < RuntimeError
- attr_reader :formula, :env
- attr_accessor :options
+ attr_reader :cmd, :args, :env
+ attr_accessor :formula, :options
def initialize(formula, cmd, args, env)
@formula = formula
+ @cmd = cmd
+ @args = args
@env = env
- args = args.map { |arg| arg.to_s.gsub " ", "\\ " }.join(" ")
- super "Failed executing: #{cmd} #{args}"
+ pretty_args = args.map { |arg| arg.to_s.gsub " ", "\\ " }.join(" ")
+ super "Failed executing: #{cmd} #{pretty_args}"
end
def issues
@@ -526,12 +528,22 @@ def initialize(cause)
# raised by safe_system in utils.rb
class ErrorDuringExecution < RuntimeError
+ attr_reader :cmd
attr_reader :status
+ attr_reader :output
def initialize(cmd, status:, output: nil)
+ @cmd = cmd
@status = status
+ @output = output
- s = "Failure while executing; `#{cmd.shelljoin.gsub(/\\=/, "=")}` exited with #{status.exitstatus}."
+ exitstatus = if status.respond_to?(:exitstatus)
+ status.exitstatus
+ else
+ status
+ end
+
+ s = "Failure while executing; `#{cmd.shelljoin.gsub(/\\=/, "=")}` exited with #{exitstatus}."
unless [*output].empty?
format_output_line = lambda do |type, line|
@@ -596,3 +608,22 @@ def initialize(bottle_path, formula_path)
EOS
end
end
+
+# Raised when a child process sends us an exception over its error pipe.
+class ChildProcessError < RuntimeError
+ attr_reader :inner
+ attr_reader :inner_class
+
+ def initialize(inner)
+ @inner = inner
+ @inner_class = Object.const_get inner["json_class"]
+
+ super <<~EOS
+ An exception occured within a build process:
+ #{inner_class}: #{inner["m"]}
+ EOS
+
+ # Clobber our real (but irrelevant) backtrace with that of the inner exception.
+ set_backtrace inner["b"]
+ end
+end | true |
Other | Homebrew | brew | 86b964745038eebff6218e97735e6344b6f3e42a.json | utils: Use JSON to marshal child errors
Replaces our serialization of child process
errors via Marshal with JSON, preventing
unintentional or malicious code execution outside
of the build sandbox.
Additionally, adds tests for the new behavior. | Library/Homebrew/formula_installer.rb | @@ -744,14 +744,18 @@ def build
raise "Empty installation"
end
rescue Exception => e # rubocop:disable Lint/RescueException
- e.options = display_options(formula) if e.is_a?(BuildError)
+ if e.is_a? BuildError
+ e.formula = formula
+ e.options = options
+ end
+
ignore_interrupts do
# any exceptions must leave us with nothing installed
formula.update_head_version
formula.prefix.rmtree if formula.prefix.directory?
formula.rack.rmdir_if_possible
end
- raise
+ raise e
end
def link(keg) | true |
Other | Homebrew | brew | 86b964745038eebff6218e97735e6344b6f3e42a.json | utils: Use JSON to marshal child errors
Replaces our serialization of child process
errors via Marshal with JSON, preventing
unintentional or malicious code execution outside
of the build sandbox.
Additionally, adds tests for the new behavior. | Library/Homebrew/global.rb | @@ -1,5 +1,7 @@
require "pathname"
require "English"
+require "json"
+require "json/add/core"
HOMEBREW_LIBRARY_PATH = Pathname.new(__FILE__).realpath.parent
| true |
Other | Homebrew | brew | 86b964745038eebff6218e97735e6344b6f3e42a.json | utils: Use JSON to marshal child errors
Replaces our serialization of child process
errors via Marshal with JSON, preventing
unintentional or malicious code execution outside
of the build sandbox.
Additionally, adds tests for the new behavior. | Library/Homebrew/postinstall.rb | @@ -15,7 +15,7 @@
formula.extend(Debrew::Formula) if ARGV.debug?
formula.run_post_install
rescue Exception => e # rubocop:disable Lint/RescueException
- Marshal.dump(e, error_pipe)
+ error_pipe.puts e.to_json
error_pipe.close
exit! 1
end | true |
Other | Homebrew | brew | 86b964745038eebff6218e97735e6344b6f3e42a.json | utils: Use JSON to marshal child errors
Replaces our serialization of child process
errors via Marshal with JSON, preventing
unintentional or malicious code execution outside
of the build sandbox.
Additionally, adds tests for the new behavior. | Library/Homebrew/test.rb | @@ -28,7 +28,7 @@
raise "test returned false" if formula.run_test == false
end
rescue Exception => e # rubocop:disable Lint/RescueException
- Marshal.dump(e, error_pipe)
+ error_pipe.puts e.to_json
error_pipe.close
exit! 1
end | true |
Other | Homebrew | brew | 86b964745038eebff6218e97735e6344b6f3e42a.json | utils: Use JSON to marshal child errors
Replaces our serialization of child process
errors via Marshal with JSON, preventing
unintentional or malicious code execution outside
of the build sandbox.
Additionally, adds tests for the new behavior. | Library/Homebrew/test/formula_installer_spec.rb | @@ -4,6 +4,7 @@
require "tab"
require "test/support/fixtures/testball"
require "test/support/fixtures/testball_bottle"
+require "test/support/fixtures/failball"
describe FormulaInstaller do
define_negated_matcher :need_bottle, :be_bottle_unneeded
@@ -28,7 +29,7 @@ def temporary_install(formula)
Tab.clear_cache
expect(Tab.for_keg(keg)).not_to be_poured_from_bottle
- yield formula
+ yield formula if block_given?
ensure
Tab.clear_cache
keg.unlink
@@ -132,4 +133,21 @@ class #{Formulary.class_s(dep_name)} < Formula
fi.check_install_sanity
}.to raise_error(CannotInstallFormulaError)
end
+
+ specify "install fails with BuildError when a system() call fails" do
+ ENV["HOMEBREW_TEST_NO_EXIT_CLEANUP"] = "1"
+ ENV["FAILBALL_BUILD_ERROR"] = "1"
+
+ expect {
+ temporary_install(Failball.new)
+ }.to raise_error(BuildError)
+ end
+
+ specify "install fails with a RuntimeError when #install raises" do
+ ENV["HOMEBREW_TEST_NO_EXIT_CLEANUP"] = "1"
+
+ expect {
+ temporary_install(Failball.new)
+ }.to raise_error(RuntimeError)
+ end
end | true |
Other | Homebrew | brew | 86b964745038eebff6218e97735e6344b6f3e42a.json | utils: Use JSON to marshal child errors
Replaces our serialization of child process
errors via Marshal with JSON, preventing
unintentional or malicious code execution outside
of the build sandbox.
Additionally, adds tests for the new behavior. | Library/Homebrew/test/support/fixtures/failball.rb | @@ -0,0 +1,20 @@
+class Failball < Formula
+ def initialize(name = "failball", path = Pathname.new(__FILE__).expand_path, spec = :stable, alias_path: nil)
+ self.class.instance_eval do
+ stable.url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz"
+ stable.sha256 TESTBALL_SHA256
+ end
+ super
+ end
+
+ def install
+ prefix.install "bin"
+ prefix.install "libexec"
+
+ # This should get marshalled into a BuildError.
+ system "/usr/bin/false" if ENV["FAILBALL_BUILD_ERROR"]
+
+ # This should get marshalled into a RuntimeError.
+ raise "something that isn't a build error happened!"
+ end
+end | true |
Other | Homebrew | brew | 86b964745038eebff6218e97735e6344b6f3e42a.json | utils: Use JSON to marshal child errors
Replaces our serialization of child process
errors via Marshal with JSON, preventing
unintentional or malicious code execution outside
of the build sandbox.
Additionally, adds tests for the new behavior. | Library/Homebrew/test/support/lib/config.rb | @@ -8,7 +8,11 @@
TEST_TMPDIR = ENV.fetch("HOMEBREW_TEST_TMPDIR") do |k|
dir = Dir.mktmpdir("homebrew-tests-", ENV["HOMEBREW_TEMP"] || "/tmp")
- at_exit { FileUtils.remove_entry(dir) }
+ at_exit do
+ # Child processes inherit this at_exit handler, but we don't want them
+ # to clean TEST_TMPDIR up prematurely (i.e., when they exit early for a test).
+ FileUtils.remove_entry(dir) unless ENV["HOMEBREW_TEST_NO_EXIT_CLEANUP"]
+ end
ENV[k] = dir
end
| true |
Other | Homebrew | brew | 86b964745038eebff6218e97735e6344b6f3e42a.json | utils: Use JSON to marshal child errors
Replaces our serialization of child process
errors via Marshal with JSON, preventing
unintentional or malicious code execution outside
of the build sandbox.
Additionally, adds tests for the new behavior. | Library/Homebrew/test/utils/fork_spec.rb | @@ -0,0 +1,21 @@
+require "utils/fork"
+
+describe Utils do
+ describe "#safe_fork" do
+ it "raises a RuntimeError on an error that isn't ErrorDuringExecution" do
+ expect {
+ described_class.safe_fork do
+ raise "this is an exception in the child"
+ end
+ }.to raise_error(RuntimeError)
+ end
+
+ it "raises an ErrorDuringExecution on one in the child" do
+ expect {
+ described_class.safe_fork do
+ safe_system "/usr/bin/false"
+ end
+ }.to raise_error(ErrorDuringExecution)
+ end
+ end
+end | true |
Other | Homebrew | brew | 86b964745038eebff6218e97735e6344b6f3e42a.json | utils: Use JSON to marshal child errors
Replaces our serialization of child process
errors via Marshal with JSON, preventing
unintentional or malicious code execution outside
of the build sandbox.
Additionally, adds tests for the new behavior. | Library/Homebrew/utils/fork.rb | @@ -2,6 +2,26 @@
require "socket"
module Utils
+ def self.rewrite_child_error(child_error)
+ error = if child_error.inner_class == ErrorDuringExecution
+ ErrorDuringExecution.new(child_error.inner["cmd"],
+ status: child_error.inner["status"],
+ output: child_error.inner["output"])
+ elsif child_error.inner_class == BuildError
+ # We fill `BuildError#formula` and `BuildError#options` in later,
+ # when we rescue this in `FormulaInstaller#build`.
+ BuildError.new(nil, child_error.inner["cmd"],
+ child_error.inner["args"], child_error.inner["env"])
+ else
+ # Everything other error in the child just becomes a RuntimeError.
+ RuntimeError.new(child_error.message)
+ end
+
+ error.set_backtrace child_error.backtrace
+
+ error
+ end
+
def self.safe_fork(&_block)
Dir.mktmpdir("homebrew", HOMEBREW_TEMP) do |tmpdir|
UNIXServer.open("#{tmpdir}/socket") do |server|
@@ -15,7 +35,18 @@ def self.safe_fork(&_block)
write.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
yield
rescue Exception => e # rubocop:disable Lint/RescueException
- Marshal.dump(e, write)
+ error_hash = JSON.parse e.to_json
+
+ # Special case: We need to recreate ErrorDuringExecutions
+ # for proper error messages and because other code expects
+ # to rescue them further down.
+ if e.is_a?(ErrorDuringExecution)
+ error_hash["cmd"] = e.cmd
+ error_hash["status"] = e.status.exitstatus
+ error_hash["output"] = e.output
+ end
+
+ write.puts error_hash.to_json
write.close
exit!
else
@@ -33,10 +64,20 @@ def self.safe_fork(&_block)
socket.close
end
write.close
- data = read.read
+ # Each line on the error pipe contains a JSON-serialized exception.
+ # We read the first, since only one is necessary for a failure.
+ data = read.gets
read.close
Process.wait(pid) unless socket.nil?
- raise Marshal.load(data) unless data.nil? || data.empty? # rubocop:disable Security/MarshalLoad
+
+ if data && !data.empty?
+ error_hash = JSON.parse(data) unless data.nil? || data.empty?
+
+ e = ChildProcessError.new(error_hash)
+
+ raise rewrite_child_error(e)
+ end
+
raise Interrupt if $CHILD_STATUS.exitstatus == 130
raise "Forked child process failed: #{$CHILD_STATUS}" unless $CHILD_STATUS.success?
end | true |
Other | Homebrew | brew | ec9e45a8f062cbd00ad9fdd64d4f3f35c5c578fd.json | tests: handle file leaks and SVN test prompt.
- Ignore files that are generated by `brew tests`
- Make the SVN tests work without prompting for GitHub's SSL certificate | .gitignore | @@ -18,6 +18,8 @@
/Library/Homebrew/test/bin
/Library/Homebrew/test/coverage
/Library/Homebrew/test/fs_leak_log
+/Library/Homebrew/test/.gem
+/Library/Homebrew/test/.subversion
/Library/Homebrew/tmp
/Library/Homebrew/.npmignore
/Library/LinkedKegs | true |
Other | Homebrew | brew | ec9e45a8f062cbd00ad9fdd64d4f3f35c5c578fd.json | tests: handle file leaks and SVN test prompt.
- Ignore files that are generated by `brew tests`
- Make the SVN tests work without prompting for GitHub's SSL certificate | Library/Homebrew/test/utils/svn_spec.rb | @@ -32,7 +32,9 @@
it "returns true when remote exists", :needs_network, :needs_svn do
HOMEBREW_CACHE.cd do
- system HOMEBREW_SHIMS_PATH/"scm/svn", "checkout", "https://github.com/Homebrew/install"
+ system HOMEBREW_SHIMS_PATH/"scm/svn", "checkout",
+ "--non-interactive", "--trust-server-cert", "--quiet",
+ "https://github.com/Homebrew/install"
end
expect(described_class).to be_svn_remote_exists(HOMEBREW_CACHE/"install") | true |
Other | Homebrew | brew | ec9e45a8f062cbd00ad9fdd64d4f3f35c5c578fd.json | tests: handle file leaks and SVN test prompt.
- Ignore files that are generated by `brew tests`
- Make the SVN tests work without prompting for GitHub's SSL certificate | Library/Homebrew/utils/svn.rb | @@ -10,6 +10,7 @@ def self.svn_available?
def self.svn_remote_exists?(url)
return true unless svn_available?
- quiet_system "svn", "ls", url, "--depth", "empty"
+ ssl_args = ["--non-interactive", "--trust-server-cert"] if ENV["HOMEBREW_TEST_ONLINE"]
+ quiet_system "svn", "ls", url, "--depth", "empty", *ssl_args
end
end | true |
Other | Homebrew | brew | 9102c120bb0ab57added0ea60edcc160ce37e136.json | cleanup: fix go_cache cleanup | Library/Homebrew/cleanup.rb | @@ -39,6 +39,12 @@ def nested_cache?
directory? && %w[go_cache glide_home java_cache npm_cache gclient_cache].include?(basename.to_s)
end
+ def go_cache_directory?
+ # Go makes its cache contents read-only to ensure cache integrity,
+ # which makes sense but is something we need to undo for cleanup.
+ directory? && %w[go_cache].include?(basename.to_s)
+ end
+
def prune?(days)
return false unless days
return true if days.zero?
@@ -228,6 +234,7 @@ def cleanup_cache(entries = nil)
entries ||= [cache, cache/"Cask"].select(&:directory?).flat_map(&:children)
entries.each do |path|
+ FileUtils.chmod_R 0755, path if path.go_cache_directory? && !dry_run?
next cleanup_path(path) { path.unlink } if path.incomplete?
next cleanup_path(path) { FileUtils.rm_rf path } if path.nested_cache?
| false |
Other | Homebrew | brew | b54682f7091724fee2537b25a2dcc4d084d6a773.json | Avoid network call in `#initialize`. | Library/Homebrew/download_strategy.rb | @@ -188,11 +188,8 @@ def extract_ref(specs)
end
class AbstractFileDownloadStrategy < AbstractDownloadStrategy
- attr_reader :temporary_path
-
- def initialize(url, name, version, **meta)
- super
- @temporary_path = Pathname.new("#{cached_location}.incomplete")
+ def temporary_path
+ @temporary_path ||= Pathname.new("#{cached_location}.incomplete")
end
def symlink_location | false |
Other | Homebrew | brew | ae18bdf1619103ab6a5b78d94df9c150ae8e0f03.json | Skip `mtime` for non-existent symlink. | Library/Homebrew/cleanup.rb | @@ -43,6 +43,8 @@ def prune?(days)
return false unless days
return true if days.zero?
+ return true if symlink? && !exist?
+
# TODO: Replace with ActiveSupport's `.days.ago`.
mtime < ((@time ||= Time.now) - days * 60 * 60 * 24)
end | false |
Other | Homebrew | brew | 9b50fd81d729080b746b9637ad3a0c59049b96a3.json | Move everything into one file. | Library/Homebrew/update_migrator.rb | @@ -1,39 +1,374 @@
-require "update_migrator/cache_entries_to_double_dashes"
-require "update_migrator/cache_entries_to_symlinks"
-require "update_migrator/legacy_cache"
-require "update_migrator/legacy_keg_symlinks"
-require "update_migrator/legacy_repository"
+require "hbc/cask_loader"
+require "hbc/download"
module UpdateMigrator
- module_function
+ class << self
+ def formula_resources(formula)
+ specs = [formula.stable, formula.devel, formula.head].compact
- def formula_resources(formula)
- specs = [formula.stable, formula.devel, formula.head].compact
+ [*formula.bottle&.resource] + specs.flat_map do |spec|
+ [
+ spec,
+ *spec.resources.values,
+ *spec.patches.select(&:external?).map(&:resource),
+ ]
+ end
+ end
+ private :formula_resources
- [*formula.bottle&.resource] + specs.flat_map do |spec|
- [
- spec,
- *spec.resources.values,
- *spec.patches.select(&:external?).map(&:resource),
- ]
+ def parse_extname(url)
+ uri_path = if URI::DEFAULT_PARSER.make_regexp =~ url
+ uri = URI(url)
+ uri.query ? "#{uri.path}?#{uri.query}" : uri.path
+ else
+ url
+ end
+
+ # Given a URL like https://example.com/download.php?file=foo-1.0.tar.gz
+ # the extension we want is ".tar.gz", not ".php".
+ Pathname.new(uri_path).ascend do |path|
+ ext = path.extname[/[^?&]+/]
+ return ext if ext
+ end
+
+ nil
end
- end
+ private :parse_extname
+
+ def migrate_cache_entries_to_double_dashes(initial_version)
+ return if initial_version && initial_version > "1.7.1"
+
+ return if ENV.key?("HOMEBREW_DISABLE_LOAD_FORMULA")
- def parse_extname(url)
- uri_path = if URI::DEFAULT_PARSER.make_regexp =~ url
- uri = URI(url)
- uri.query ? "#{uri.path}?#{uri.query}" : uri.path
- else
- url
+ ohai "Migrating cache entries..."
+
+ Formula.each do |formula|
+ formula_resources(formula).each do |resource|
+ downloader = resource.downloader
+
+ url = downloader.url
+ name = resource.download_name
+ version = resource.version
+
+ extname = parse_extname(url)
+ old_location = downloader.cache/"#{name}-#{version}#{extname}"
+ new_location = downloader.cache/"#{name}--#{version}#{extname}"
+
+ next unless old_location.file?
+
+ if new_location.exist?
+ begin
+ FileUtils.rm_rf old_location
+ rescue Errno::EACCES
+ opoo "Could not remove #{old_location}, please do so manually."
+ end
+ else
+ begin
+ FileUtils.mv old_location, new_location
+ rescue Errno::EACCES
+ opoo "Could not move #{old_location} to #{new_location}, please do so manually."
+ end
+ end
+ end
+ end
end
- # Given a URL like https://example.com/download.php?file=foo-1.0.tar.gz
- # the extension we want is ".tar.gz", not ".php".
- Pathname.new(uri_path).ascend do |path|
- ext = path.extname[/[^?&]+/]
- return ext if ext
+ def migrate_cache_entries_to_symlinks(initial_version)
+ return if initial_version && initial_version > "1.7.2"
+
+ return if ENV.key?("HOMEBREW_DISABLE_LOAD_FORMULA")
+
+ ohai "Migrating cache entries..."
+
+ cache_entries = lambda do |path|
+ if path.directory?
+ path.children
+ .reject(&:symlink?)
+ .select(&:file?)
+ .map { |child| child.basename.to_s.sub(/\-\-.*/, "") }
+ .uniq
+ else
+ []
+ end
+ end
+
+ load_formula = lambda do |formula|
+ begin
+ Formula[formula]
+ rescue FormulaUnavailableError
+ nil
+ end
+ end
+
+ load_cask = lambda do |cask|
+ begin
+ Hbc::CaskLoader.load(cask)
+ rescue Hbc::CaskUnavailableError
+ nil
+ end
+ end
+
+ formula_downloaders =
+ cache_entries.call(HOMEBREW_CACHE)
+ .map(&load_formula)
+ .compact
+ .flat_map { |formula| formula_resources(formula) }
+ .map { |resource| [resource.downloader, resource.download_name, resource.version] }
+
+ cask_downloaders =
+ cache_entries.call(HOMEBREW_CACHE/"Cask")
+ .map(&load_cask)
+ .compact
+ .map { |cask| [Hbc::Download.new(cask).downloader, cask.token, cask.version] }
+
+ downloaders = formula_downloaders + cask_downloaders
+
+ downloaders.each do |downloader, name, version|
+ next unless downloader.respond_to?(:symlink_location)
+
+ url = downloader.url
+ extname = parse_extname(url)
+ old_location = downloader.cache/"#{name}--#{version}#{extname}"
+ next unless old_location.file?
+
+ new_symlink_location = downloader.symlink_location
+ new_location = downloader.cached_location
+
+ if new_location.exist? && new_symlink_location.symlink?
+ begin
+ FileUtils.rm_rf old_location unless old_location == new_symlink_location
+ rescue Errno::EACCES
+ opoo "Could not remove #{old_location}, please do so manually."
+ end
+ else
+ begin
+ new_location.dirname.mkpath
+ if new_location.exist?
+ FileUtils.rm_rf old_location
+ else
+ FileUtils.mv old_location, new_location
+ end
+ symlink_target = new_location.relative_path_from(new_symlink_location.dirname)
+ new_symlink_location.dirname.mkpath
+ FileUtils.ln_s symlink_target, new_symlink_location, force: true
+ rescue Errno::EACCES
+ opoo "Could not move #{old_location} to #{new_location}, please do so manually."
+ end
+ end
+ end
end
- nil
+ def migrate_legacy_cache_if_necessary
+ legacy_cache = Pathname.new "/Library/Caches/Homebrew"
+ return if HOMEBREW_CACHE.to_s == legacy_cache.to_s
+ return unless legacy_cache.directory?
+ return unless legacy_cache.readable_real?
+
+ migration_attempted_file = legacy_cache/".migration_attempted"
+ return if migration_attempted_file.exist?
+
+ return unless legacy_cache.writable_real?
+ FileUtils.touch migration_attempted_file
+
+ # This directory could have been compromised if it's world-writable/
+ # a symlink/owned by another user so don't copy files in those cases.
+ world_writable = legacy_cache.stat.mode & 0777 == 0777
+ return if world_writable
+ return if legacy_cache.symlink?
+ return if !legacy_cache.owned? && legacy_cache.lstat.uid.nonzero?
+
+ ohai "Migrating #{legacy_cache} to #{HOMEBREW_CACHE}..."
+ HOMEBREW_CACHE.mkpath
+ legacy_cache.cd do
+ legacy_cache.entries.each do |f|
+ next if [".", "..", ".migration_attempted"].include? f.to_s
+ begin
+ FileUtils.cp_r f, HOMEBREW_CACHE
+ rescue
+ @migration_failed ||= true
+ end
+ end
+ end
+
+ if @migration_failed
+ opoo <<~EOS
+ Failed to migrate #{legacy_cache} to
+ #{HOMEBREW_CACHE}. Please do so manually.
+ EOS
+ else
+ ohai "Deleting #{legacy_cache}..."
+ FileUtils.rm_rf legacy_cache
+ if legacy_cache.exist?
+ FileUtils.touch migration_attempted_file
+ opoo <<~EOS
+ Failed to delete #{legacy_cache}.
+ Please do so manually.
+ EOS
+ end
+ end
+ end
+
+ def migrate_legacy_keg_symlinks_if_necessary
+ legacy_linked_kegs = HOMEBREW_LIBRARY/"LinkedKegs"
+ return unless legacy_linked_kegs.directory?
+
+ HOMEBREW_LINKED_KEGS.mkpath unless legacy_linked_kegs.children.empty?
+ legacy_linked_kegs.children.each do |link|
+ name = link.basename.to_s
+ src = begin
+ link.realpath
+ rescue Errno::ENOENT
+ begin
+ (HOMEBREW_PREFIX/"opt/#{name}").realpath
+ rescue Errno::ENOENT
+ begin
+ Formulary.factory(name).installed_prefix
+ rescue
+ next
+ end
+ end
+ end
+ dst = HOMEBREW_LINKED_KEGS/name
+ dst.unlink if dst.exist?
+ FileUtils.ln_sf(src.relative_path_from(dst.parent), dst)
+ end
+ FileUtils.rm_rf legacy_linked_kegs
+
+ legacy_pinned_kegs = HOMEBREW_LIBRARY/"PinnedKegs"
+ return unless legacy_pinned_kegs.directory?
+
+ HOMEBREW_PINNED_KEGS.mkpath unless legacy_pinned_kegs.children.empty?
+ legacy_pinned_kegs.children.each do |link|
+ name = link.basename.to_s
+ src = link.realpath
+ dst = HOMEBREW_PINNED_KEGS/name
+ FileUtils.ln_sf(src.relative_path_from(dst.parent), dst)
+ end
+ FileUtils.rm_rf legacy_pinned_kegs
+ end
+
+ def migrate_legacy_repository_if_necessary
+ return unless HOMEBREW_PREFIX.to_s == "/usr/local"
+ return unless HOMEBREW_REPOSITORY.to_s == "/usr/local"
+
+ ohai "Migrating HOMEBREW_REPOSITORY (please wait)..."
+
+ unless HOMEBREW_PREFIX.writable_real?
+ ofail <<~EOS
+ #{HOMEBREW_PREFIX} is not writable.
+
+ You should change the ownership and permissions of #{HOMEBREW_PREFIX}
+ temporarily back to your user account so we can complete the Homebrew
+ repository migration:
+ sudo chown -R $(whoami) #{HOMEBREW_PREFIX}
+ EOS
+ return
+ end
+
+ new_homebrew_repository = Pathname.new "/usr/local/Homebrew"
+ new_homebrew_repository.rmdir_if_possible
+ if new_homebrew_repository.exist?
+ ofail <<~EOS
+ #{new_homebrew_repository} already exists.
+ Please remove it manually or uninstall and reinstall Homebrew into a new
+ location as the migration cannot be done automatically.
+ EOS
+ return
+ end
+ new_homebrew_repository.mkpath
+
+ repo_files = HOMEBREW_REPOSITORY.cd do
+ Utils.popen_read("git ls-files").lines.map(&:chomp)
+ end
+
+ unless Utils.popen_read("git status --untracked-files=all --porcelain").empty?
+ HOMEBREW_REPOSITORY.cd do
+ quiet_system "git", "merge", "--abort"
+ quiet_system "git", "rebase", "--abort"
+ quiet_system "git", "reset", "--mixed"
+ safe_system "git", "-c", "user.email=brew-update@localhost",
+ "-c", "user.name=brew update",
+ "stash", "save", "--include-untracked"
+ end
+ stashed = true
+ end
+
+ FileUtils.cp_r "#{HOMEBREW_REPOSITORY}/.git", "#{new_homebrew_repository}/.git"
+ new_homebrew_repository.cd do
+ safe_system "git", "checkout", "--force", "."
+ safe_system "git", "stash", "pop" if stashed
+ end
+
+ if (HOMEBREW_REPOSITORY/"Library/Locks").exist?
+ FileUtils.cp_r "#{HOMEBREW_REPOSITORY}/Library/Locks", "#{new_homebrew_repository}/Library/Locks"
+ end
+
+ if (HOMEBREW_REPOSITORY/"Library/Taps").exist?
+ FileUtils.cp_r "#{HOMEBREW_REPOSITORY}/Library/Taps", "#{new_homebrew_repository}/Library/Taps"
+ end
+
+ unremovable_paths = []
+ extra_remove_paths = [
+ ".git",
+ "Library/Locks",
+ "Library/Taps",
+ "Library/Homebrew/cask",
+ "Library/Homebrew/test",
+ ]
+ (repo_files + extra_remove_paths).each do |file|
+ path = Pathname.new "#{HOMEBREW_REPOSITORY}/#{file}"
+ begin
+ FileUtils.rm_rf path
+ rescue Errno::EACCES
+ unremovable_paths << path
+ end
+ quiet_system "rmdir", "-p", path.parent if path.parent.exist?
+ end
+
+ unless unremovable_paths.empty?
+ ofail <<~EOS
+ Could not remove old HOMEBREW_REPOSITORY paths!
+ Please do this manually with:
+ sudo rm -rf #{unremovable_paths.join " "}
+ EOS
+ end
+
+ (Keg::ALL_TOP_LEVEL_DIRECTORIES + ["Cellar"]).each do |dir|
+ FileUtils.mkdir_p "#{HOMEBREW_PREFIX}/#{dir}"
+ end
+
+ src = Pathname.new("#{new_homebrew_repository}/bin/brew")
+ dst = Pathname.new("#{HOMEBREW_PREFIX}/bin/brew")
+ begin
+ FileUtils.ln_s(src.relative_path_from(dst.parent), dst)
+ rescue Errno::EACCES, Errno::ENOENT
+ ofail <<~EOS
+ Could not create symlink at #{dst}!
+ Please do this manually with:
+ sudo ln -sf #{src} #{dst}
+ sudo chown $(whoami) #{dst}
+ EOS
+ end
+
+ link_completions_manpages_and_docs(new_homebrew_repository)
+
+ ohai "Migrated HOMEBREW_REPOSITORY to #{new_homebrew_repository}!"
+ puts <<~EOS
+ Homebrew no longer needs to have ownership of /usr/local. If you wish you can
+ return /usr/local to its default ownership with:
+ sudo chown root:wheel #{HOMEBREW_PREFIX}
+ EOS
+ rescue => e
+ ofail <<~EOS
+ #{Tty.bold}Failed to migrate HOMEBREW_REPOSITORY to #{new_homebrew_repository}!#{Tty.reset}
+ The error was:
+ #{e}
+ Please try to resolve this error yourself and then run `brew update` again to
+ complete the migration. If you need help please +1 an existing error or comment
+ with your new error in issue:
+ #{Formatter.url("https://github.com/Homebrew/brew/issues/987")}
+ EOS
+ $stderr.puts e.backtrace
+ end
end
end | true |
Other | Homebrew | brew | 9b50fd81d729080b746b9637ad3a0c59049b96a3.json | Move everything into one file. | Library/Homebrew/update_migrator/cache_entries_to_double_dashes.rb | @@ -1,41 +0,0 @@
-module UpdateMigrator
- module_function
-
- def migrate_cache_entries_to_double_dashes(initial_version)
- return if initial_version && initial_version > "1.7.1"
-
- return if ENV.key?("HOMEBREW_DISABLE_LOAD_FORMULA")
-
- ohai "Migrating cache entries..."
-
- Formula.each do |formula|
- formula_resources(formula).each do |resource|
- downloader = resource.downloader
-
- url = downloader.url
- name = resource.download_name
- version = resource.version
-
- extname = parse_extname(url)
- old_location = downloader.cache/"#{name}-#{version}#{extname}"
- new_location = downloader.cache/"#{name}--#{version}#{extname}"
-
- next unless old_location.file?
-
- if new_location.exist?
- begin
- FileUtils.rm_rf old_location
- rescue Errno::EACCES
- opoo "Could not remove #{old_location}, please do so manually."
- end
- else
- begin
- FileUtils.mv old_location, new_location
- rescue Errno::EACCES
- opoo "Could not move #{old_location} to #{new_location}, please do so manually."
- end
- end
- end
- end
- end
-end | true |
Other | Homebrew | brew | 9b50fd81d729080b746b9637ad3a0c59049b96a3.json | Move everything into one file. | Library/Homebrew/update_migrator/cache_entries_to_symlinks.rb | @@ -1,91 +0,0 @@
-require "hbc/cask_loader"
-require "hbc/download"
-
-module UpdateMigrator
- module_function
-
- def migrate_cache_entries_to_symlinks(initial_version)
- return if initial_version && initial_version > "1.7.2"
-
- return if ENV.key?("HOMEBREW_DISABLE_LOAD_FORMULA")
-
- ohai "Migrating cache entries..."
-
- cache_entries = lambda do |path|
- if path.directory?
- path.children
- .reject(&:symlink?)
- .select(&:file?)
- .map { |child| child.basename.to_s.sub(/\-\-.*/, "") }
- .uniq
- else
- []
- end
- end
-
- load_formula = lambda do |formula|
- begin
- Formula[formula]
- rescue FormulaUnavailableError
- nil
- end
- end
-
- load_cask = lambda do |cask|
- begin
- Hbc::CaskLoader.load(cask)
- rescue Hbc::CaskUnavailableError
- nil
- end
- end
-
- formula_downloaders =
- cache_entries.call(HOMEBREW_CACHE)
- .map(&load_formula)
- .compact
- .flat_map { |formula| formula_resources(formula) }
- .map { |resource| [resource.downloader, resource.download_name, resource.version] }
-
- cask_downloaders =
- cache_entries.call(HOMEBREW_CACHE/"Cask")
- .map(&load_cask)
- .compact
- .map { |cask| [Hbc::Download.new(cask).downloader, cask.token, cask.version] }
-
- downloaders = formula_downloaders + cask_downloaders
-
- downloaders.each do |downloader, name, version|
- next unless downloader.respond_to?(:symlink_location)
-
- url = downloader.url
- extname = parse_extname(url)
- old_location = downloader.cache/"#{name}--#{version}#{extname}"
- next unless old_location.file?
-
- new_symlink_location = downloader.symlink_location
- new_location = downloader.cached_location
-
- if new_location.exist? && new_symlink_location.symlink?
- begin
- FileUtils.rm_rf old_location unless old_location == new_symlink_location
- rescue Errno::EACCES
- opoo "Could not remove #{old_location}, please do so manually."
- end
- else
- begin
- new_location.dirname.mkpath
- if new_location.exist?
- FileUtils.rm_rf old_location
- else
- FileUtils.mv old_location, new_location
- end
- symlink_target = new_location.relative_path_from(new_symlink_location.dirname)
- new_symlink_location.dirname.mkpath
- FileUtils.ln_s symlink_target, new_symlink_location, force: true
- rescue Errno::EACCES
- opoo "Could not move #{old_location} to #{new_location}, please do so manually."
- end
- end
- end
- end
-end | true |
Other | Homebrew | brew | 9b50fd81d729080b746b9637ad3a0c59049b96a3.json | Move everything into one file. | Library/Homebrew/update_migrator/legacy_cache.rb | @@ -1,53 +0,0 @@
-module UpdateMigrator
- module_function
-
- def migrate_legacy_cache_if_necessary
- legacy_cache = Pathname.new "/Library/Caches/Homebrew"
- return if HOMEBREW_CACHE.to_s == legacy_cache.to_s
- return unless legacy_cache.directory?
- return unless legacy_cache.readable_real?
-
- migration_attempted_file = legacy_cache/".migration_attempted"
- return if migration_attempted_file.exist?
-
- return unless legacy_cache.writable_real?
- FileUtils.touch migration_attempted_file
-
- # This directory could have been compromised if it's world-writable/
- # a symlink/owned by another user so don't copy files in those cases.
- world_writable = legacy_cache.stat.mode & 0777 == 0777
- return if world_writable
- return if legacy_cache.symlink?
- return if !legacy_cache.owned? && legacy_cache.lstat.uid.nonzero?
-
- ohai "Migrating #{legacy_cache} to #{HOMEBREW_CACHE}..."
- HOMEBREW_CACHE.mkpath
- legacy_cache.cd do
- legacy_cache.entries.each do |f|
- next if [".", "..", ".migration_attempted"].include? f.to_s
- begin
- FileUtils.cp_r f, HOMEBREW_CACHE
- rescue
- @migration_failed ||= true
- end
- end
- end
-
- if @migration_failed
- opoo <<~EOS
- Failed to migrate #{legacy_cache} to
- #{HOMEBREW_CACHE}. Please do so manually.
- EOS
- else
- ohai "Deleting #{legacy_cache}..."
- FileUtils.rm_rf legacy_cache
- if legacy_cache.exist?
- FileUtils.touch migration_attempted_file
- opoo <<~EOS
- Failed to delete #{legacy_cache}.
- Please do so manually.
- EOS
- end
- end
- end
-end | true |
Other | Homebrew | brew | 9b50fd81d729080b746b9637ad3a0c59049b96a3.json | Move everything into one file. | Library/Homebrew/update_migrator/legacy_keg_symlinks.rb | @@ -1,42 +0,0 @@
-module UpdateMigrator
- module_function
-
- def migrate_legacy_keg_symlinks_if_necessary
- legacy_linked_kegs = HOMEBREW_LIBRARY/"LinkedKegs"
- return unless legacy_linked_kegs.directory?
-
- HOMEBREW_LINKED_KEGS.mkpath unless legacy_linked_kegs.children.empty?
- legacy_linked_kegs.children.each do |link|
- name = link.basename.to_s
- src = begin
- link.realpath
- rescue Errno::ENOENT
- begin
- (HOMEBREW_PREFIX/"opt/#{name}").realpath
- rescue Errno::ENOENT
- begin
- Formulary.factory(name).installed_prefix
- rescue
- next
- end
- end
- end
- dst = HOMEBREW_LINKED_KEGS/name
- dst.unlink if dst.exist?
- FileUtils.ln_sf(src.relative_path_from(dst.parent), dst)
- end
- FileUtils.rm_rf legacy_linked_kegs
-
- legacy_pinned_kegs = HOMEBREW_LIBRARY/"PinnedKegs"
- return unless legacy_pinned_kegs.directory?
-
- HOMEBREW_PINNED_KEGS.mkpath unless legacy_pinned_kegs.children.empty?
- legacy_pinned_kegs.children.each do |link|
- name = link.basename.to_s
- src = link.realpath
- dst = HOMEBREW_PINNED_KEGS/name
- FileUtils.ln_sf(src.relative_path_from(dst.parent), dst)
- end
- FileUtils.rm_rf legacy_pinned_kegs
- end
-end | true |
Other | Homebrew | brew | 9b50fd81d729080b746b9637ad3a0c59049b96a3.json | Move everything into one file. | Library/Homebrew/update_migrator/legacy_repository.rb | @@ -1,122 +0,0 @@
-module UpdateMigrator
- module_function
-
- def migrate_legacy_repository_if_necessary
- return unless HOMEBREW_PREFIX.to_s == "/usr/local"
- return unless HOMEBREW_REPOSITORY.to_s == "/usr/local"
-
- ohai "Migrating HOMEBREW_REPOSITORY (please wait)..."
-
- unless HOMEBREW_PREFIX.writable_real?
- ofail <<~EOS
- #{HOMEBREW_PREFIX} is not writable.
-
- You should change the ownership and permissions of #{HOMEBREW_PREFIX}
- temporarily back to your user account so we can complete the Homebrew
- repository migration:
- sudo chown -R $(whoami) #{HOMEBREW_PREFIX}
- EOS
- return
- end
-
- new_homebrew_repository = Pathname.new "/usr/local/Homebrew"
- new_homebrew_repository.rmdir_if_possible
- if new_homebrew_repository.exist?
- ofail <<~EOS
- #{new_homebrew_repository} already exists.
- Please remove it manually or uninstall and reinstall Homebrew into a new
- location as the migration cannot be done automatically.
- EOS
- return
- end
- new_homebrew_repository.mkpath
-
- repo_files = HOMEBREW_REPOSITORY.cd do
- Utils.popen_read("git ls-files").lines.map(&:chomp)
- end
-
- unless Utils.popen_read("git status --untracked-files=all --porcelain").empty?
- HOMEBREW_REPOSITORY.cd do
- quiet_system "git", "merge", "--abort"
- quiet_system "git", "rebase", "--abort"
- quiet_system "git", "reset", "--mixed"
- safe_system "git", "-c", "user.email=brew-update@localhost",
- "-c", "user.name=brew update",
- "stash", "save", "--include-untracked"
- end
- stashed = true
- end
-
- FileUtils.cp_r "#{HOMEBREW_REPOSITORY}/.git", "#{new_homebrew_repository}/.git"
- new_homebrew_repository.cd do
- safe_system "git", "checkout", "--force", "."
- safe_system "git", "stash", "pop" if stashed
- end
-
- if (HOMEBREW_REPOSITORY/"Library/Locks").exist?
- FileUtils.cp_r "#{HOMEBREW_REPOSITORY}/Library/Locks", "#{new_homebrew_repository}/Library/Locks"
- end
-
- if (HOMEBREW_REPOSITORY/"Library/Taps").exist?
- FileUtils.cp_r "#{HOMEBREW_REPOSITORY}/Library/Taps", "#{new_homebrew_repository}/Library/Taps"
- end
-
- unremovable_paths = []
- extra_remove_paths = [".git", "Library/Locks", "Library/Taps",
- "Library/Homebrew/cask", "Library/Homebrew/test"]
- (repo_files + extra_remove_paths).each do |file|
- path = Pathname.new "#{HOMEBREW_REPOSITORY}/#{file}"
- begin
- FileUtils.rm_rf path
- rescue Errno::EACCES
- unremovable_paths << path
- end
- quiet_system "rmdir", "-p", path.parent if path.parent.exist?
- end
-
- unless unremovable_paths.empty?
- ofail <<~EOS
- Could not remove old HOMEBREW_REPOSITORY paths!
- Please do this manually with:
- sudo rm -rf #{unremovable_paths.join " "}
- EOS
- end
-
- (Keg::ALL_TOP_LEVEL_DIRECTORIES + ["Cellar"]).each do |dir|
- FileUtils.mkdir_p "#{HOMEBREW_PREFIX}/#{dir}"
- end
-
- src = Pathname.new("#{new_homebrew_repository}/bin/brew")
- dst = Pathname.new("#{HOMEBREW_PREFIX}/bin/brew")
- begin
- FileUtils.ln_s(src.relative_path_from(dst.parent), dst)
- rescue Errno::EACCES, Errno::ENOENT
- ofail <<~EOS
- Could not create symlink at #{dst}!
- Please do this manually with:
- sudo ln -sf #{src} #{dst}
- sudo chown $(whoami) #{dst}
- EOS
- end
-
- link_completions_manpages_and_docs(new_homebrew_repository)
-
- ohai "Migrated HOMEBREW_REPOSITORY to #{new_homebrew_repository}!"
- puts <<~EOS
- Homebrew no longer needs to have ownership of /usr/local. If you wish you can
- return /usr/local to its default ownership with:
- sudo chown root:wheel #{HOMEBREW_PREFIX}
- EOS
- rescue => e
- ofail <<~EOS
- #{Tty.bold}Failed to migrate HOMEBREW_REPOSITORY to #{new_homebrew_repository}!#{Tty.reset}
- The error was:
- #{e}
- Please try to resolve this error yourself and then run `brew update` again to
- complete the migration. If you need help please +1 an existing error or comment
- with your new error in issue:
- #{Formatter.url("https://github.com/Homebrew/brew/issues/987")}
- EOS
- $stderr.puts e.backtrace
- end
-end | true |
Other | Homebrew | brew | 443111896e71f394a19047caf6ac9e0e8e2e9b4d.json | Share common logic. | Library/Homebrew/update_migrator/cache_entries_to_symlinks.rb | @@ -11,6 +11,18 @@ def migrate_cache_entries_to_symlinks(initial_version)
ohai "Migrating cache entries..."
+ cache_entries = lambda do |path|
+ if path.directory?
+ path.children
+ .reject(&:symlink?)
+ .select(&:file?)
+ .map { |child| child.basename.to_s.sub(/\-\-.*/, "") }
+ .uniq
+ else
+ []
+ end
+ end
+
load_formula = lambda do |formula|
begin
Formula[formula]
@@ -27,32 +39,18 @@ def migrate_cache_entries_to_symlinks(initial_version)
end
end
- formula_downloaders = if HOMEBREW_CACHE.directory?
- HOMEBREW_CACHE.children
- .reject(&:symlink?)
- .select(&:file?)
- .map { |child| child.basename.to_s.sub(/\-\-.*/, "") }
- .uniq
- .map(&load_formula)
- .compact
- .flat_map { |formula| formula_resources(formula) }
- .map { |resource| [resource.downloader, resource.download_name, resource.version] }
- else
- []
- end
+ formula_downloaders =
+ cache_entries.call(HOMEBREW_CACHE)
+ .map(&load_formula)
+ .compact
+ .flat_map { |formula| formula_resources(formula) }
+ .map { |resource| [resource.downloader, resource.download_name, resource.version] }
- cask_downloaders = if (HOMEBREW_CACHE/"Cask").directory?
- (HOMEBREW_CACHE/"Cask").children
- .reject(&:symlink?)
- .select(&:file?)
- .map { |child| child.basename.to_s.sub(/\-\-.*/, "") }
- .uniq
- .map(&load_cask)
- .compact
- .map { |cask| [Hbc::Download.new(cask).downloader, cask.token, cask.version] }
- else
- []
- end
+ cask_downloaders =
+ cache_entries.call(HOMEBREW_CACHE/"Cask")
+ .map(&load_cask)
+ .compact
+ .map { |cask| [Hbc::Download.new(cask).downloader, cask.token, cask.version] }
downloaders = formula_downloaders + cask_downloaders
| false |
Other | Homebrew | brew | ccf396887a283595affef49d8a1e445f45fecf06.json | Add comment about refinement scope. | Library/Homebrew/cleanup.rb | @@ -213,6 +213,7 @@ def cleanup_unreferenced_downloads
return if dry_run?
return unless (cache/"downloads").directory?
+ # We can't use `.reject(&:incomplete?) here due to the refinement scope.
downloads = (cache/"downloads").children.reject { |path| path.incomplete? } # rubocop:disable Style/SymbolProc
referenced_downloads = [cache, cache/"Cask"].select(&:directory?)
.flat_map(&:children) | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.