From 123dda09f0a96cb2d16ef2b1848a8232d68a5508 Mon Sep 17 00:00:00 2001 From: "L. E. Segovia" <13498015+amyspark@users.noreply.github.com> Date: Fri, 14 Sep 2018 15:48:16 +0000 Subject: [PATCH] Cask: constrain quarantine support status Quarantine is available ONLY if the script exits with '2'. It is definitely NOT available if Swift doesn't exist or if it exits with '5' (incompatible SDK). All other cases are from now on treated as unsupported. Also print to standard error only when explictly required (via an exception). --- Library/Homebrew/cask/cmd/doctor.rb | 4 +-- Library/Homebrew/cask/quarantine.rb | 53 ++++++++++++++++------------- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/Library/Homebrew/cask/cmd/doctor.rb b/Library/Homebrew/cask/cmd/doctor.rb index edd1ac9e77..459da9fcf5 100644 --- a/Library/Homebrew/cask/cmd/doctor.rb +++ b/Library/Homebrew/cask/cmd/doctor.rb @@ -120,9 +120,7 @@ module Cask def check_quarantine_support ohai "Gatekeeper support" - status = Quarantine.check_quarantine_support - - case status + case Quarantine.check_quarantine_support when :quarantine_available puts "Enabled" when :no_swift diff --git a/Library/Homebrew/cask/quarantine.rb b/Library/Homebrew/cask/quarantine.rb index 1e65cc2195..15d689aa46 100644 --- a/Library/Homebrew/cask/quarantine.rb +++ b/Library/Homebrew/cask/quarantine.rb @@ -17,18 +17,24 @@ module Cask if swift.nil? odebug "Swift is not available on this system." - return :no_swift + :no_swift + else + api_check = system_command(swift, + args: [QUARANTINE_SCRIPT], + print_stderr: false) + + case api_check.exit_status + when 5 + odebug "This feature requires the macOS 10.10 SDK or higher." + :no_quarantine + when 2 + odebug "Quarantine is available." + :quarantine_available + else + odebug "Unknown support status" + :unknown + end end - - api_check = system_command(swift, args: [QUARANTINE_SCRIPT]) - - if api_check.exit_status == 5 - odebug "This feature requires the macOS 10.10 SDK or higher." - return :no_quarantine - end - - odebug "Quarantine is available." - :quarantine_available end def available? @@ -73,12 +79,12 @@ module Cask odebug "Releasing #{download_path} from quarantine" quarantiner = system_command("/usr/bin/xattr", - args: [ - "-d", - QUARANTINE_ATTRIBUTE, - download_path, - ], - print_stderr: false) + args: [ + "-d", + QUARANTINE_ATTRIBUTE, + download_path, + ], + print_stderr: false) return if quarantiner.success? @@ -93,12 +99,13 @@ module Cask odebug "Quarantining #{download_path}" quarantiner = system_command(swift, - args: [ - QUARANTINE_SCRIPT, - download_path, - cask.url.to_s, - cask.homepage.to_s, - ]) + args: [ + QUARANTINE_SCRIPT, + download_path, + cask.url.to_s, + cask.homepage.to_s, + ], + print_stderr: false) return if quarantiner.success?