From c6894a23c14902f7efa9bf1dacd7cd0db90e2dda Mon Sep 17 00:00:00 2001 From: "L. E. Segovia" <13498015+amyspark@users.noreply.github.com> Date: Tue, 9 Apr 2019 21:45:35 +0000 Subject: [PATCH] Only merge extended attributes if required --- Library/Homebrew/cask/installer.rb | 4 ++-- .../extend/os/mac/unpack_strategy/zip.rb | 22 +++++++++---------- Library/Homebrew/unpack_strategy.rb | 9 ++++---- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/Library/Homebrew/cask/installer.rb b/Library/Homebrew/cask/installer.rb index 2631717a2c..2d80d45ba8 100644 --- a/Library/Homebrew/cask/installer.rb +++ b/Library/Homebrew/cask/installer.rb @@ -161,7 +161,7 @@ module Cask def primary_container @primary_container ||= begin - UnpackStrategy.detect(@downloaded_path, type: @cask.container&.type) + UnpackStrategy.detect(@downloaded_path, type: @cask.container&.type, merge_xattrs: true) end end @@ -179,7 +179,7 @@ module Cask FileUtils.chmod_R "+rw", tmpdir/nested_container, force: true, verbose: verbose? - UnpackStrategy.detect(tmpdir/nested_container) + UnpackStrategy.detect(tmpdir/nested_container, merge_xattrs: true) .extract_nestedly(to: @cask.staged_path, verbose: verbose?) end else diff --git a/Library/Homebrew/extend/os/mac/unpack_strategy/zip.rb b/Library/Homebrew/extend/os/mac/unpack_strategy/zip.rb index 32847afdea..6f0dc90a38 100644 --- a/Library/Homebrew/extend/os/mac/unpack_strategy/zip.rb +++ b/Library/Homebrew/extend/os/mac/unpack_strategy/zip.rb @@ -2,6 +2,16 @@ module UnpackStrategy class Zip prepend Module.new { def extract_to_dir(unpack_dir, basename:, verbose:) + if merge_xattrs && contains_extended_attributes?(path) + # We use ditto directly, because dot_clean has issues if the __MACOSX + # folder has incorrect permissions. + # (Also, Homebrew's ZIP artifact automatically deletes this folder.) + return system_command! "ditto", + args: ["-x", "-k", path, unpack_dir], + verbose: verbose, + print_stderr: false + end + result = begin super rescue ErrorDuringExecution => e @@ -13,18 +23,6 @@ module UnpackStrategy return end - if contains_extended_attributes?(path) - # Merge ._ files back into extended attributes. - # We use ditto, because dot_clean has issues if the __MACOSX - # folder has incorrect permissions. - # (Also, Homebrew's ZIP artifact automatically deletes this folder.) - system_command! "ditto", - args: ["-x", "-k", path, unpack_dir], - verbose: verbose, - print_stderr: false - return - end - volumes = result.stderr.chomp .split("\n") .map { |l| l[/\A skipping: (.+) volume label\Z/, 1] } diff --git a/Library/Homebrew/unpack_strategy.rb b/Library/Homebrew/unpack_strategy.rb index 0617eed0a6..26c61e1569 100644 --- a/Library/Homebrew/unpack_strategy.rb +++ b/Library/Homebrew/unpack_strategy.rb @@ -88,7 +88,7 @@ module UnpackStrategy strategies.find { |s| s.can_extract?(path) } end - def self.detect(path, prioritise_extension: false, type: nil, ref_type: nil, ref: nil) + def self.detect(path, prioritise_extension: false, type: nil, ref_type: nil, ref: nil, merge_xattrs: nil) strategy = from_type(type) if type if prioritise_extension && path.extname.present? @@ -102,15 +102,16 @@ module UnpackStrategy strategy ||= Uncompressed - strategy.new(path, ref_type: ref_type, ref: ref) + strategy.new(path, ref_type: ref_type, ref: ref, merge_xattrs: merge_xattrs) end - attr_reader :path + attr_reader :path, :merge_xattrs - def initialize(path, ref_type: nil, ref: nil) + def initialize(path, ref_type: nil, ref: nil, merge_xattrs: nil) @path = Pathname(path).expand_path @ref_type = ref_type @ref = ref + @merge_xattrs = merge_xattrs end def extract(to: nil, basename: nil, verbose: false)