From 6d7e49b02b07b35710e2a0bd15fa146c6fa5e0e5 Mon Sep 17 00:00:00 2001 From: "L. E. Segovia" <13498015+amyspark@users.noreply.github.com> Date: Wed, 26 Sep 2018 20:55:54 +0000 Subject: [PATCH] Cask: check if xattr works before quarantining Fixes Homebrew/homebrew-cask#52128. --- Library/Homebrew/cask/cmd/doctor.rb | 2 ++ Library/Homebrew/cask/quarantine.rb | 20 ++++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/cask/cmd/doctor.rb b/Library/Homebrew/cask/cmd/doctor.rb index 7c3095d8df..82e917018b 100644 --- a/Library/Homebrew/cask/cmd/doctor.rb +++ b/Library/Homebrew/cask/cmd/doctor.rb @@ -124,6 +124,8 @@ module Cask case Quarantine.check_quarantine_support when :quarantine_available puts "Enabled" + when :xattr_broken + add_error "There's not a working version of xattr." when :no_swift add_error "Swift is not available on this system." when :no_quarantine diff --git a/Library/Homebrew/cask/quarantine.rb b/Library/Homebrew/cask/quarantine.rb index 15d689aa46..ec9f7c74bf 100644 --- a/Library/Homebrew/cask/quarantine.rb +++ b/Library/Homebrew/cask/quarantine.rb @@ -12,10 +12,18 @@ module Cask @swift ||= DevelopmentTools.locate("swift") end + # @private + def xattr + @xattr ||= DevelopmentTools.locate("xattr") + end + def check_quarantine_support odebug "Checking quarantine support" - if swift.nil? + if !system_command!(xattr).success? + odebug "There's not a working version of xattr." + :xattr_broken + elsif swift.nil? odebug "Swift is not available on this system." :no_swift else @@ -56,13 +64,13 @@ module Cask end def status(file) - system_command("/usr/bin/xattr", + system_command(xattr, args: ["-p", QUARANTINE_ATTRIBUTE, file], print_stderr: false).stdout.rstrip end - def toggle_no_translocation_bit(xattr) - fields = xattr.split(";") + def toggle_no_translocation_bit(attribute) + fields = attribute.split(";") # Fields: status, epoch, download agent, event ID # Let's toggle the app translocation bit, bit 8 @@ -78,7 +86,7 @@ module Cask odebug "Releasing #{download_path} from quarantine" - quarantiner = system_command("/usr/bin/xattr", + quarantiner = system_command(xattr, args: [ "-d", QUARANTINE_ATTRIBUTE, @@ -134,7 +142,7 @@ module Cask args: [ "-0", "--", - "/usr/bin/xattr", + xattr, "-w", "-s", QUARANTINE_ATTRIBUTE,