Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup: cleanup portable ruby, old linkage cache. #5029

Merged
merged 1 commit into from
Oct 4, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 41 additions & 0 deletions Library/Homebrew/cleanup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,10 @@ def clean!
end
cleanup_cache
cleanup_logs
cleanup_portable_ruby
return if dry_run?

cleanup_linkage_db
rm_ds_store
else
args.each do |arg|
Expand Down Expand Up @@ -290,6 +292,45 @@ def cleanup_lockfiles(*lockfiles)
end
end

def cleanup_portable_ruby
system_ruby_version =
Utils.popen_read("/usr/bin/ruby", "-e", "puts RUBY_VERSION")
.chomp
use_system_ruby = (
Gem::Version.new(system_ruby_version) >= Gem::Version.new(RUBY_VERSION)
) && ENV["HOMEBREW_FORCE_VENDOR_RUBY"].nil?
vendor_path = HOMEBREW_LIBRARY/"Homebrew/vendor"
portable_ruby_version_file = vendor_path/"portable-ruby-version"
portable_ruby_version = if portable_ruby_version_file.exist?
portable_ruby_version_file.read
.chomp
end

portable_ruby_path = vendor_path/"portable-ruby"
portable_ruby_glob = "#{portable_ruby_path}/*.*"
Pathname.glob(portable_ruby_glob).each do |path|
next if !use_system_ruby && portable_ruby_version == path.basename.to_s
if dry_run?
puts "Would remove: #{path} (#{path.abv})"
else
FileUtils.rm_rf path
end
end

return unless Dir.glob(portable_ruby_glob).empty?
return unless portable_ruby_path.exist?

if dry_run?
puts "Would remove: #{portable_ruby_path} (#{portable_ruby_path.abv})"
else
FileUtils.rm_rf portable_ruby_path
end
end

def cleanup_linkage_db
FileUtils.rm_rf [cache/"linkage.db", cache/"linkage.db.db"]
end

def rm_ds_store(dirs = nil)
dirs ||= begin
Keg::MUST_EXIST_DIRECTORIES + [
Expand Down