diff options
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc.rb | 3 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/cache.rb | 7 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/cask.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/caskroom.rb | 15 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/cli.rb | 11 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/cli/cleanup.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/cli/internal_audit_modified_casks.rb | 63 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/cli/style.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/locations.rb | 4 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/utils.rb | 34 | ||||
| -rw-r--r-- | Library/Homebrew/compat/hbc.rb | 17 | ||||
| -rw-r--r-- | Library/Homebrew/compat/hbc/cache.rb | 13 | ||||
| -rw-r--r-- | Library/Homebrew/compat/hbc/caskroom.rb | 20 | ||||
| -rw-r--r-- | Library/Homebrew/dev-cmd/bottle.rb | 1 | ||||
| -rw-r--r-- | Library/Homebrew/test/cask/cli/cleanup_spec.rb | 2 |
15 files changed, 82 insertions, 114 deletions
diff --git a/Library/Homebrew/cask/lib/hbc.rb b/Library/Homebrew/cask/lib/hbc.rb index 048f912ec..3cdec07d2 100644 --- a/Library/Homebrew/cask/lib/hbc.rb +++ b/Library/Homebrew/cask/lib/hbc.rb @@ -43,9 +43,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 7b586528e..d2d0222ba 100644 --- a/Library/Homebrew/cask/lib/hbc/cache.rb +++ b/Library/Homebrew/cask/lib/hbc/cache.rb @@ -8,12 +8,5 @@ module Hbc odebug "Creating Cache at #{Hbc.cache}" Hbc.cache.mkpath end - - def delete_legacy_cache - return unless Hbc.legacy_cache.exist? - - ohai "Deleting legacy cache at #{Hbc.legacy_cache}..." - FileUtils.remove_entry_secure(Hbc.legacy_cache) - end end end diff --git a/Library/Homebrew/cask/lib/hbc/cask.rb b/Library/Homebrew/cask/lib/hbc/cask.rb index ae0eed792..52dd676b4 100644 --- a/Library/Homebrew/cask/lib/hbc/cask.rb +++ b/Library/Homebrew/cask/lib/hbc/cask.rb @@ -71,7 +71,7 @@ module Hbc Pathname.glob(metadata_master_container_path.join("*", "*")) .map { |p| p.relative_path_from(metadata_master_container_path) } .sort_by(&:basename) # sort by timestamp - .map(&:split) + .map { |p| p.split.map(&:to_s) } end def versions diff --git a/Library/Homebrew/cask/lib/hbc/caskroom.rb b/Library/Homebrew/cask/lib/hbc/caskroom.rb index 255e23888..7f4aab0a9 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/cask/lib/hbc/cli.rb b/Library/Homebrew/cask/lib/hbc/cli.rb index bb88a6297..39235fa63 100644 --- a/Library/Homebrew/cask/lib/hbc/cli.rb +++ b/Library/Homebrew/cask/lib/hbc/cli.rb @@ -103,17 +103,6 @@ module Hbc @lookup.fetch(command_string, command_string) end - # modified from Homebrew - def self.require?(path) - require path - true # OK if already loaded - rescue LoadError => e - # HACK: :( because we should raise on syntax errors - # but not if the file doesn't exist. - # TODO: make robust! - raise unless e.to_s.include? path - end - def self.should_init?(command) (command.is_a? Class) && (command < CLI::Base) && command.needs_init? end diff --git a/Library/Homebrew/cask/lib/hbc/cli/cleanup.rb b/Library/Homebrew/cask/lib/hbc/cli/cleanup.rb index 5b6b00560..9ebccabd0 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/cleanup.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/cleanup.rb @@ -62,7 +62,7 @@ module Hbc end def disk_cleanup_size - Utils.size_in_bytes(cache_files) + cache_files.map(&:disk_usage).inject(:+) end def remove_cache_files(*tokens) diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_audit_modified_casks.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_audit_modified_casks.rb index d750f5af4..3b46bffe4 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_audit_modified_casks.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_audit_modified_casks.rb @@ -3,40 +3,38 @@ module Hbc class InternalAuditModifiedCasks < InternalUseBase RELEVANT_STANZAS = [:version, :sha256, :url, :appcast].freeze - class << self - def needs_init? - true - end + def self.needs_init? + true + end - def run(*args) - commit_range = commit_range(args) - cleanup = args.any? { |a| a =~ /^-+c(leanup)?$/i } - new(commit_range, cleanup: cleanup).run - end + def self.run(*args) + commit_range = commit_range(args) + cleanup = args.any? { |a| a =~ /^-+c(leanup)?$/i } + new(commit_range, cleanup: cleanup).run + end - def commit_range(args) - posargs = args.reject { |a| a.empty? || a.chars.first == "-" } - odie usage unless posargs.size == 1 - posargs.first - end + def self.commit_range(args) + posargs = args.reject { |a| a.empty? || a.chars.first == "-" } + odie usage unless posargs.size == 1 + posargs.first + end - def posargs(args) - args.reject { |a| a.empty? || a.chars.first == "-" } - end + def self.posargs(args) + args.reject { |a| a.empty? || a.chars.first == "-" } + end - def usage - <<-EOS.undent - Usage: brew cask _audit_modified_casks [options...] <commit range> + def self.usage + <<-EOS.undent + Usage: brew cask _audit_modified_casks [options...] <commit range> - Given a range of Git commits, find any Casks that were modified and run `brew - cask audit' on them. If the `url', `version', or `sha256' stanzas were modified, - run with the `--download' flag to verify the hash. + Given a range of Git commits, find any Casks that were modified and run `brew + cask audit' on them. If the `url', `version', or `sha256' stanzas were modified, + run with the `--download' flag to verify the hash. - Options: - -c, --cleanup - Remove all cached downloads. Use with care. - EOS - end + Options: + -c, --cleanup + Remove all cached downloads. Use with care. + EOS end def initialize(commit_range, cleanup: false) @@ -85,7 +83,7 @@ module Hbc @modified_casks = modified_cask_files.map { |f| Hbc.load(f) } if @modified_casks.any? num_modified = @modified_casks.size - ohai "#{num_modified} modified #{pluralize("cask", num_modified)}: " \ + ohai "#{num_modified} modified cask#{plural(num_modified)}: " \ "#{@modified_casks.join(" ")}" end @modified_casks @@ -122,15 +120,10 @@ module Hbc def report_failures return if failed_casks.empty? num_failed = failed_casks.size - cask_pluralized = pluralize("cask", num_failed) - odie "audit failed for #{num_failed} #{cask_pluralized}: " \ + odie "audit failed for #{num_failed} cask#{plural(num_failed)}: " \ "#{failed_casks.join(" ")}" end - def pluralize(str, num) - num == 1 ? str : "#{str}s" - end - def cleanup Cleanup.run if cleanup? end diff --git a/Library/Homebrew/cask/lib/hbc/cli/style.rb b/Library/Homebrew/cask/lib/hbc/cli/style.rb index a64a1dbe7..f38d785fc 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/style.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/style.rb @@ -24,7 +24,7 @@ module Hbc end def install_rubocop - Utils.capture_stderr do + capture_stderr do begin Homebrew.install_gem_setup_path! "rubocop-cask", HOMEBREW_RUBOCOP_CASK_VERSION, "rubocop" rescue SystemExit diff --git a/Library/Homebrew/cask/lib/hbc/locations.rb b/Library/Homebrew/cask/lib/hbc/locations.rb index 4fb4a2191..7a0f93851 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 diff --git a/Library/Homebrew/cask/lib/hbc/utils.rb b/Library/Homebrew/cask/lib/hbc/utils.rb index 6b839345a..3fc817dd5 100644 --- a/Library/Homebrew/cask/lib/hbc/utils.rb +++ b/Library/Homebrew/cask/lib/hbc/utils.rb @@ -89,27 +89,6 @@ module Hbc Etc.getpwuid(Process.euid).name end - # paths that "look" descendant (textually) will still - # return false unless both the given paths exist - def self.file_is_descendant(file, dir) - file = Pathname.new(file) - dir = Pathname.new(dir) - return false unless file.exist? && dir.exist? - unless dir.directory? - onoe "Argument must be a directory: '#{dir}'" - return false - end - unless file.absolute? && dir.absolute? - onoe "Both arguments must be absolute: '#{file}', '#{dir}'" - return false - end - while file.parent != file - return true if File.identical?(file, dir) - file = file.parent - end - false - end - def self.path_occupied?(path) File.exist?(path) || File.symlink?(path) end @@ -144,18 +123,5 @@ module Hbc timestamp.concat(fraction) container_path.join(timestamp) end - - def self.size_in_bytes(files) - Array(files).reduce(0) { |acc, elem| acc + (File.size?(elem) || 0) } - end - - def self.capture_stderr - previous_stderr = $stderr - $stderr = StringIO.new - yield - $stderr.string - ensure - $stderr = previous_stderr - end end end 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 diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb index 619986f76..b11da5607 100644 --- a/Library/Homebrew/dev-cmd/bottle.rb +++ b/Library/Homebrew/dev-cmd/bottle.rb @@ -437,7 +437,6 @@ module Homebrew --keep-old was passed but there are changes in: #{mismatches.join("\n")} EOS - odie "--keep-old was passed but there were changes in #{mismatches.join(", ")}!" end output = bottle_output bottle end diff --git a/Library/Homebrew/test/cask/cli/cleanup_spec.rb b/Library/Homebrew/test/cask/cli/cleanup_spec.rb index f8578e80d..c7ef356c0 100644 --- a/Library/Homebrew/test/cask/cli/cleanup_spec.rb +++ b/Library/Homebrew/test/cask/cli/cleanup_spec.rb @@ -19,7 +19,7 @@ describe Hbc::CLI::Cleanup, :cask do cached_downloads.each(&FileUtils.method(:touch)) - cleanup_size = Hbc::Utils.size_in_bytes(cached_downloads[0]) + cleanup_size = cached_downloads[0].disk_usage expect { subject.cleanup(cleaned_up_cached_download) |
