diff --git a/Library/Homebrew/lock_file.rb b/Library/Homebrew/lock_file.rb index ed47b01f87..adcad80a14 100644 --- a/Library/Homebrew/lock_file.rb +++ b/Library/Homebrew/lock_file.rb @@ -1,4 +1,4 @@ -# typed: true # rubocop:todo Sorbet/StrictSigil +# typed: strict # frozen_string_literal: true require "fcntl" @@ -11,14 +11,15 @@ class LockFile class OpenFileChangedOnDisk < RuntimeError; end private_constant :OpenFileChangedOnDisk + sig { returns(Pathname) } attr_reader :path sig { params(type: Symbol, locked_path: Pathname).void } def initialize(type, locked_path) @locked_path = locked_path lock_name = locked_path.basename.to_s - @path = HOMEBREW_LOCKS/"#{lock_name}.#{type}.lock" - @lockfile = nil + @path = T.let(HOMEBREW_LOCKS/"#{lock_name}.#{type}.lock", Pathname) + @lockfile = T.let(nil, T.nilable(File)) end sig { void } @@ -30,7 +31,7 @@ class LockFile begin lockfile = begin - path.open(File::RDWR | File::CREAT) + File.open(path, File::RDWR | File::CREAT) rescue Errno::EMFILE odie "The maximum number of open files on this system has been reached. " \ "Use `ulimit -n` to increase this limit." @@ -78,7 +79,8 @@ class LockFile end end - def with_lock + sig { params(_block: T.proc.void).void } + def with_lock(&_block) lock yield ensure diff --git a/Library/Homebrew/simulate_system.rb b/Library/Homebrew/simulate_system.rb index 840d4ea963..b36f479b08 100644 --- a/Library/Homebrew/simulate_system.rb +++ b/Library/Homebrew/simulate_system.rb @@ -1,4 +1,4 @@ -# typed: true # rubocop:todo Sorbet/StrictSigil +# typed: strict # frozen_string_literal: true require "macos_version" @@ -8,7 +8,11 @@ module Homebrew # Helper module for simulating different system configurations. class SimulateSystem class << self - attr_reader :arch, :os + sig { returns(T.nilable(Symbol)) } + attr_reader :arch + + sig { returns(T.nilable(Symbol)) } + attr_reader :os sig { returns(T::Hash[Symbol, Symbol]) } def arch_symbols @@ -56,14 +60,14 @@ module Homebrew os_options = [:macos, :linux, *MacOSVersion::SYMBOLS.keys] raise "Unknown OS: #{new_os}" unless os_options.include?(new_os) - @os = new_os + @os = T.let(new_os, T.nilable(Symbol)) end sig { params(new_arch: Symbol).void } def arch=(new_arch) raise "New arch must be :arm or :intel" unless OnSystem::ARCH_OPTIONS.include?(new_arch) - @arch = new_arch + @arch = T.let(new_arch, T.nilable(Symbol)) end sig { void }