Merge pull request #20471 from Homebrew/copilot/fix-20469

Fix concurrent download error when formula has same patch applied to multiple directories
This commit is contained in:
Mike McQuaid 2025-08-15 16:28:30 +00:00 committed by GitHub
commit c493fc6944
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 10 deletions

View File

@ -132,6 +132,26 @@ module Downloadable
EOS EOS
end end
sig { returns(Integer) }
def hash
[self.class, cached_download].hash
end
sig { params(other: Object).returns(T::Boolean) }
def eql?(other)
return false if self.class != other.class
other = T.cast(other, Downloadable)
cached_download == other.cached_download
end
sig { returns(String) }
def to_s
short_cached_download = cached_download.to_s
.delete_prefix("#{HOMEBREW_CACHE}/downloads/")
"#<#{self.class}: #{short_cached_download}>"
end
private private
sig { overridable.returns(String) } sig { overridable.returns(String) }

View File

@ -26,14 +26,4 @@ RSpec.describe Homebrew::Cmd::FetchCmd do
expect(HOMEBREW_CACHE/"testball2--0.1.tbz").to be_a_symlink expect(HOMEBREW_CACHE/"testball2--0.1.tbz").to be_a_symlink
expect(HOMEBREW_CACHE/"testball2--0.1.tbz").to exist expect(HOMEBREW_CACHE/"testball2--0.1.tbz").to exist
end end
it "errors when concurrently downloading to the same destination", :integration_test do
# This test will fail if the fetch is not performed concurrently.
# N.B. this test relies on how we set up test formulae, see the `integration_test` shared context.
setup_test_formula "testball1"
setup_test_formula "testball3"
expect { brew "fetch", "testball1", "testball3", "HOMEBREW_DOWNLOAD_CONCURRENCY" => "2" }.to be_a_failure
.and output(/Error:.*process has already locked/).to_stderr
end
end end