Change migration to loop through formulae.
This commit is contained in:
parent
54a9f687df
commit
888a7073bc
@ -192,25 +192,41 @@ module Homebrew
|
||||
def migrate_cache_entries_to_double_dashes(initial_version)
|
||||
return if initial_version > "1.7.1"
|
||||
|
||||
HOMEBREW_CACHE.children.each do |child|
|
||||
next unless child.file?
|
||||
Formula.each do |formula|
|
||||
specs = [*formula.stable, *formula.devel, *formula.head]
|
||||
|
||||
next unless /^(?<prefix>[^\.]+[^\-])\-(?<suffix>[^\-].*)/ =~ child.basename.to_s
|
||||
target = HOMEBREW_CACHE/"#{prefix}--#{suffix}"
|
||||
resources = [*formula.bottle&.resource] + specs.flat_map do |spec|
|
||||
[
|
||||
spec,
|
||||
*spec.resources.values,
|
||||
*spec.patches.select(&:external?).map(&:resource),
|
||||
]
|
||||
end
|
||||
|
||||
next if suffix.include?("--") && !suffix.start_with?("patch")
|
||||
resources.each do |resource|
|
||||
downloader = resource.downloader
|
||||
|
||||
if target.exist?
|
||||
name = resource.download_name
|
||||
version = resource.version
|
||||
|
||||
new_location = downloader.cached_location
|
||||
extname = new_location.extname
|
||||
old_location = downloader.cached_location.dirname/"#{name}-#{version}#{extname}"
|
||||
|
||||
next unless old_location.file?
|
||||
|
||||
if new_location.exist?
|
||||
begin
|
||||
FileUtils.rm_rf child
|
||||
FileUtils.rm_rf old_location
|
||||
rescue Errno::EACCES
|
||||
opoo "Could not remove #{child}, please do so manually."
|
||||
opoo "Could not remove #{old_location}, please do so manually."
|
||||
end
|
||||
else
|
||||
begin
|
||||
FileUtils.mv child, target
|
||||
FileUtils.mv old_location, new_location
|
||||
rescue Errno::EACCES
|
||||
opoo "Could not move #{child} to #{target}, please do so manually."
|
||||
opoo "Could not move #{old_location} to #{new_location}, please do so manually."
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -25,7 +25,7 @@ class SoftwareSpec
|
||||
attr_reader :compiler_failures
|
||||
|
||||
def_delegators :@resource, :stage, :fetch, :verify_download_integrity, :source_modified_time
|
||||
def_delegators :@resource, :cached_download, :clear_cache
|
||||
def_delegators :@resource, :download_name, :cached_download, :clear_cache
|
||||
def_delegators :@resource, :checksum, :mirrors, :specs, :using
|
||||
def_delegators :@resource, :version, :mirror, *Checksum::TYPES
|
||||
def_delegators :@resource, :downloader
|
||||
|
@ -2,51 +2,45 @@ require "cmd/update-report"
|
||||
|
||||
describe "brew update-report" do
|
||||
describe "::migrate_cache_entries_to_double_dashes" do
|
||||
let(:legacy_cache_file) { HOMEBREW_CACHE/"foo-1.2.3.tar.gz" }
|
||||
let(:renamed_cache_file) { HOMEBREW_CACHE/"foo--1.2.3.tar.gz" }
|
||||
let(:formula_name) { "foo" }
|
||||
let(:f) {
|
||||
formula formula_name do
|
||||
url "https://example.com/foo-1.2.3.tar.gz"
|
||||
version "1.2.3"
|
||||
end
|
||||
}
|
||||
let(:old_cache_file) { HOMEBREW_CACHE/"#{formula_name}-1.2.3.tar.gz" }
|
||||
let(:new_cache_file) { HOMEBREW_CACHE/"#{formula_name}--1.2.3.tar.gz" }
|
||||
|
||||
before(:each) do
|
||||
FileUtils.touch legacy_cache_file
|
||||
FileUtils.touch old_cache_file
|
||||
allow(Formula).to receive(:each).and_yield(f)
|
||||
end
|
||||
|
||||
it "moves old files to use double dashes when upgrading from <= 1.7.1" do
|
||||
Homebrew.migrate_cache_entries_to_double_dashes(Version.new("1.7.1"))
|
||||
|
||||
expect(legacy_cache_file).not_to exist
|
||||
expect(renamed_cache_file).to exist
|
||||
expect(old_cache_file).not_to exist
|
||||
expect(new_cache_file).to exist
|
||||
end
|
||||
|
||||
context "when the formula name contains dashes" do
|
||||
let(:legacy_cache_file) { HOMEBREW_CACHE/"foo-bar-1.2.3.tar.gz" }
|
||||
let(:renamed_cache_file) { HOMEBREW_CACHE/"foo-bar--1.2.3.tar.gz" }
|
||||
let(:formula_name) { "foo-bar" }
|
||||
|
||||
it "does not introduce extra double dashes when called multiple times" do
|
||||
Homebrew.migrate_cache_entries_to_double_dashes(Version.new("1.7.1"))
|
||||
Homebrew.migrate_cache_entries_to_double_dashes(Version.new("1.7.1"))
|
||||
|
||||
expect(legacy_cache_file).not_to exist
|
||||
expect(renamed_cache_file).to exist
|
||||
end
|
||||
end
|
||||
|
||||
context "when the file is a patch and the formula name contains dashes" do
|
||||
let(:legacy_cache_file) { HOMEBREW_CACHE/"foo-bar-patch--1.2.3.tar.gz" }
|
||||
let(:renamed_cache_file) { HOMEBREW_CACHE/"foo-bar--patch--1.2.3.tar.gz" }
|
||||
|
||||
it "does not introduce extra double dashes when called multiple times" do
|
||||
Homebrew.migrate_cache_entries_to_double_dashes(Version.new("1.7.1"))
|
||||
Homebrew.migrate_cache_entries_to_double_dashes(Version.new("1.7.1"))
|
||||
|
||||
expect(legacy_cache_file).not_to exist
|
||||
expect(renamed_cache_file).to exist
|
||||
expect(old_cache_file).not_to exist
|
||||
expect(new_cache_file).to exist
|
||||
end
|
||||
end
|
||||
|
||||
it "does not move files if upgrading from > 1.7.1" do
|
||||
Homebrew.migrate_cache_entries_to_double_dashes(Version.new("1.7.2"))
|
||||
|
||||
expect(legacy_cache_file).to exist
|
||||
expect(renamed_cache_file).not_to exist
|
||||
expect(old_cache_file).to exist
|
||||
expect(new_cache_file).not_to exist
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user