Remove active_support Time extensions

This commit is contained in:
Douglas Eichelberger 2023-02-04 13:51:35 -08:00
parent 6a8dd4ff52
commit 24e7c2c5bd
4 changed files with 18 additions and 17 deletions

View File

@ -46,7 +46,8 @@ module Homebrew
return true if symlink? && !exist? return true if symlink? && !exist?
mtime < days.days.ago && ctime < days.days.ago days_ago = (DateTime.now - days).to_time
mtime < days_ago && ctime < days_ago
end end
def stale?(scrub: false) def stale?(scrub: false)
@ -125,8 +126,8 @@ module Homebrew
return true if scrub && cask.versions.exclude?(cask.version) return true if scrub && cask.versions.exclude?(cask.version)
if cask.version.latest? if cask.version.latest?
return mtime < CLEANUP_DEFAULT_DAYS.days.ago && cleanup_threshold = (DateTime.now - CLEANUP_DEFAULT_DAYS).to_time
ctime < CLEANUP_DEFAULT_DAYS.days.ago return mtime < cleanup_threshold && ctime < cleanup_threshold
end end
false false
@ -202,7 +203,7 @@ module Homebrew
return false return false
end end
PERIODIC_CLEAN_FILE.mtime < CLEANUP_DEFAULT_DAYS.days.ago PERIODIC_CLEAN_FILE.mtime < (DateTime.now - CLEANUP_DEFAULT_DAYS).to_time
end end
def self.periodic_clean!(dry_run: false) def self.periodic_clean!(dry_run: false)

View File

@ -65,7 +65,7 @@ module Homebrew
end end
limit = args.limit.presence&.to_i limit = args.limit.presence&.to_i
end_time = Time.now + limit.minutes if limit end_time = Time.now + (limit * 60) if limit
until queue.empty? || (end_time && end_time < Time.now) until queue.empty? || (end_time && end_time < Time.now)
cask = queue.deq cask = queue.deq
@ -101,7 +101,7 @@ module Homebrew
last_check_time = state["check_time"]&.then { |t| Time.parse(t) } last_check_time = state["check_time"]&.then { |t| Time.parse(t) }
check_time = Time.now check_time = Time.now
if last_check_time && check_time < (last_check_time + 1.day) if last_check_time && check_time < (last_check_time + (DateTime.now + 1).to_time)
opoo "Skipping, already checked within the last 24 hours." opoo "Skipping, already checked within the last 24 hours."
return return
end end
@ -119,7 +119,7 @@ module Homebrew
if last_time != time || last_file_size != file_size if last_time != time || last_file_size != file_size
sha256 = begin sha256 = begin
Timeout.timeout(5.minutes) do Timeout.timeout(5 * 60) do
unversioned_cask_checker.installer.download.sha256 unversioned_cask_checker.installer.download.sha256
end end
rescue => e rescue => e
@ -128,7 +128,7 @@ module Homebrew
if sha256.present? && last_sha256 != sha256 if sha256.present? && last_sha256 != sha256
version = begin version = begin
Timeout.timeout(1.minute) do Timeout.timeout(60) do
unversioned_cask_checker.guess_cask_version unversioned_cask_checker.guess_cask_version
end end
rescue Timeout::Error rescue Timeout::Error

View File

@ -13,7 +13,7 @@ require "forwardable"
# Only require "core_ext" here to ensure we're only requiring the minimum of # Only require "core_ext" here to ensure we're only requiring the minimum of
# what we need. # what we need.
require "active_support/core_ext/object/blank" require "active_support/core_ext/object/blank"
require "active_support/core_ext/numeric/time" require "active_support/core_ext/string/filters"
require "active_support/core_ext/object/try" require "active_support/core_ext/object/try"
require "active_support/core_ext/array/access" require "active_support/core_ext/array/access"
require "active_support/core_ext/string/inflections" require "active_support/core_ext/string/inflections"

View File

@ -37,8 +37,8 @@ describe Homebrew::Cleanup do
end end
it "returns true when ctime and mtime < days_default" do it "returns true when ctime and mtime < days_default" do
allow_any_instance_of(Pathname).to receive(:ctime).and_return(2.days.ago) allow_any_instance_of(Pathname).to receive(:ctime).and_return((DateTime.now - 2).to_time)
allow_any_instance_of(Pathname).to receive(:mtime).and_return(2.days.ago) allow_any_instance_of(Pathname).to receive(:mtime).and_return((DateTime.now - 2).to_time)
expect(path.prune?(1)).to be true expect(path.prune?(1)).to be true
end end
@ -186,8 +186,8 @@ describe Homebrew::Cleanup do
it "removes the download for the latest version after 30 days" do it "removes the download for the latest version after 30 days" do
download = Cask::Cache.path/"#{cask.token}--#{cask.version}" download = Cask::Cache.path/"#{cask.token}--#{cask.version}"
allow(download).to receive(:ctime).and_return(30.days.ago - 1.hour) allow(download).to receive(:ctime).and_return((DateTime.now - 30).to_time - (60 * 60))
allow(download).to receive(:mtime).and_return(30.days.ago - 1.hour) allow(download).to receive(:mtime).and_return((DateTime.now - 30).to_time - (60 * 60))
cleanup.cleanup_cask(cask) cleanup.cleanup_cask(cask)
@ -209,15 +209,15 @@ describe Homebrew::Cleanup do
end end
it "cleans up logs if older than 30 days" do it "cleans up logs if older than 30 days" do
allow_any_instance_of(Pathname).to receive(:ctime).and_return(31.days.ago) allow_any_instance_of(Pathname).to receive(:ctime).and_return((DateTime.now - 31).to_time)
allow_any_instance_of(Pathname).to receive(:mtime).and_return(31.days.ago) allow_any_instance_of(Pathname).to receive(:mtime).and_return((DateTime.now - 31).to_time)
cleanup.cleanup_logs cleanup.cleanup_logs
expect(path).not_to exist expect(path).not_to exist
end end
it "does not clean up logs less than 30 days old" do it "does not clean up logs less than 30 days old" do
allow_any_instance_of(Pathname).to receive(:ctime).and_return(15.days.ago) allow_any_instance_of(Pathname).to receive(:ctime).and_return((DateTime.now - 15).to_time)
allow_any_instance_of(Pathname).to receive(:mtime).and_return(15.days.ago) allow_any_instance_of(Pathname).to receive(:mtime).and_return((DateTime.now - 15).to_time)
cleanup.cleanup_logs cleanup.cleanup_logs
expect(path).to exist expect(path).to exist
end end