diff --git a/Library/Homebrew/compat.rb b/Library/Homebrew/compat.rb index fbb74cb546..163a666aa6 100644 --- a/Library/Homebrew/compat.rb +++ b/Library/Homebrew/compat.rb @@ -1,6 +1,7 @@ require "compat/os/mac" require "compat/dependable" require "compat/dependency_collector" +require "compat/download_strategy" require "compat/fileutils" require "compat/formula_support" require "compat/hbc" diff --git a/Library/Homebrew/compat/download_strategy.rb b/Library/Homebrew/compat/download_strategy.rb new file mode 100644 index 0000000000..38d8464758 --- /dev/null +++ b/Library/Homebrew/compat/download_strategy.rb @@ -0,0 +1,16 @@ +class AbstractFileDownloadStrategy + # TODO: This can be removed after a month because downloads + # will be outdated anyways at that point. + module Compat + def initialize(url, name, version, **meta) + super + + old_cached_location = @cache/"#{name}-#{version}#{ext}" + + return unless old_cached_location.exist? + FileUtils.mv old_cached_location, cached_location, force: true + end + end + + prepend Compat +end diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index a9dacad7e9..cfccde511a 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -181,7 +181,7 @@ class AbstractFileDownloadStrategy < AbstractDownloadStrategy def initialize(url, name, version, **meta) super - @cached_location = @cache/"#{name}-#{version}#{ext}" + @cached_location = @cache/"#{name}--#{version}#{ext}" @temporary_path = Pathname.new("#{cached_location}.incomplete") end diff --git a/Library/Homebrew/test/cmd/fetch_spec.rb b/Library/Homebrew/test/cmd/fetch_spec.rb index 9e8d0bbf43..da5c5ce413 100644 --- a/Library/Homebrew/test/cmd/fetch_spec.rb +++ b/Library/Homebrew/test/cmd/fetch_spec.rb @@ -2,10 +2,10 @@ describe "brew fetch", :integration_test do it "downloads the Formula's URL" do setup_test_formula "testball" - expect(HOMEBREW_CACHE/"testball-0.1.tbz").not_to exist + expect(HOMEBREW_CACHE/"testball--0.1.tbz").not_to exist expect { brew "fetch", "testball" }.to be_a_success - expect(HOMEBREW_CACHE/"testball-0.1.tbz").to exist + expect(HOMEBREW_CACHE/"testball--0.1.tbz").to exist end end diff --git a/Library/Homebrew/test/download_strategies_spec.rb b/Library/Homebrew/test/download_strategies_spec.rb index 317eda99b7..8c1a887e1e 100644 --- a/Library/Homebrew/test/download_strategies_spec.rb +++ b/Library/Homebrew/test/download_strategies_spec.rb @@ -238,13 +238,13 @@ describe CurlDownloadStrategy do subject { described_class.new(url, name, version, **specs).cached_location } context "when URL ends with file" do - it { is_expected.to eq(HOMEBREW_CACHE/"foo-.tar.gz") } + it { is_expected.to eq(HOMEBREW_CACHE/"foo--.tar.gz") } end context "when URL file is in middle" do let(:url) { "http://example.com/foo.tar.gz/from/this/mirror" } - it { is_expected.to eq(HOMEBREW_CACHE/"foo-.tar.gz") } + it { is_expected.to eq(HOMEBREW_CACHE/"foo--.tar.gz") } end end end