From cf2bf08ec97847069ce22745476b4b2987b035e5 Mon Sep 17 00:00:00 2001 From: Øyvind Ingebrigtsen Øvergaard Date: Sun, 20 Dec 2015 23:13:58 +0100 Subject: 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 --- Library/Homebrew/cmd/bottle.rb | 6 +++++- .../test/resources/source-with-broken-symlink/broken-link | 1 + Library/Homebrew/test/test_bottle.rb | 8 ++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 120000 Library/Homebrew/test/resources/source-with-broken-symlink/broken-link create mode 100644 Library/Homebrew/test/test_bottle.rb (limited to 'Library') diff --git a/Library/Homebrew/cmd/bottle.rb b/Library/Homebrew/cmd/bottle.rb index fe2829c19..4c629cdbb 100644 --- a/Library/Homebrew/cmd/bottle.rb +++ b/Library/Homebrew/cmd/bottle.rb @@ -140,6 +140,10 @@ module Homebrew erb.result(bottle.instance_eval { binding }).gsub(/^\s*$\n/, "") end + def most_recent_mtime(pathname) + pathname.to_enum(:find).select(&:exist?).map(&:mtime).max + end + def bottle_formula(f) unless f.installed? return ofail "Formula not installed or up-to-date: #{f.full_name}" @@ -187,7 +191,7 @@ module Homebrew skip_relocation = false formula_source_time = f.stable.stage do - Pathname.pwd.to_enum(:find).map(&:mtime).max + most_recent_mtime(Pathname.pwd) end keg.lock do diff --git a/Library/Homebrew/test/resources/source-with-broken-symlink/broken-link b/Library/Homebrew/test/resources/source-with-broken-symlink/broken-link new file mode 120000 index 000000000..cfa0a4651 --- /dev/null +++ b/Library/Homebrew/test/resources/source-with-broken-symlink/broken-link @@ -0,0 +1 @@ +does-not-exist \ No newline at end of file diff --git a/Library/Homebrew/test/test_bottle.rb b/Library/Homebrew/test/test_bottle.rb new file mode 100644 index 000000000..f4398cc1d --- /dev/null +++ b/Library/Homebrew/test/test_bottle.rb @@ -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 -- cgit v1.2.3