cleanup: tweak prune code.
This commit is contained in:
parent
e85e57b217
commit
76316a82cb
@ -20,7 +20,7 @@ module Homebrew
|
|||||||
def cleanup_logs
|
def cleanup_logs
|
||||||
return unless HOMEBREW_LOGS.directory?
|
return unless HOMEBREW_LOGS.directory?
|
||||||
HOMEBREW_LOGS.subdirs.each do |dir|
|
HOMEBREW_LOGS.subdirs.each do |dir|
|
||||||
cleanup_path(dir) { dir.rmtree } if prune?(:logs, dir.mtime)
|
cleanup_path(dir) { dir.rmtree } if prune?(dir, :days_default => 14)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ module Homebrew
|
|||||||
def cleanup_cache
|
def cleanup_cache
|
||||||
return unless HOMEBREW_CACHE.directory?
|
return unless HOMEBREW_CACHE.directory?
|
||||||
HOMEBREW_CACHE.children.each do |path|
|
HOMEBREW_CACHE.children.each do |path|
|
||||||
if prune?(:cache, path.mtime)
|
if prune?(path)
|
||||||
if path.file?
|
if path.file?
|
||||||
cleanup_path(path) { path.unlink }
|
cleanup_path(path) { path.unlink }
|
||||||
elsif path.directory? && path.to_s.include?("--")
|
elsif path.directory? && path.to_s.include?("--")
|
||||||
@ -121,27 +121,25 @@ module Homebrew
|
|||||||
quiet_system "find", *args
|
quiet_system "find", *args
|
||||||
end
|
end
|
||||||
|
|
||||||
def prune?(kind, time)
|
def prune?(path, options={})
|
||||||
unless @cleanup_prune_limit
|
@time ||= Time.now
|
||||||
# Infer and cache prune limits for cleanup: Use '--prune' or fall back to
|
|
||||||
# defaults (never prune download cache and prune logs after two weeks).
|
path_modified_time = path.mtime
|
||||||
days = ARGV.value "prune"
|
days_default = options[:days_default]
|
||||||
offset = Time.now
|
|
||||||
@cleanup_prune_limit = {}
|
prune = ARGV.value "prune"
|
||||||
{ :cache => nil, :logs => 14 }.each do |k, days_default|
|
|
||||||
@cleanup_prune_limit[k] = if days == "all"
|
return true if prune == "all"
|
||||||
"all"
|
|
||||||
elsif days
|
prune_time = if prune
|
||||||
offset - 60 * 60 * 24 * days.to_i
|
@time - 60 * 60 * 24 * prune.to_i
|
||||||
elsif days_default
|
elsif days_default
|
||||||
offset - 60 * 60 * 24 * days_default
|
@time - 60 * 60 * 24 * days_default.to_i
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if limit = @cleanup_prune_limit[kind]
|
return false unless prune_time
|
||||||
limit == "all" || time < limit
|
|
||||||
end
|
prune_time < path_modified_time
|
||||||
end
|
end
|
||||||
|
|
||||||
def eligible_for_cleanup?(formula)
|
def eligible_for_cleanup?(formula)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user