Change limit to minutes.
This commit is contained in:
parent
b57a448f2a
commit
0a54169fa6
@ -23,7 +23,7 @@ module Homebrew
|
|||||||
switch "-n", "--dry-run",
|
switch "-n", "--dry-run",
|
||||||
description: "List what would be done, but do not actually do anything."
|
description: "List what would be done, but do not actually do anything."
|
||||||
flag "--limit=",
|
flag "--limit=",
|
||||||
description: "Maximum number of casks to update."
|
description: "Maximum runtime in minutes."
|
||||||
flag "--state-file=",
|
flag "--state-file=",
|
||||||
description: "File for keeping track of state."
|
description: "File for keeping track of state."
|
||||||
|
|
||||||
@ -44,9 +44,7 @@ module Homebrew
|
|||||||
|
|
||||||
tap = Tap.fetch(args.named.first)
|
tap = Tap.fetch(args.named.first)
|
||||||
|
|
||||||
old_state = state_file.exist? ? JSON.parse(state_file.read) : {}
|
state = state_file.exist? ? JSON.parse(state_file.read) : {}
|
||||||
|
|
||||||
new_state = {}
|
|
||||||
|
|
||||||
cask_files = tap.cask_files
|
cask_files = tap.cask_files
|
||||||
unversioned_cask_files = cask_files.select do |cask_file|
|
unversioned_cask_files = cask_files.select do |cask_file|
|
||||||
@ -60,14 +58,28 @@ module Homebrew
|
|||||||
|
|
||||||
unversioned_casks = unversioned_cask_files.map { |path| Cask::CaskLoader.load(path) }
|
unversioned_casks = unversioned_cask_files.map { |path| Cask::CaskLoader.load(path) }
|
||||||
|
|
||||||
ohai "Static Casks:"
|
ohai "Unversioned Casks:"
|
||||||
puts "Total: #{unversioned_casks.count}"
|
puts "Total: #{unversioned_casks.count}"
|
||||||
puts "Single-App: #{unversioned_casks.count { |c| single_app_cask?(c) }}"
|
puts "Single-App: #{unversioned_casks.count { |c| single_app_cask?(c) }}"
|
||||||
puts "Single-Pkg: #{unversioned_casks.count { |c| single_pkg_cask?(c) }}"
|
puts "Single-Pkg: #{unversioned_casks.count { |c| single_pkg_cask?(c) }}"
|
||||||
|
|
||||||
limit = args.limit.presence&.to_i || unversioned_casks.count
|
checked, unchecked = unversioned_casks.partition { |c| state.key?(c.full_name) }
|
||||||
|
|
||||||
|
queue = Queue.new
|
||||||
|
|
||||||
|
unchecked.shuffle.each do |c|
|
||||||
|
queue.enq c
|
||||||
|
end
|
||||||
|
checked.sort_by { |c| state.dig(c.full_name, "check_time") }.each do |c|
|
||||||
|
queue.enq c
|
||||||
|
end
|
||||||
|
|
||||||
|
limit = args.limit.presence&.to_i
|
||||||
|
end_time = Time.now + limit.minutes if limit
|
||||||
|
|
||||||
|
until queue.empty? || (end_time && end_time < Time.now)
|
||||||
|
cask = queue.deq
|
||||||
|
|
||||||
unversioned_casks.shuffle.each do |cask|
|
|
||||||
ohai "Checking #{cask.full_name}"
|
ohai "Checking #{cask.full_name}"
|
||||||
|
|
||||||
unless single_app_cask?(cask)
|
unless single_app_cask?(cask)
|
||||||
@ -83,10 +95,7 @@ module Homebrew
|
|||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
odebug "Time: #{time.inspect}"
|
last_state = state.fetch(cask.full_name, {})
|
||||||
odebug "Size: #{file_size.inspect}"
|
|
||||||
|
|
||||||
last_state = old_state.fetch(cask.full_name, {})
|
|
||||||
last_check_time = last_state["check_time"]&.yield_self { |t| Time.parse(t) }
|
last_check_time = last_state["check_time"]&.yield_self { |t| Time.parse(t) }
|
||||||
|
|
||||||
check_time = Time.now
|
check_time = Time.now
|
||||||
@ -113,8 +122,6 @@ module Homebrew
|
|||||||
sha256 = cached_download.sha256
|
sha256 = cached_download.sha256
|
||||||
|
|
||||||
if last_sha256 != sha256 && (version = guess_cask_version(cask, installer))
|
if last_sha256 != sha256 && (version = guess_cask_version(cask, installer))
|
||||||
odebug "Version: #{version.inspect}"
|
|
||||||
|
|
||||||
if cask.version == version
|
if cask.version == version
|
||||||
oh1 "Cask #{cask} is up-to-date at #{version}"
|
oh1 "Cask #{cask} is up-to-date at #{version}"
|
||||||
else
|
else
|
||||||
@ -142,19 +149,17 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
unless args.dry_run?
|
next if args.dry_run?
|
||||||
new_state[cask.full_name] = {
|
|
||||||
"sha256" => sha256,
|
|
||||||
"check_time" => check_time.iso8601,
|
|
||||||
"time" => time&.iso8601,
|
|
||||||
"file_size" => file_size,
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
break if (limit -= 1).zero?
|
state[cask.full_name] = {
|
||||||
|
"sha256" => sha256,
|
||||||
|
"check_time" => check_time.iso8601,
|
||||||
|
"time" => time&.iso8601,
|
||||||
|
"file_size" => file_size,
|
||||||
|
}
|
||||||
|
|
||||||
|
state_file.atomic_write JSON.generate(state)
|
||||||
end
|
end
|
||||||
|
|
||||||
state_file.atomic_write JSON.pretty_generate(old_state.merge(new_state))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { params(cask: Cask::Cask, installer: Cask::Installer).returns(T.nilable(String)) }
|
sig { params(cask: Cask::Cask, installer: Cask::Installer).returns(T.nilable(String)) }
|
||||||
@ -165,7 +170,12 @@ module Homebrew
|
|||||||
Dir.mktmpdir do |dir|
|
Dir.mktmpdir do |dir|
|
||||||
dir = Pathname(dir)
|
dir = Pathname(dir)
|
||||||
|
|
||||||
installer.extract_primary_container(to: dir)
|
begin
|
||||||
|
installer.extract_primary_container(to: dir)
|
||||||
|
rescue => e
|
||||||
|
onoe e
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
plists = apps.flat_map do |app|
|
plists = apps.flat_map do |app|
|
||||||
Pathname.glob(dir/"**"/app.source.basename/"Contents"/"Info.plist")
|
Pathname.glob(dir/"**"/app.source.basename/"Contents"/"Info.plist")
|
||||||
|
|||||||
@ -906,7 +906,7 @@ Check all casks with unversioned URLs in a given *`tap`* for updates.
|
|||||||
* `-n`, `--dry-run`:
|
* `-n`, `--dry-run`:
|
||||||
List what would be done, but do not actually do anything.
|
List what would be done, but do not actually do anything.
|
||||||
* `--limit`:
|
* `--limit`:
|
||||||
Maximum number of casks to update.
|
Maximum runtime in minutes.
|
||||||
* `--state-file`:
|
* `--state-file`:
|
||||||
File for keeping track of state.
|
File for keeping track of state.
|
||||||
|
|
||||||
|
|||||||
@ -1254,7 +1254,7 @@ List what would be done, but do not actually do anything\.
|
|||||||
.
|
.
|
||||||
.TP
|
.TP
|
||||||
\fB\-\-limit\fR
|
\fB\-\-limit\fR
|
||||||
Maximum number of casks to update\.
|
Maximum runtime in minutes\.
|
||||||
.
|
.
|
||||||
.TP
|
.TP
|
||||||
\fB\-\-state\-file\fR
|
\fB\-\-state\-file\fR
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user