2018-08-01 07:41:52 +02:00
|
|
|
module UnpackStrategy
|
|
|
|
class Zip
|
2018-08-06 22:59:02 +02:00
|
|
|
prepend Module.new {
|
|
|
|
def extract_to_dir(unpack_dir, basename:, verbose:)
|
2019-04-09 21:45:35 +00:00
|
|
|
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
|
|
|
|
|
2019-03-29 21:06:39 +01:00
|
|
|
result = begin
|
|
|
|
super
|
|
|
|
rescue ErrorDuringExecution => e
|
|
|
|
raise unless e.stderr.include?("End-of-central-directory signature not found.")
|
|
|
|
|
|
|
|
system_command! "ditto",
|
|
|
|
args: ["-x", "-k", path, unpack_dir],
|
|
|
|
verbose: verbose
|
|
|
|
return
|
|
|
|
end
|
2018-10-08 09:44:03 +00:00
|
|
|
|
|
|
|
volumes = result.stderr.chomp
|
|
|
|
.split("\n")
|
|
|
|
.map { |l| l[/\A skipping: (.+) volume label\Z/, 1] }
|
|
|
|
.compact
|
|
|
|
|
2018-08-06 22:59:02 +02:00
|
|
|
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",
|
2018-11-02 17:18:07 +00:00
|
|
|
args: ["-x", "-k", path, tmp_unpack_dir],
|
2018-08-06 22:59:02 +02:00
|
|
|
verbose: verbose
|
|
|
|
|
|
|
|
volumes.each do |volume|
|
|
|
|
FileUtils.mv tmp_unpack_dir/volume, unpack_dir/volume, verbose: verbose
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
}
|
2018-08-01 07:41:52 +02:00
|
|
|
end
|
|
|
|
end
|