aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/compat
diff options
context:
space:
mode:
authorMarkus Reiter2017-03-07 15:54:36 +0100
committerGitHub2017-03-07 15:54:36 +0100
commitec7530bcda24ae3039a73285adbbccdf88b5d4e2 (patch)
treef25de9d0fb8df4d55926228cb4ee6cbf73336e67 /Library/Homebrew/compat
parent394f9fa0aaa5854aa52bc589708a079665dcf462 (diff)
parent76e65ca070c0142f05ba2fcaf05fb6931c929547 (diff)
downloadbrew-ec7530bcda24ae3039a73285adbbccdf88b5d4e2.tar.bz2
Merge pull request #2281 from reitermarkus/legacy-cache
Move legacy cache and caskroom code to `compat/*`.
Diffstat (limited to 'Library/Homebrew/compat')
-rw-r--r--Library/Homebrew/compat/hbc.rb17
-rw-r--r--Library/Homebrew/compat/hbc/cache.rb13
-rw-r--r--Library/Homebrew/compat/hbc/caskroom.rb20
3 files changed, 50 insertions, 0 deletions
diff --git a/Library/Homebrew/compat/hbc.rb b/Library/Homebrew/compat/hbc.rb
index 179639953..e60bdbc07 100644
--- a/Library/Homebrew/compat/hbc.rb
+++ b/Library/Homebrew/compat/hbc.rb
@@ -1,2 +1,19 @@
require "compat/hbc/cask_loader"
require "compat/hbc/cli/update"
+require "compat/hbc/cache"
+require "compat/hbc/caskroom"
+
+module Hbc
+ class << self
+ prepend(
+ Module.new do
+ def init
+ Cache.delete_legacy_cache
+ Caskroom.migrate_caskroom_from_repo_to_prefix
+
+ super
+ end
+ end,
+ )
+ end
+end
diff --git a/Library/Homebrew/compat/hbc/cache.rb b/Library/Homebrew/compat/hbc/cache.rb
new file mode 100644
index 000000000..34221fcf1
--- /dev/null
+++ b/Library/Homebrew/compat/hbc/cache.rb
@@ -0,0 +1,13 @@
+module Hbc
+ module Cache
+ module_function
+
+ def delete_legacy_cache
+ legacy_cache = HOMEBREW_CACHE.join("Casks")
+ return unless legacy_cache.exist?
+
+ ohai "Deleting legacy cache at #{legacy_cache}"
+ FileUtils.remove_entry_secure(legacy_cache)
+ end
+ end
+end
diff --git a/Library/Homebrew/compat/hbc/caskroom.rb b/Library/Homebrew/compat/hbc/caskroom.rb
new file mode 100644
index 000000000..489c5b224
--- /dev/null
+++ b/Library/Homebrew/compat/hbc/caskroom.rb
@@ -0,0 +1,20 @@
+module Hbc
+ module Caskroom
+ module_function
+
+ def migrate_caskroom_from_repo_to_prefix
+ repo_caskroom = HOMEBREW_REPOSITORY.join("Caskroom")
+ return if Hbc.caskroom.exist?
+ return unless repo_caskroom.directory?
+
+ ohai "Moving Caskroom from HOMEBREW_REPOSITORY to HOMEBREW_PREFIX"
+
+ if Hbc.caskroom.parent.writable?
+ FileUtils.mv repo_caskroom, Hbc.caskroom
+ else
+ opoo "#{Hbc.caskroom.parent} is not writable, sudo is needed to move the Caskroom."
+ SystemCommand.run("/bin/mv", args: [repo_caskroom, Hbc.caskroom.parent], sudo: true)
+ end
+ end
+ end
+end