Migrate legacy Caskroom.
This commit is contained in:
parent
7a8d782365
commit
3bd4349e8e
@ -1,6 +1,6 @@
|
|||||||
module Hbc; end
|
|
||||||
|
|
||||||
require "hardware"
|
require "hardware"
|
||||||
|
require "utils"
|
||||||
|
|
||||||
require "hbc/artifact"
|
require "hbc/artifact"
|
||||||
require "hbc/audit"
|
require "hbc/audit"
|
||||||
require "hbc/auditor"
|
require "hbc/auditor"
|
||||||
@ -34,7 +34,6 @@ require "hbc/url_checker"
|
|||||||
require "hbc/utils"
|
require "hbc/utils"
|
||||||
require "hbc/verify"
|
require "hbc/verify"
|
||||||
require "hbc/version"
|
require "hbc/version"
|
||||||
require "utils"
|
|
||||||
|
|
||||||
module Hbc
|
module Hbc
|
||||||
include Locations
|
include Locations
|
||||||
|
@ -83,7 +83,7 @@ module Hbc
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.needs_init?
|
def self.needs_init?
|
||||||
false
|
true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -7,35 +7,10 @@ module Hbc
|
|||||||
end
|
end
|
||||||
|
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
def legacy_caskroom
|
|
||||||
@legacy_caskroom ||= Pathname.new("/opt/homebrew-cask/Caskroom")
|
|
||||||
end
|
|
||||||
|
|
||||||
def default_caskroom
|
|
||||||
@default_caskroom ||= HOMEBREW_PREFIX.join("Caskroom")
|
|
||||||
end
|
|
||||||
|
|
||||||
attr_writer :caskroom
|
attr_writer :caskroom
|
||||||
|
|
||||||
def caskroom
|
def caskroom
|
||||||
@caskroom ||= begin
|
@caskroom ||= HOMEBREW_PREFIX.join("Caskroom")
|
||||||
if Utils.path_occupied?(legacy_caskroom)
|
|
||||||
opoo <<-EOS.undent
|
|
||||||
The default Caskroom location has moved to #{default_caskroom}.
|
|
||||||
|
|
||||||
Please migrate your Casks to the new location and delete #{legacy_caskroom},
|
|
||||||
or if you would like to keep your Caskroom at #{legacy_caskroom}, add the
|
|
||||||
following to your HOMEBREW_CASK_OPTS:
|
|
||||||
|
|
||||||
--caskroom=#{legacy_caskroom}
|
|
||||||
|
|
||||||
For more details on each of those options, see https://github.com/caskroom/homebrew-cask/issues/21913.
|
|
||||||
EOS
|
|
||||||
legacy_caskroom
|
|
||||||
else
|
|
||||||
default_caskroom
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_writer :cache
|
attr_writer :cache
|
||||||
|
@ -29,11 +29,8 @@ module Hbc
|
|||||||
end
|
end
|
||||||
|
|
||||||
def user_agent
|
def user_agent
|
||||||
if @user_agent == :fake
|
return FAKE_USER_AGENT if @user_agent == :fake
|
||||||
FAKE_USER_AGENT
|
@user_agent
|
||||||
else
|
|
||||||
@user_agent
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -9,7 +9,9 @@ module Hbc
|
|||||||
Module.new do
|
Module.new do
|
||||||
def init
|
def init
|
||||||
Cache.delete_legacy_cache
|
Cache.delete_legacy_cache
|
||||||
|
|
||||||
Caskroom.migrate_caskroom_from_repo_to_prefix
|
Caskroom.migrate_caskroom_from_repo_to_prefix
|
||||||
|
Caskroom.migrate_legacy_caskroom
|
||||||
|
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
@ -2,6 +2,31 @@ module Hbc
|
|||||||
module Caskroom
|
module Caskroom
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
|
def migrate_legacy_caskroom
|
||||||
|
return if Hbc.caskroom.exist?
|
||||||
|
|
||||||
|
legacy_caskroom = Pathname.new("/opt/homebrew-cask/Caskroom")
|
||||||
|
return if Hbc.caskroom == legacy_caskroom
|
||||||
|
return unless legacy_caskroom.exist?
|
||||||
|
return if legacy_caskroom.symlink?
|
||||||
|
|
||||||
|
ohai "Migrating Caskroom from #{legacy_caskroom} to #{Hbc.caskroom}."
|
||||||
|
if Hbc.caskroom.parent.writable?
|
||||||
|
FileUtils.mv legacy_caskroom, Hbc.caskroom
|
||||||
|
else
|
||||||
|
opoo "#{Hbc.caskroom.parent} is not writable, sudo is needed to move the Caskroom."
|
||||||
|
SystemCommand.run("/bin/mv", args: [legacy_caskroom, Hbc.caskroom.parent], sudo: true)
|
||||||
|
end
|
||||||
|
|
||||||
|
ohai "Creating symlink from #{Hbc.caskroom} to #{legacy_caskroom}."
|
||||||
|
if legacy_caskroom.parent.writable?
|
||||||
|
FileUtils.ln_s Hbc.caskroom, legacy_caskroom
|
||||||
|
else
|
||||||
|
opoo "#{legacy_caskroom.parent} is not writable, sudo is needed to link the Caskroom."
|
||||||
|
SystemCommand.run("/bin/ln", args: ["-s", Hbc.caskroom, legacy_caskroom], sudo: true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def migrate_caskroom_from_repo_to_prefix
|
def migrate_caskroom_from_repo_to_prefix
|
||||||
repo_caskroom = HOMEBREW_REPOSITORY.join("Caskroom")
|
repo_caskroom = HOMEBREW_REPOSITORY.join("Caskroom")
|
||||||
return if Hbc.caskroom.exist?
|
return if Hbc.caskroom.exist?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user