From da34d85ddcfcf954c3db947a1d3850e19f2305b0 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Mon, 6 Aug 2018 22:59:02 +0200 Subject: [PATCH] Only use `ditto` to extract skipped volumes. --- .../extend/os/mac/unpack_strategy/zip.rb | 29 +++++++++++++++---- Library/Homebrew/unpack_strategy/zip.rb | 3 +- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/extend/os/mac/unpack_strategy/zip.rb b/Library/Homebrew/extend/os/mac/unpack_strategy/zip.rb index e31d2c3756..c24d2f14a9 100644 --- a/Library/Homebrew/extend/os/mac/unpack_strategy/zip.rb +++ b/Library/Homebrew/extend/os/mac/unpack_strategy/zip.rb @@ -1,9 +1,28 @@ module UnpackStrategy class Zip - def extract_to_dir(unpack_dir, basename:, verbose:) - # `ditto` keeps Finder attributes intact and does not skip volume labels - # like `unzip` does, which can prevent disk images from being unzipped. - system_command! "ditto", args: ["-x", "-k", path, unpack_dir] - end + prepend Module.new { + def extract_to_dir(unpack_dir, basename:, verbose:) + volumes = super.stderr.chomp + .split("\n") + .map { |l| l[/\A skipping: (.+) volume label\Z/, 1] } + .compact + + return if volumes.empty? + + Dir.mktmpdir do |tmp_unpack_dir| + tmp_unpack_dir = Pathname(tmp_unpack_dir) + + # `ditto` keeps Finder attributes intact and does not skip volume labels + # like `unzip` does, which can prevent disk images from being unzipped. + system_command! "ditto", + args: ["-x", "-k", path, tmp_unpack_dir], + verbose: verbose + + volumes.each do |volume| + FileUtils.mv tmp_unpack_dir/volume, unpack_dir/volume, verbose: verbose + end + end + end + } end end diff --git a/Library/Homebrew/unpack_strategy/zip.rb b/Library/Homebrew/unpack_strategy/zip.rb index 53abf291cd..c4785e05af 100644 --- a/Library/Homebrew/unpack_strategy/zip.rb +++ b/Library/Homebrew/unpack_strategy/zip.rb @@ -18,7 +18,8 @@ module UnpackStrategy quiet_flags = verbose ? [] : ["-qq"] system_command! "unzip", args: [*quiet_flags, path, "-d", unpack_dir], - verbose: verbose + verbose: verbose, + print_stderr: false end end end