Merge pull request #4990 from amyspark/check-xattr

Cask: check if xattr works before quarantining
This commit is contained in:
JCount 2018-09-29 12:58:14 -04:00 committed by GitHub
commit ac801d4d63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 6 deletions

View File

@ -124,6 +124,8 @@ module Cask
case Quarantine.check_quarantine_support case Quarantine.check_quarantine_support
when :quarantine_available when :quarantine_available
puts "Enabled" puts "Enabled"
when :xattr_broken
add_error "There's not a working version of xattr."
when :no_swift when :no_swift
add_error "Swift is not available on this system." add_error "Swift is not available on this system."
when :no_quarantine when :no_quarantine

View File

@ -12,10 +12,18 @@ module Cask
@swift ||= DevelopmentTools.locate("swift") @swift ||= DevelopmentTools.locate("swift")
end end
# @private
def xattr
@xattr ||= DevelopmentTools.locate("xattr")
end
def check_quarantine_support def check_quarantine_support
odebug "Checking 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." odebug "Swift is not available on this system."
:no_swift :no_swift
else else
@ -56,13 +64,13 @@ module Cask
end end
def status(file) def status(file)
system_command("/usr/bin/xattr", system_command(xattr,
args: ["-p", QUARANTINE_ATTRIBUTE, file], args: ["-p", QUARANTINE_ATTRIBUTE, file],
print_stderr: false).stdout.rstrip print_stderr: false).stdout.rstrip
end end
def toggle_no_translocation_bit(xattr) def toggle_no_translocation_bit(attribute)
fields = xattr.split(";") fields = attribute.split(";")
# Fields: status, epoch, download agent, event ID # Fields: status, epoch, download agent, event ID
# Let's toggle the app translocation bit, bit 8 # Let's toggle the app translocation bit, bit 8
@ -78,7 +86,7 @@ module Cask
odebug "Releasing #{download_path} from quarantine" odebug "Releasing #{download_path} from quarantine"
quarantiner = system_command("/usr/bin/xattr", quarantiner = system_command(xattr,
args: [ args: [
"-d", "-d",
QUARANTINE_ATTRIBUTE, QUARANTINE_ATTRIBUTE,
@ -134,7 +142,7 @@ module Cask
args: [ args: [
"-0", "-0",
"--", "--",
"/usr/bin/xattr", xattr,
"-w", "-w",
"-s", "-s",
QUARANTINE_ATTRIBUTE, QUARANTINE_ATTRIBUTE,