From b2359873d032615ccfef0ef07b4cc01996dee0be Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Mon, 6 Mar 2017 21:28:17 +0100 Subject: [PATCH 1/2] Move `legacy_cache` outside of `Locations`. --- Library/Homebrew/cask/lib/hbc/cache.rb | 7 ++++--- Library/Homebrew/cask/lib/hbc/locations.rb | 4 ---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cache.rb b/Library/Homebrew/cask/lib/hbc/cache.rb index 7b586528ed..4e99fdd4f6 100644 --- a/Library/Homebrew/cask/lib/hbc/cache.rb +++ b/Library/Homebrew/cask/lib/hbc/cache.rb @@ -10,10 +10,11 @@ module Hbc end def delete_legacy_cache - return unless Hbc.legacy_cache.exist? + legacy_cache = HOMEBREW_CACHE.join("Casks") + return unless legacy_cache.exist? - ohai "Deleting legacy cache at #{Hbc.legacy_cache}..." - FileUtils.remove_entry_secure(Hbc.legacy_cache) + ohai "Deleting legacy cache at #{legacy_cache}..." + FileUtils.remove_entry_secure(legacy_cache) end end end diff --git a/Library/Homebrew/cask/lib/hbc/locations.rb b/Library/Homebrew/cask/lib/hbc/locations.rb index 4fb4a21914..7a0f938514 100644 --- a/Library/Homebrew/cask/lib/hbc/locations.rb +++ b/Library/Homebrew/cask/lib/hbc/locations.rb @@ -38,10 +38,6 @@ module Hbc end end - def legacy_cache - @legacy_cache ||= HOMEBREW_CACHE.join("Casks") - end - attr_writer :cache def cache From 76e65ca070c0142f05ba2fcaf05fb6931c929547 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Mon, 6 Mar 2017 21:49:35 +0100 Subject: [PATCH 2/2] Move legacy cache and caskroom code to `compat/*`. --- Library/Homebrew/cask/lib/hbc.rb | 3 --- Library/Homebrew/cask/lib/hbc/cache.rb | 8 -------- Library/Homebrew/cask/lib/hbc/caskroom.rb | 15 --------------- Library/Homebrew/compat/hbc.rb | 17 +++++++++++++++++ Library/Homebrew/compat/hbc/cache.rb | 13 +++++++++++++ Library/Homebrew/compat/hbc/caskroom.rb | 20 ++++++++++++++++++++ 6 files changed, 50 insertions(+), 26 deletions(-) create mode 100644 Library/Homebrew/compat/hbc/cache.rb create mode 100644 Library/Homebrew/compat/hbc/caskroom.rb diff --git a/Library/Homebrew/cask/lib/hbc.rb b/Library/Homebrew/cask/lib/hbc.rb index c971cbd58b..74158b04e8 100644 --- a/Library/Homebrew/cask/lib/hbc.rb +++ b/Library/Homebrew/cask/lib/hbc.rb @@ -45,9 +45,6 @@ module Hbc def self.init Cache.ensure_cache_exists - Cache.delete_legacy_cache - - Caskroom.migrate_caskroom_from_repo_to_prefix Caskroom.ensure_caskroom_exists end diff --git a/Library/Homebrew/cask/lib/hbc/cache.rb b/Library/Homebrew/cask/lib/hbc/cache.rb index 4e99fdd4f6..d2d0222ba9 100644 --- a/Library/Homebrew/cask/lib/hbc/cache.rb +++ b/Library/Homebrew/cask/lib/hbc/cache.rb @@ -8,13 +8,5 @@ module Hbc odebug "Creating Cache at #{Hbc.cache}" Hbc.cache.mkpath end - - 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/cask/lib/hbc/caskroom.rb b/Library/Homebrew/cask/lib/hbc/caskroom.rb index 255e23888a..7f4aab0a97 100644 --- a/Library/Homebrew/cask/lib/hbc/caskroom.rb +++ b/Library/Homebrew/cask/lib/hbc/caskroom.rb @@ -2,21 +2,6 @@ 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 - def ensure_caskroom_exists return if Hbc.caskroom.exist? diff --git a/Library/Homebrew/compat/hbc.rb b/Library/Homebrew/compat/hbc.rb index 179639953e..e60bdbc07a 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 0000000000..34221fcf1d --- /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 0000000000..489c5b224a --- /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