Fix concurrent download error for duplicate URLs

Co-authored-by: MikeMcQuaid <125011+MikeMcQuaid@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-08-15 17:13:30 +01:00 committed by Mike McQuaid
parent 1cfd8589c5
commit c3934c8d8b
No known key found for this signature in database
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