From e49a0434014464488de356550ffaa6028666faf5 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Thu, 13 Aug 2015 10:22:28 +0100 Subject: [PATCH] cleanup: remove more on --force or --prune. Remove more logs, use the prune time period and remove version control checkouts when --force or --prune is used. --- Library/Homebrew/cmd/cleanup.rb | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/cmd/cleanup.rb b/Library/Homebrew/cmd/cleanup.rb index 157b40891c..d905300581 100644 --- a/Library/Homebrew/cmd/cleanup.rb +++ b/Library/Homebrew/cmd/cleanup.rb @@ -23,9 +23,14 @@ module Homebrew def cleanup_logs return unless HOMEBREW_LOGS.directory? - time = Time.now - 2 * 7 * 24 * 60 * 60 # two weeks + prune = ARGV.value "prune" + if prune + time = Time.now - 60 * 60 * 24 * prune.to_i + else + time = Time.now - 60 * 60 * 24 * 7 * 2 # two weeks + end HOMEBREW_LOGS.subdirs.each do |dir| - cleanup_path(dir) { dir.rmtree } if dir.mtime < time + cleanup_path(dir) { dir.rmtree } if ARGV.force? || (dir.mtime < time) end end @@ -66,8 +71,18 @@ module Homebrew return unless HOMEBREW_CACHE.directory? prune = ARGV.value "prune" time = Time.now - 60 * 60 * 24 * prune.to_i - HOMEBREW_CACHE.children.select(&:file?).each do |file| - next cleanup_path(file) { file.unlink } if prune && file.mtime < time + HOMEBREW_CACHE.children.each do |path| + if ARGV.force? || (prune && path.mtime < time) + if path.file? + cleanup_path(path) { path.unlink } + elsif path.directory? && path.to_s.include?("--") + cleanup_path(path) { path.rmdir } + end + next + end + + next unless path.file? + file = path if Pathname::BOTTLE_EXTNAME_RX === file.to_s version = bottle_resolve_version(file) rescue file.version