bottle: don't read mtime from nonexistant files

If the source contains a broken symlink, `brew bottle` would fail for no
good reason when trying to determine the most recently modified
file. To avoid this, we ignore any files for which stat(2) fails.

Closes Homebrew/homebrew#47111.

Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
This commit is contained in:
Øyvind Ingebrigtsen Øvergaard 2015-12-20 23:13:58 +01:00 committed by Mike McQuaid
parent 28776ee1c3
commit cf2bf08ec9
3 changed files with 14 additions and 1 deletions

View File

@ -140,6 +140,10 @@ module Homebrew
erb.result(bottle.instance_eval { binding }).gsub(/^\s*$\n/, "") erb.result(bottle.instance_eval { binding }).gsub(/^\s*$\n/, "")
end end
def most_recent_mtime(pathname)
pathname.to_enum(:find).select(&:exist?).map(&:mtime).max
end
def bottle_formula(f) def bottle_formula(f)
unless f.installed? unless f.installed?
return ofail "Formula not installed or up-to-date: #{f.full_name}" return ofail "Formula not installed or up-to-date: #{f.full_name}"
@ -187,7 +191,7 @@ module Homebrew
skip_relocation = false skip_relocation = false
formula_source_time = f.stable.stage do formula_source_time = f.stable.stage do
Pathname.pwd.to_enum(:find).map(&:mtime).max most_recent_mtime(Pathname.pwd)
end end
keg.lock do keg.lock do

View File

@ -0,0 +1 @@
does-not-exist

View File

@ -0,0 +1,8 @@
require "testing_env"
require "cmd/bottle"
class BottleTests < Homebrew::TestCase
def test_most_recent_mtime_with_broken_symlink()
refute_nil Homebrew.most_recent_mtime(Pathname(File.join(TEST_DIRECTORY, 'resources/source-with-broken-symlink')))
end
end