aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Library/Homebrew/cask/lib/hbc.rb5
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/list.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/locations.rb27
-rw-r--r--Library/Homebrew/cask/lib/hbc/url.rb7
-rw-r--r--Library/Homebrew/compat/hbc.rb2
-rw-r--r--Library/Homebrew/compat/hbc/caskroom.rb25
6 files changed, 33 insertions, 35 deletions
diff --git a/Library/Homebrew/cask/lib/hbc.rb b/Library/Homebrew/cask/lib/hbc.rb
index 3cdec07d2..363879574 100644
--- a/Library/Homebrew/cask/lib/hbc.rb
+++ b/Library/Homebrew/cask/lib/hbc.rb
@@ -1,6 +1,6 @@
-module Hbc; end
-
require "hardware"
+require "utils"
+
require "hbc/artifact"
require "hbc/audit"
require "hbc/auditor"
@@ -34,7 +34,6 @@ require "hbc/url_checker"
require "hbc/utils"
require "hbc/verify"
require "hbc/version"
-require "utils"
module Hbc
include Locations
diff --git a/Library/Homebrew/cask/lib/hbc/cli/list.rb b/Library/Homebrew/cask/lib/hbc/cli/list.rb
index e100fbd83..5d7a58b93 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/list.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/list.rb
@@ -83,7 +83,7 @@ module Hbc
end
def self.needs_init?
- false
+ true
end
end
end
diff --git a/Library/Homebrew/cask/lib/hbc/locations.rb b/Library/Homebrew/cask/lib/hbc/locations.rb
index 7a0f93851..80add91dd 100644
--- a/Library/Homebrew/cask/lib/hbc/locations.rb
+++ b/Library/Homebrew/cask/lib/hbc/locations.rb
@@ -7,35 +7,10 @@ module Hbc
end
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
def caskroom
- @caskroom ||= begin
- 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
+ @caskroom ||= HOMEBREW_PREFIX.join("Caskroom")
end
attr_writer :cache
diff --git a/Library/Homebrew/cask/lib/hbc/url.rb b/Library/Homebrew/cask/lib/hbc/url.rb
index c09aaa061..1a5101da1 100644
--- a/Library/Homebrew/cask/lib/hbc/url.rb
+++ b/Library/Homebrew/cask/lib/hbc/url.rb
@@ -29,11 +29,8 @@ module Hbc
end
def user_agent
- if @user_agent == :fake
- FAKE_USER_AGENT
- else
- @user_agent
- end
+ return FAKE_USER_AGENT if @user_agent == :fake
+ @user_agent
end
end
end
diff --git a/Library/Homebrew/compat/hbc.rb b/Library/Homebrew/compat/hbc.rb
index e60bdbc07..353a72488 100644
--- a/Library/Homebrew/compat/hbc.rb
+++ b/Library/Homebrew/compat/hbc.rb
@@ -9,7 +9,9 @@ module Hbc
Module.new do
def init
Cache.delete_legacy_cache
+
Caskroom.migrate_caskroom_from_repo_to_prefix
+ Caskroom.migrate_legacy_caskroom
super
end
diff --git a/Library/Homebrew/compat/hbc/caskroom.rb b/Library/Homebrew/compat/hbc/caskroom.rb
index 489c5b224..3621a35fb 100644
--- a/Library/Homebrew/compat/hbc/caskroom.rb
+++ b/Library/Homebrew/compat/hbc/caskroom.rb
@@ -2,6 +2,31 @@ module Hbc
module Caskroom
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
repo_caskroom = HOMEBREW_REPOSITORY.join("Caskroom")
return if Hbc.caskroom.exist?