Fix type errors in Sandbox.
This commit is contained in:
parent
9ee8cc97c9
commit
cf169e5270
@ -5,9 +5,12 @@
|
|||||||
#
|
#
|
||||||
# @api private
|
# @api private
|
||||||
module OS
|
module OS
|
||||||
|
extend T::Sig
|
||||||
|
|
||||||
# Check if the operating system is macOS.
|
# Check if the operating system is macOS.
|
||||||
#
|
#
|
||||||
# @api public
|
# @api public
|
||||||
|
sig { returns(T::Boolean) }
|
||||||
def self.mac?
|
def self.mac?
|
||||||
return false if ENV["HOMEBREW_TEST_GENERIC_OS"]
|
return false if ENV["HOMEBREW_TEST_GENERIC_OS"]
|
||||||
|
|
||||||
@ -17,6 +20,7 @@ module OS
|
|||||||
# Check if the operating system is Linux.
|
# Check if the operating system is Linux.
|
||||||
#
|
#
|
||||||
# @api public
|
# @api public
|
||||||
|
sig { returns(T::Boolean) }
|
||||||
def self.linux?
|
def self.linux?
|
||||||
return false if ENV["HOMEBREW_TEST_GENERIC_OS"]
|
return false if ENV["HOMEBREW_TEST_GENERIC_OS"]
|
||||||
|
|
||||||
@ -26,6 +30,7 @@ module OS
|
|||||||
# Get the kernel version.
|
# Get the kernel version.
|
||||||
#
|
#
|
||||||
# @api public
|
# @api public
|
||||||
|
sig { returns(Version) }
|
||||||
def self.kernel_version
|
def self.kernel_version
|
||||||
@kernel_version ||= Version.new(Utils.safe_popen_read("uname", "-r").chomp)
|
@kernel_version ||= Version.new(Utils.safe_popen_read("uname", "-r").chomp)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
# typed: false
|
# typed: true
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "erb"
|
require "erb"
|
||||||
@ -56,12 +56,12 @@ class Sandbox
|
|||||||
end
|
end
|
||||||
|
|
||||||
def allow_cvs
|
def allow_cvs
|
||||||
allow_write_path "#{Dir.home(ENV["USER"])}/.cvspass"
|
allow_write_path "#{Dir.home(ENV.fetch("USER"))}/.cvspass"
|
||||||
end
|
end
|
||||||
|
|
||||||
def allow_fossil
|
def allow_fossil
|
||||||
allow_write_path "#{Dir.home(ENV["USER"])}/.fossil"
|
allow_write_path "#{Dir.home(ENV.fetch("USER"))}/.fossil"
|
||||||
allow_write_path "#{Dir.home(ENV["USER"])}/.fossil-journal"
|
allow_write_path "#{Dir.home(ENV.fetch("USER"))}/.fossil-journal"
|
||||||
end
|
end
|
||||||
|
|
||||||
def allow_write_cellar(formula)
|
def allow_write_cellar(formula)
|
||||||
@ -72,7 +72,7 @@ class Sandbox
|
|||||||
|
|
||||||
# Xcode projects expect access to certain cache/archive dirs.
|
# Xcode projects expect access to certain cache/archive dirs.
|
||||||
def allow_write_xcode
|
def allow_write_xcode
|
||||||
allow_write_path "#{Dir.home(ENV["USER"])}/Library/Developer"
|
allow_write_path "#{Dir.home(ENV.fetch("USER"))}/Library/Developer"
|
||||||
end
|
end
|
||||||
|
|
||||||
def allow_write_log(formula)
|
def allow_write_log(formula)
|
||||||
@ -94,40 +94,43 @@ class Sandbox
|
|||||||
seatbelt.write(@profile.dump)
|
seatbelt.write(@profile.dump)
|
||||||
seatbelt.close
|
seatbelt.close
|
||||||
@start = Time.now
|
@start = Time.now
|
||||||
safe_system SANDBOX_EXEC, "-f", seatbelt.path, *args
|
|
||||||
rescue
|
|
||||||
@failed = true
|
|
||||||
raise
|
|
||||||
ensure
|
|
||||||
seatbelt.unlink
|
|
||||||
sleep 0.1 # wait for a bit to let syslog catch up the latest events.
|
|
||||||
syslog_args = %W[
|
|
||||||
-F $((Time)(local))\ $(Sender)[$(PID)]:\ $(Message)
|
|
||||||
-k Time ge #{@start.to_i}
|
|
||||||
-k Message S deny
|
|
||||||
-k Sender kernel
|
|
||||||
-o
|
|
||||||
-k Time ge #{@start.to_i}
|
|
||||||
-k Message S deny
|
|
||||||
-k Sender sandboxd
|
|
||||||
]
|
|
||||||
logs = Utils.popen_read("syslog", *syslog_args)
|
|
||||||
|
|
||||||
# These messages are confusing and non-fatal, so don't report them.
|
begin
|
||||||
logs = logs.lines.reject { |l| l.match(/^.*Python\(\d+\) deny file-write.*pyc$/) }.join
|
T.unsafe(self).safe_system SANDBOX_EXEC, "-f", seatbelt.path, *args
|
||||||
|
rescue
|
||||||
|
@failed = true
|
||||||
|
raise
|
||||||
|
ensure
|
||||||
|
seatbelt.unlink
|
||||||
|
sleep 0.1 # wait for a bit to let syslog catch up the latest events.
|
||||||
|
syslog_args = %W[
|
||||||
|
-F $((Time)(local))\ $(Sender)[$(PID)]:\ $(Message)
|
||||||
|
-k Time ge #{@start.to_i}
|
||||||
|
-k Message S deny
|
||||||
|
-k Sender kernel
|
||||||
|
-o
|
||||||
|
-k Time ge #{@start.to_i}
|
||||||
|
-k Message S deny
|
||||||
|
-k Sender sandboxd
|
||||||
|
]
|
||||||
|
logs = Utils.popen_read("syslog", *syslog_args)
|
||||||
|
|
||||||
unless logs.empty?
|
# These messages are confusing and non-fatal, so don't report them.
|
||||||
if @logfile
|
logs = logs.lines.reject { |l| l.match(/^.*Python\(\d+\) deny file-write.*pyc$/) }.join
|
||||||
File.open(@logfile, "w") do |log|
|
|
||||||
log.write logs
|
unless logs.empty?
|
||||||
log.write "\nWe use time to filter sandbox log. Therefore, unrelated logs may be recorded.\n"
|
if @logfile
|
||||||
|
File.open(@logfile, "w") do |log|
|
||||||
|
log.write logs
|
||||||
|
log.write "\nWe use time to filter sandbox log. Therefore, unrelated logs may be recorded.\n"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
if @failed && Homebrew::EnvConfig.verbose?
|
if @failed && Homebrew::EnvConfig.verbose?
|
||||||
ohai "Sandbox log"
|
ohai "Sandbox log"
|
||||||
puts logs
|
puts logs
|
||||||
$stdout.flush # without it, brew test-bot would fail to catch the log
|
$stdout.flush # without it, brew test-bot would fail to catch the log
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user