Class: Homebrew::Cmd::CleanupCmd

Inherits:
AbstractCommand show all
Defined in:
cmd/cleanup.rb

Instance Attribute Summary

Attributes inherited from AbstractCommand

#args

Instance Method Summary collapse

Methods inherited from AbstractCommand

command, command_name, #initialize, parser

Constructor Details

This class inherits a constructor from Homebrew::AbstractCommand

Instance Method Details

#runvoid

This method returns an undefined value.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'cmd/cleanup.rb', line 34

def run
  days = args.prune.presence&.then do |prune|
    case prune
    when /\A\d+\Z/
      prune.to_i
    when "all"
      0
    else
      raise UsageError, "`--prune` expects an integer or `all`."
    end
  end

  cleanup = Cleanup.new(*args.named, dry_run: args.dry_run?, scrub: args.s?, days:)
  if args.prune_prefix?
    cleanup.prune_prefix_symlinks_and_directories
    return
  end

  cleanup.clean!(quiet: args.quiet?, periodic: false)

  unless cleanup.disk_cleanup_size.zero?
    disk_space = disk_usage_readable(cleanup.disk_cleanup_size)
    if args.dry_run?
      ohai "This operation would free approximately #{disk_space} of disk space."
    else
      ohai "This operation has freed approximately #{disk_space} of disk space."
    end
  end

  return if cleanup.unremovable_kegs.empty?

  ofail <<~EOS
    Could not cleanup old kegs! Fix your permissions on:
      #{cleanup.unremovable_kegs.join "\n  "}
  EOS
end