From d50dc2e1bb35160600d285f859f2546470162780 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 14 Aug 2020 04:33:33 +0200 Subject: [PATCH] Refactor and document `Homebrew::Diagnostic`. --- Library/Homebrew/diagnostic.rb | 42 ++------------------ Library/Homebrew/extend/os/mac/diagnostic.rb | 38 ++++++++++++++++++ 2 files changed, 42 insertions(+), 38 deletions(-) diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index 82a511d193..e8309f30d1 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -12,6 +12,9 @@ require "cask/caskroom" require "cask/quarantine" module Homebrew + # Module containing diagnostic checks. + # + # @api private module Diagnostic def self.missing_deps(ff, hide = nil) missing = {} @@ -25,44 +28,7 @@ module Homebrew missing end - class Volumes - def initialize - @volumes = get_mounts - end - - def which(path) - vols = get_mounts path - - # no volume found - return -1 if vols.empty? - - vol_index = @volumes.index(vols[0]) - # volume not found in volume list - return -1 if vol_index.nil? - - vol_index - end - - def get_mounts(path = nil) - vols = [] - # get the volume of path, if path is nil returns all volumes - - args = %w[/bin/df -P] - args << path if path - - Utils.popen_read(*args) do |io| - io.each_line do |line| - case line.chomp - # regex matches: /dev/disk0s2 489562928 440803616 48247312 91% / - when /^.+\s+[0-9]+\s+[0-9]+\s+[0-9]+\s+[0-9]{1,3}%\s+(.+)/ - vols << Regexp.last_match(1) - end - end - end - vols - end - end - + # Diagnostic checks. class Checks def initialize(verbose = true) @verbose = verbose diff --git a/Library/Homebrew/extend/os/mac/diagnostic.rb b/Library/Homebrew/extend/os/mac/diagnostic.rb index d9b9cadf32..21cd0faee4 100644 --- a/Library/Homebrew/extend/os/mac/diagnostic.rb +++ b/Library/Homebrew/extend/os/mac/diagnostic.rb @@ -2,6 +2,44 @@ module Homebrew module Diagnostic + class Volumes + def initialize + @volumes = get_mounts + end + + def which(path) + vols = get_mounts path + + # no volume found + return -1 if vols.empty? + + vol_index = @volumes.index(vols[0]) + # volume not found in volume list + return -1 if vol_index.nil? + + vol_index + end + + def get_mounts(path = nil) + vols = [] + # get the volume of path, if path is nil returns all volumes + + args = %w[/bin/df -P] + args << path if path + + Utils.popen_read(*args) do |io| + io.each_line do |line| + case line.chomp + # regex matches: /dev/disk0s2 489562928 440803616 48247312 91% / + when /^.+\s+[0-9]+\s+[0-9]+\s+[0-9]+\s+[0-9]{1,3}%\s+(.+)/ + vols << Regexp.last_match(1) + end + end + end + vols + end + end + class Checks undef fatal_build_from_source_checks, supported_configuration_checks, build_from_source_checks