Class: Homebrew::Cleanup Private
- Extended by:
- Predicable
- Defined in:
- cleanup.rb,
extend/os/mac/cleanup.rb,
extend/os/linux/cleanup.rb
Overview
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
Helper class for cleaning up the Homebrew cache.
Constant Summary collapse
- PERIODIC_CLEAN_FILE =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
(HOMEBREW_CACHE/".cleaned").freeze
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
private
-
#cache ⇒ Object
readonly
private
-
#days ⇒ Object
readonly
private
-
#disk_cleanup_size ⇒ Object
readonly
private
Class Method Summary collapse
-
.autoremove(dry_run: false) ⇒ Object
private
-
.go_cache_directory?(pathname) ⇒ Boolean
private
-
.incomplete?(pathname) ⇒ Boolean
private
-
.install_formula_clean!(formula, dry_run: false) ⇒ Object
private
-
.nested_cache?(pathname) ⇒ Boolean
private
-
.periodic_clean!(dry_run: false) ⇒ Object
private
-
.periodic_clean_due? ⇒ Boolean
private
-
.prune?(pathname, days) ⇒ Boolean
private
-
.puts_no_install_cleanup_disable_message ⇒ Object
private
-
.puts_no_install_cleanup_disable_message_if_not_already! ⇒ Object
private
-
.skip_clean_formula?(formula) ⇒ Boolean
private
-
.stale?(entry, scrub: false) ⇒ Boolean
private
Instance Method Summary collapse
-
#cache_files ⇒ Object
private
-
#clean!(quiet: false, periodic: false) ⇒ Object
private
-
#cleanup_bootsnap ⇒ Object
private
-
#cleanup_cache(entries = nil) ⇒ Object
private
-
#cleanup_cache_db(rack = nil) ⇒ Object
private
-
#cleanup_cask(cask, ds_store: true) ⇒ Object
private
-
#cleanup_empty_api_source_directories(directory = cache/"api-source") ⇒ Object
private
-
#cleanup_formula(formula, quiet: false, ds_store: true, cache_db: true) ⇒ Object
private
-
#cleanup_keg(keg) ⇒ Object
private
-
#cleanup_lockfiles(*lockfiles) ⇒ Object
private
-
#cleanup_logs ⇒ Object
private
-
#cleanup_path(path) ⇒ Object
private
-
#cleanup_portable_ruby ⇒ Object
private
-
#cleanup_python_site_packages ⇒ Object
private
-
#cleanup_unreferenced_downloads ⇒ Object
private
-
#initialize(*args, dry_run: false, scrub: false, days: nil, cache: HOMEBREW_CACHE) ⇒ Cleanup
constructor
private
A new instance of Cleanup.
-
#prune_prefix_symlinks_and_directories ⇒ Object
private
-
#rm_ds_store(dirs = nil) ⇒ Object
private
-
#unremovable_kegs ⇒ Object
private
-
#use_system_ruby? ⇒ Boolean
private
Methods included from Predicable
Constructor Details
#initialize(*args, dry_run: false, scrub: false, days: nil, cache: HOMEBREW_CACHE) ⇒ Cleanup
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Returns a new instance of Cleanup.
186 187 188 189 190 191 192 193 194 195 |
# File 'cleanup.rb', line 186 def initialize(*args, dry_run: false, scrub: false, days: nil, cache: HOMEBREW_CACHE) @disk_cleanup_size = 0 @args = args @dry_run = dry_run @scrub = scrub @prune = days.present? @days = days || Homebrew::EnvConfig.cleanup_max_age_days.to_i @cache = cache @cleaned_up_paths = Set.new end |
Instance Attribute Details
#args ⇒ Object (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
184 185 186 |
# File 'cleanup.rb', line 184 def args @args end |
#cache ⇒ Object (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
184 185 186 |
# File 'cleanup.rb', line 184 def cache @cache end |
#days ⇒ Object (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
184 185 186 |
# File 'cleanup.rb', line 184 def days @days end |
#disk_cleanup_size ⇒ Object (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
184 185 186 |
# File 'cleanup.rb', line 184 def disk_cleanup_size @disk_cleanup_size end |
Class Method Details
.autoremove(dry_run: false) ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 |
# File 'cleanup.rb', line 642 def self.autoremove(dry_run: false) require "utils/autoremove" require "cask/caskroom" # If this runs after install, uninstall, reinstall or upgrade, # the cache of installed formulae may no longer be valid. Formula.clear_cache unless dry_run formulae = Formula.installed # Remove formulae listed in HOMEBREW_NO_CLEANUP_FORMULAE and their dependencies. if Homebrew::EnvConfig.no_cleanup_formulae.present? formulae -= formulae.select(&method(:skip_clean_formula?)) .flat_map { |f| [f, *f.runtime_formula_dependencies] } end casks = Cask::Caskroom.casks removable_formulae = Utils::Autoremove.removable_formulae(formulae, casks) return if removable_formulae.blank? formulae_names = removable_formulae.map(&:full_name).sort verb = dry_run ? "Would autoremove" : "Autoremoving" oh1 "#{verb} #{formulae_names.count} unneeded #{Utils.pluralize("formula", formulae_names.count, plural: "e")}:" puts formulae_names.join("\n") return if dry_run require "uninstall" kegs_by_rack = removable_formulae.map(&:any_installed_keg).group_by(&:rack) Uninstall.uninstall_kegs(kegs_by_rack) # The installed formula cache will be invalid after uninstalling. Formula.clear_cache end |
.go_cache_directory?(pathname) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
39 40 41 42 43 |
# File 'cleanup.rb', line 39 def go_cache_directory?(pathname) # Go makes its cache contents read-only to ensure cache integrity, # which makes sense but is something we need to undo for cleanup. pathname.directory? && %w[go_cache go_mod_cache].include?(pathname.basename.to_s) end |
.incomplete?(pathname) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
20 21 22 |
# File 'cleanup.rb', line 20 def incomplete?(pathname) pathname.extname.end_with?(".incomplete") end |
.install_formula_clean!(formula, dry_run: false) ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'cleanup.rb', line 197 def self.install_formula_clean!(formula, dry_run: false) return if Homebrew::EnvConfig.no_install_cleanup? return unless formula.latest_version_installed? return if skip_clean_formula?(formula) if dry_run ohai "Would run `brew cleanup #{formula}`" else ohai "Running `brew cleanup #{formula}`..." end return if dry_run Cleanup.new.cleanup_formula(formula) end |
.nested_cache?(pathname) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'cleanup.rb', line 25 def nested_cache?(pathname) pathname.directory? && %w[ cargo_cache go_cache go_mod_cache glide_home java_cache npm_cache pip_cache gclient_cache ].include?(pathname.basename.to_s) end |
.periodic_clean!(dry_run: false) ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'cleanup.rb', line 249 def self.periodic_clean!(dry_run: false) return if Homebrew::EnvConfig.no_install_cleanup? return unless periodic_clean_due? if dry_run oh1 "Would run `brew cleanup` which has not been run in the last #{CLEANUP_DEFAULT_DAYS} days" else oh1 "`brew cleanup` has not been run in the last #{CLEANUP_DEFAULT_DAYS} days, running now..." end return if dry_run Cleanup.new.clean!(quiet: true, periodic: true) end |
.periodic_clean_due? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
237 238 239 240 241 242 243 244 245 246 247 |
# File 'cleanup.rb', line 237 def self.periodic_clean_due? return false if Homebrew::EnvConfig.no_install_cleanup? unless PERIODIC_CLEAN_FILE.exist? HOMEBREW_CACHE.mkpath FileUtils.touch PERIODIC_CLEAN_FILE return false end PERIODIC_CLEAN_FILE.mtime < (DateTime.now - CLEANUP_DEFAULT_DAYS).to_time end |
.prune?(pathname, days) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
46 47 48 49 50 51 52 53 |
# File 'cleanup.rb', line 46 def prune?(pathname, days) return false unless days return true if days.zero? return true if pathname.symlink? && !pathname.exist? days_ago = (DateTime.now - days).to_time pathname.mtime < days_ago && pathname.ctime < days_ago end |
.puts_no_install_cleanup_disable_message ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
214 215 216 217 218 219 220 |
# File 'cleanup.rb', line 214 def self. return if Homebrew::EnvConfig.no_env_hints? return if Homebrew::EnvConfig.no_install_cleanup? puts "Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP." puts "Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`)." end |
.puts_no_install_cleanup_disable_message_if_not_already! ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
222 223 224 225 226 227 |
# File 'cleanup.rb', line 222 def self. return if @puts_no_install_cleanup_disable_message_if_not_already @puts_no_install_cleanup_disable_message_if_not_already = true end |
.skip_clean_formula?(formula) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
229 230 231 232 233 234 235 |
# File 'cleanup.rb', line 229 def self.skip_clean_formula?(formula) no_cleanup_formula = Homebrew::EnvConfig.no_cleanup_formulae return false if no_cleanup_formula.blank? @skip_clean_formulae ||= no_cleanup_formula.split(",") @skip_clean_formulae.include?(formula.name) || (@skip_clean_formulae & formula.aliases).present? end |
.stale?(entry, scrub: false) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'cleanup.rb', line 56 def stale?(entry, scrub: false) pathname = entry[:path] return false unless pathname.resolved_path.file? case entry[:type] when :api_source stale_api_source?(pathname, scrub) when :cask stale_cask?(pathname, scrub) when :gh_actions_artifact stale_gh_actions_artifact?(pathname, scrub) else stale_formula?(pathname, scrub) end end |
Instance Method Details
#cache_files ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
359 360 361 362 363 364 365 366 367 368 369 |
# File 'cleanup.rb', line 359 def cache_files files = cache.directory? ? cache.children : [] cask_files = (cache/"Cask").directory? ? (cache/"Cask").children : [] api_source_files = (cache/"api-source").glob("*/*/*/*/*") # org/repo/git_head/type/file.rb gh_actions_artifacts = (cache/"gh-actions-artifact").directory? ? (cache/"gh-actions-artifact").children : [] files.map { |path| { path: path, type: nil } } + cask_files.map { |path| { path: path, type: :cask } } + api_source_files.map { |path| { path: path, type: :api_source } } + gh_actions_artifacts.map { |path| { path: path, type: :gh_actions_artifact } } end |
#clean!(quiet: false, periodic: false) ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
# File 'cleanup.rb', line 265 def clean!(quiet: false, periodic: false) if args.empty? Formula.installed .sort_by(&:name) .reject { |f| Cleanup.skip_clean_formula?(f) } .each do |formula| cleanup_formula(formula, quiet: quiet, ds_store: false, cache_db: false) end Cleanup.autoremove(dry_run: dry_run?) if Homebrew::EnvConfig.autoremove? cleanup_cache cleanup_empty_api_source_directories cleanup_logs cleanup_lockfiles cleanup_python_site_packages prune_prefix_symlinks_and_directories unless dry_run? cleanup_cache_db rm_ds_store HOMEBREW_CACHE.mkpath FileUtils.touch PERIODIC_CLEAN_FILE end # Cleaning up Ruby needs to be done last to avoid requiring additional # files afterwards. Additionally, don't allow it on periodic cleans to # avoid having to try to do a `brew install` when we've just deleted # the running Ruby process... return if periodic cleanup_portable_ruby cleanup_bootsnap else args.each do |arg| formula = begin Formulary.resolve(arg) rescue FormulaUnavailableError, TapFormulaAmbiguityError, TapFormulaWithOldnameAmbiguityError nil end cask = begin Cask::CaskLoader.load(arg) rescue Cask::CaskError nil end if formula && Cleanup.skip_clean_formula?(formula) onoe "Refusing to clean #{formula} because it is listed in " \ "#{Tty.bold}HOMEBREW_NO_CLEANUP_FORMULAE#{Tty.reset}!" elsif formula cleanup_formula(formula) end cleanup_cask(cask) if cask end end end |
#cleanup_bootsnap ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
509 510 511 512 513 514 |
# File 'cleanup.rb', line 509 def cleanup_bootsnap bootsnap = cache/"bootsnap" return unless bootsnap.exist? cleanup_path(bootsnap) { bootsnap.rmtree } end |
#cleanup_cache(entries = nil) ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 |
# File 'cleanup.rb', line 409 def cleanup_cache(entries = nil) entries ||= cache_files entries.each do |entry| path = entry[:path] next if path == PERIODIC_CLEAN_FILE FileUtils.chmod_R 0755, path if self.class.go_cache_directory?(path) && !dry_run? next cleanup_path(path) { path.unlink } if self.class.incomplete?(path) next cleanup_path(path) { FileUtils.rm_rf path } if self.class.nested_cache?(path) if self.class.prune?(path, days) if path.file? || path.symlink? cleanup_path(path) { path.unlink } elsif path.directory? && path.to_s.include?("--") cleanup_path(path) { FileUtils.rm_rf path } end next end # If we've specified --prune don't do the (expensive) .stale? check. cleanup_path(path) { path.unlink } if !prune? && self.class.stale?(entry, scrub: scrub?) end cleanup_unreferenced_downloads end |
#cleanup_cache_db(rack = nil) ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 |
# File 'cleanup.rb', line 516 def cleanup_cache_db(rack = nil) FileUtils.rm_rf [ cache/"desc_cache.json", cache/"linkage.db", cache/"linkage.db.db", ] CacheStoreDatabase.use(:linkage) do |db| break unless db.created? db.each_key do |keg| next if rack.present? && !keg.start_with?("#{rack}/") next if File.directory?(keg) LinkageCacheStore.new(keg, db).delete! end end end |
#cleanup_cask(cask, ds_store: true) ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
336 337 338 339 340 |
# File 'cleanup.rb', line 336 def cleanup_cask(cask, ds_store: true) cleanup_cache(Pathname.glob(cache/"Cask/#{cask.token}--*").map { |path| { path: path, type: :cask } }) rm_ds_store([cask.caskroom_path]) if ds_store cleanup_lockfiles(CaskLock.new(cask.token).path) end |
#cleanup_empty_api_source_directories(directory = cache/"api-source") ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
371 372 373 374 375 376 377 378 379 380 381 |
# File 'cleanup.rb', line 371 def cleanup_empty_api_source_directories(directory = cache/"api-source") return if dry_run? return unless directory.directory? directory.each_child do |child| next unless child.directory? cleanup_empty_api_source_directories(child) child.rmdir if child.empty? end end |
#cleanup_formula(formula, quiet: false, ds_store: true, cache_db: true) ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
327 328 329 330 331 332 333 334 |
# File 'cleanup.rb', line 327 def cleanup_formula(formula, quiet: false, ds_store: true, cache_db: true) formula.eligible_kegs_for_cleanup(quiet: quiet) .each(&method(:cleanup_keg)) cleanup_cache(Pathname.glob(cache/"#{formula.name}--*").map { |path| { path: path, type: nil } }) rm_ds_store([formula.rack]) if ds_store cleanup_cache_db(formula.rack) if cache_db cleanup_lockfiles(FormulaLock.new(formula.name).path) end |
#cleanup_keg(keg) ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
342 343 344 345 346 347 |
# File 'cleanup.rb', line 342 def cleanup_keg(keg) cleanup_path(keg) { keg.uninstall(raise_failures: true) } rescue Errno::EACCES, Errno::ENOTEMPTY => e opoo e. unremovable_kegs << keg end |
#cleanup_lockfiles(*lockfiles) ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 |
# File 'cleanup.rb', line 450 def cleanup_lockfiles(*lockfiles) return if dry_run? lockfiles = HOMEBREW_LOCKS.children.select(&:file?) if lockfiles.empty? && HOMEBREW_LOCKS.directory? lockfiles.each do |file| next unless file.readable? next unless file.open(File::RDWR).flock(File::LOCK_EX | File::LOCK_NB) begin file.unlink ensure file.open(File::RDWR).flock(File::LOCK_UN) if file.exist? end end end |
#cleanup_logs ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
349 350 351 352 353 354 355 356 357 |
# File 'cleanup.rb', line 349 def cleanup_logs return unless HOMEBREW_LOGS.directory? logs_days = [days, CLEANUP_DEFAULT_DAYS].min HOMEBREW_LOGS.subdirs.each do |dir| cleanup_path(dir) { dir.rmtree } if self.class.prune?(dir, logs_days) end end |
#cleanup_path(path) ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
436 437 438 439 440 441 442 443 444 445 446 447 448 |
# File 'cleanup.rb', line 436 def cleanup_path(path) return unless path.exist? return unless @cleaned_up_paths.add?(path) @disk_cleanup_size += path.disk_usage if dry_run? puts "Would remove: #{path} (#{path.abv})" else puts "Removing: #{path}... (#{path.abv})" yield end end |
#cleanup_portable_ruby ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 |
# File 'cleanup.rb', line 467 def cleanup_portable_ruby vendor_dir = HOMEBREW_LIBRARY/"Homebrew/vendor" portable_ruby_latest_version = (vendor_dir/"portable-ruby-version").read.chomp portable_rubies_to_remove = [] Pathname.glob(vendor_dir/"portable-ruby/*.*").select(&:directory?).each do |path| next if !use_system_ruby? && portable_ruby_latest_version == path.basename.to_s portable_rubies_to_remove << path end return if portable_rubies_to_remove.empty? bundler_paths = (vendor_dir/"bundle/ruby").children.select do |child| basename = child.basename.to_s next false if basename == ".homebrew_gem_groups" next true unless child.directory? [ "#{Version.new(portable_ruby_latest_version).major_minor}.0", RbConfig::CONFIG["ruby_version"], ].uniq.exclude?(basename) end bundler_paths.each do |bundler_path| if dry_run? puts Utils.popen_read("git", "-C", HOMEBREW_REPOSITORY, "clean", "-nx", bundler_path).chomp else puts Utils.popen_read("git", "-C", HOMEBREW_REPOSITORY, "clean", "-ffqx", bundler_path).chomp end end portable_rubies_to_remove.each do |portable_ruby| cleanup_path(portable_ruby) { portable_ruby.rmtree } end end |
#cleanup_python_site_packages ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 |
# File 'cleanup.rb', line 549 def cleanup_python_site_packages pyc_files = Hash.new { |h, k| h[k] = [] } seen_non_pyc_file = Hash.new { |h, k| h[k] = false } unused_pyc_files = [] HOMEBREW_PREFIX.glob("lib/python*/site-packages").each do |site_packages| site_packages.each_child do |child| next unless child.directory? # TODO: Work out a sensible way to clean up pip's, setuptools', and wheel's # {dist,site}-info directories. Alternatively, consider always removing # all `-info` directories, because we may not be making use of them. next if child.basename.to_s.end_with?("-info") # Clean up old *.pyc files in the top-level __pycache__. if child.basename.to_s == "__pycache__" child.find do |path| next if path.extname != ".pyc" next unless self.class.prune?(path, days) unused_pyc_files << path end next end # Look for directories that contain only *.pyc files. child.find do |path| next if path.directory? if path.extname == ".pyc" pyc_files[child] << path else seen_non_pyc_file[child] = true break end end end end unused_pyc_files += pyc_files.reject { |k,| seen_non_pyc_file[k] } .values .flatten return if unused_pyc_files.blank? unused_pyc_files.each do |pyc| cleanup_path(pyc) { pyc.unlink } end end |
#cleanup_unreferenced_downloads ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 |
# File 'cleanup.rb', line 383 def cleanup_unreferenced_downloads return if dry_run? return unless (cache/"downloads").directory? downloads = (cache/"downloads").children referenced_downloads = cache_files.map { |file| file[:path] }.select(&:symlink?).map(&:resolved_path) (downloads - referenced_downloads).each do |download| if self.class.incomplete?(download) begin LockFile.new(download.basename).with_lock do download.unlink end rescue OperationInProgressError # Skip incomplete downloads which are still in progress. next end elsif download.directory? FileUtils.rm_rf download else download.unlink end end end |
#prune_prefix_symlinks_and_directories ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 |
# File 'cleanup.rb', line 598 def prune_prefix_symlinks_and_directories ObserverPathnameExtension.reset_counts! dirs = [] Keg::MUST_EXIST_SUBDIRECTORIES.each do |dir| next unless dir.directory? dir.find do |path| path.extend(ObserverPathnameExtension) if path.symlink? unless path.resolved_path_exists? path.uninstall_info if path.to_s.match?(Keg::INFOFILE_RX) && !dry_run? if dry_run? puts "Would remove (broken link): #{path}" else path.unlink end end elsif path.directory? && Keg::MUST_EXIST_SUBDIRECTORIES.exclude?(path) dirs << path end end end dirs.reverse_each do |d| if dry_run? && d.children.empty? puts "Would remove (empty directory): #{d}" else d.rmdir_if_possible end end return if dry_run? return if ObserverPathnameExtension.total.zero? n, d = ObserverPathnameExtension.counts print "Pruned #{n} symbolic links " print "and #{d} directories " if d.positive? puts "from #{HOMEBREW_PREFIX}" end |
#rm_ds_store(dirs = nil) ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
535 536 537 538 539 540 541 542 543 544 545 546 547 |
# File 'cleanup.rb', line 535 def rm_ds_store(dirs = nil) dirs ||= Keg::MUST_EXIST_DIRECTORIES + [ HOMEBREW_PREFIX/"Caskroom", ] dirs.select(&:directory?) .flat_map { |d| Pathname.glob("#{d}/**/.DS_Store") } .each do |dir| dir.unlink rescue Errno::EACCES # don't care if we can't delete a .DS_Store nil end end |
#unremovable_kegs ⇒ Object
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
323 324 325 |
# File 'cleanup.rb', line 323 def unremovable_kegs @unremovable_kegs ||= [] end |
#use_system_ruby? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
8 9 10 11 12 |
# File 'extend/os/mac/cleanup.rb', line 8 def use_system_ruby? return false if Homebrew::EnvConfig.force_vendor_ruby? ENV["HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH"].present? end |