cleanup: tweak missing clean file behaviour.

Instead of cleaning every time if the file is missing: don't clean this
time, touch the file and clean when it's next needed.

Now that this feature has been around for longer this makes more sense
for existing installations and stops the first `brew install` run on a
new/test installation without this file always running a `brew cleanup`.

Also, fix up the use of a compat/deprecated method hit by tests by
this change.
This commit is contained in:
Mike McQuaid 2020-05-07 09:58:27 +01:00
parent 954c833de2
commit 4da5c09c25
No known key found for this signature in database
GPG Key ID: 48A898132FD8EE70

View File

@ -142,14 +142,18 @@ module Homebrew
cleanup = Cleanup.new
if cleanup.periodic_clean_due?
cleanup.periodic_clean!
elsif f.installed?
elsif f.latest_version_installed?
cleanup.cleanup_formula(f)
end
end
def periodic_clean_due?
return false if Homebrew::EnvConfig.no_install_cleanup?
return true unless PERIODIC_CLEAN_FILE.exist?
unless PERIODIC_CLEAN_FILE.exist?
FileUtils.touch PERIODIC_CLEAN_FILE
return false
end
PERIODIC_CLEAN_FILE.mtime < CLEANUP_DEFAULT_DAYS.days.ago
end