50 lines
1.8 KiB
Ruby
Raw Normal View History

module Hbc
module Caskroom
2018-05-18 13:35:41 +02:00
class << self
module Compat
def migrate_legacy_caskroom
return if path.exist?
legacy_caskroom_path = Pathname.new("/opt/homebrew-cask/Caskroom")
return if path == legacy_caskroom_path
return unless legacy_caskroom_path.exist?
return if legacy_caskroom_path.symlink?
2017-03-06 21:28:34 +01:00
ohai "Migrating Caskroom from #{legacy_caskroom_path} to #{path}."
if path.parent.writable?
FileUtils.mv legacy_caskroom_path, path
2018-05-18 13:35:41 +02:00
else
opoo "#{path.parent} is not writable, sudo is needed to move the Caskroom."
SystemCommand.run("/bin/mv", args: [legacy_caskroom_path, path.parent], sudo: true)
2018-05-18 13:35:41 +02:00
end
2017-03-06 21:28:34 +01:00
ohai "Creating symlink from #{path} to #{legacy_caskroom_path}."
if legacy_caskroom_path.parent.writable?
FileUtils.ln_s path, legacy_caskroom_path
2018-05-18 13:35:41 +02:00
else
opoo "#{legacy_caskroom_path.parent} is not writable, sudo is needed to link the Caskroom."
SystemCommand.run("/bin/ln", args: ["-s", path, legacy_caskroom_path], sudo: true)
2018-05-18 13:35:41 +02:00
end
end
2017-03-06 21:28:34 +01:00
2018-05-18 13:35:41 +02:00
def migrate_caskroom_from_repo_to_prefix
repo_caskroom_path = HOMEBREW_REPOSITORY.join("Caskroom")
return if path.exist?
return unless repo_caskroom_path.directory?
2017-03-06 21:28:34 +01:00
2018-05-18 13:35:41 +02:00
ohai "Moving Caskroom from HOMEBREW_REPOSITORY to HOMEBREW_PREFIX"
if path.parent.writable?
FileUtils.mv repo_caskroom_path, path
2018-05-18 13:35:41 +02:00
else
opoo "#{path.parent} is not writable, sudo is needed to move the Caskroom."
SystemCommand.run("/bin/mv", args: [repo_caskroom_path, path.parent], sudo: true)
2018-05-18 13:35:41 +02:00
end
end
end
2018-05-18 13:35:41 +02:00
prepend Compat
end
end
end