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)
|
def migrate_cache_entries_to_double_dashes(initial_version)
|
||||||
return if initial_version > "1.7.1"
|
return if initial_version > "1.7.1"
|
||||||
|
|
||||||
HOMEBREW_CACHE.children.each do |child|
|
Formula.each do |formula|
|
||||||
next unless child.file?
|
specs = [*formula.stable, *formula.devel, *formula.head]
|
||||||
|
|
||||||
next unless /^(?<prefix>[^\.]+[^\-])\-(?<suffix>[^\-].*)/ =~ child.basename.to_s
|
resources = [*formula.bottle&.resource] + specs.flat_map do |spec|
|
||||||
target = HOMEBREW_CACHE/"#{prefix}--#{suffix}"
|
[
|
||||||
|
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
|
begin
|
||||||
FileUtils.rm_rf child
|
FileUtils.rm_rf old_location
|
||||||
rescue Errno::EACCES
|
rescue Errno::EACCES
|
||||||
opoo "Could not remove #{child}, please do so manually."
|
opoo "Could not remove #{old_location}, please do so manually."
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
FileUtils.mv child, target
|
FileUtils.mv old_location, new_location
|
||||||
rescue Errno::EACCES
|
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
|
end
|
||||||
end
|
end
|
||||||
|
@ -25,7 +25,7 @@ class SoftwareSpec
|
|||||||
attr_reader :compiler_failures
|
attr_reader :compiler_failures
|
||||||
|
|
||||||
def_delegators :@resource, :stage, :fetch, :verify_download_integrity, :source_modified_time
|
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, :checksum, :mirrors, :specs, :using
|
||||||
def_delegators :@resource, :version, :mirror, *Checksum::TYPES
|
def_delegators :@resource, :version, :mirror, *Checksum::TYPES
|
||||||
def_delegators :@resource, :downloader
|
def_delegators :@resource, :downloader
|
||||||
|
@ -2,51 +2,45 @@ require "cmd/update-report"
|
|||||||
|
|
||||||
describe "brew update-report" do
|
describe "brew update-report" do
|
||||||
describe "::migrate_cache_entries_to_double_dashes" do
|
describe "::migrate_cache_entries_to_double_dashes" do
|
||||||
let(:legacy_cache_file) { HOMEBREW_CACHE/"foo-1.2.3.tar.gz" }
|
let(:formula_name) { "foo" }
|
||||||
let(:renamed_cache_file) { HOMEBREW_CACHE/"foo--1.2.3.tar.gz" }
|
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
|
before(:each) do
|
||||||
FileUtils.touch legacy_cache_file
|
FileUtils.touch old_cache_file
|
||||||
|
allow(Formula).to receive(:each).and_yield(f)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "moves old files to use double dashes when upgrading from <= 1.7.1" do
|
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"))
|
Homebrew.migrate_cache_entries_to_double_dashes(Version.new("1.7.1"))
|
||||||
|
|
||||||
expect(legacy_cache_file).not_to exist
|
expect(old_cache_file).not_to exist
|
||||||
expect(renamed_cache_file).to exist
|
expect(new_cache_file).to exist
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when the formula name contains dashes" do
|
context "when the formula name contains dashes" do
|
||||||
let(:legacy_cache_file) { HOMEBREW_CACHE/"foo-bar-1.2.3.tar.gz" }
|
let(:formula_name) { "foo-bar" }
|
||||||
let(:renamed_cache_file) { HOMEBREW_CACHE/"foo-bar--1.2.3.tar.gz" }
|
|
||||||
|
|
||||||
it "does not introduce extra double dashes when called multiple times" do
|
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"))
|
||||||
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(old_cache_file).not_to exist
|
||||||
expect(renamed_cache_file).to exist
|
expect(new_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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not move files if upgrading from > 1.7.1" do
|
it "does not move files if upgrading from > 1.7.1" do
|
||||||
Homebrew.migrate_cache_entries_to_double_dashes(Version.new("1.7.2"))
|
Homebrew.migrate_cache_entries_to_double_dashes(Version.new("1.7.2"))
|
||||||
|
|
||||||
expect(legacy_cache_file).to exist
|
expect(old_cache_file).to exist
|
||||||
expect(renamed_cache_file).not_to exist
|
expect(new_cache_file).not_to exist
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user