unpack_strategy/zip: ensure consistent timezone management
This commit is contained in:
parent
94ce3236a5
commit
7ee76b85d5
@ -15,47 +15,49 @@ module UnpackStrategy
|
|||||||
|
|
||||||
sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) }
|
sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) }
|
||||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||||
if merge_xattrs && contains_extended_attributes?(path)
|
with_env(TZ: "UTC") do
|
||||||
# We use ditto directly, because dot_clean has issues if the __MACOSX
|
if merge_xattrs && contains_extended_attributes?(path)
|
||||||
# folder has incorrect permissions.
|
# We use ditto directly, because dot_clean has issues if the __MACOSX
|
||||||
# (Also, Homebrew's ZIP artifact automatically deletes this folder.)
|
# folder has incorrect permissions.
|
||||||
return system_command! "ditto",
|
# (Also, Homebrew's ZIP artifact automatically deletes this folder.)
|
||||||
args: ["-x", "-k", path, unpack_dir],
|
return system_command! "ditto",
|
||||||
verbose: verbose,
|
args: ["-x", "-k", path, unpack_dir],
|
||||||
print_stderr: false
|
verbose: verbose,
|
||||||
end
|
print_stderr: false
|
||||||
|
end
|
||||||
|
|
||||||
result = begin
|
result = begin
|
||||||
T.let(super, T.nilable(SystemCommand::Result))
|
T.let(super, T.nilable(SystemCommand::Result))
|
||||||
rescue ErrorDuringExecution => e
|
rescue ErrorDuringExecution => e
|
||||||
raise unless e.stderr.include?("End-of-central-directory signature not found.")
|
raise unless e.stderr.include?("End-of-central-directory signature not found.")
|
||||||
|
|
||||||
system_command! "ditto",
|
system_command! "ditto",
|
||||||
args: ["-x", "-k", path, unpack_dir],
|
args: ["-x", "-k", path, unpack_dir],
|
||||||
verbose: verbose
|
verbose: verbose
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
return if result.blank?
|
return if result.blank?
|
||||||
|
|
||||||
volumes = result.stderr.chomp
|
volumes = result.stderr.chomp
|
||||||
.split("\n")
|
.split("\n")
|
||||||
.map { |l| l[/\A skipping: (.+) volume label\Z/, 1] }
|
.map { |l| l[/\A skipping: (.+) volume label\Z/, 1] }
|
||||||
.compact
|
.compact
|
||||||
|
|
||||||
return if volumes.empty?
|
return if volumes.empty?
|
||||||
|
|
||||||
Dir.mktmpdir do |tmp_unpack_dir|
|
Dir.mktmpdir do |tmp_unpack_dir|
|
||||||
tmp_unpack_dir = Pathname(tmp_unpack_dir)
|
tmp_unpack_dir = Pathname(tmp_unpack_dir)
|
||||||
|
|
||||||
# `ditto` keeps Finder attributes intact and does not skip volume labels
|
# `ditto` keeps Finder attributes intact and does not skip volume labels
|
||||||
# like `unzip` does, which can prevent disk images from being unzipped.
|
# like `unzip` does, which can prevent disk images from being unzipped.
|
||||||
system_command! "ditto",
|
system_command! "ditto",
|
||||||
args: ["-x", "-k", path, tmp_unpack_dir],
|
args: ["-x", "-k", path, tmp_unpack_dir],
|
||||||
verbose: verbose
|
verbose: verbose
|
||||||
|
|
||||||
volumes.each do |volume|
|
volumes.each do |volume|
|
||||||
FileUtils.mv tmp_unpack_dir/volume, unpack_dir/volume, verbose: verbose
|
FileUtils.mv tmp_unpack_dir/volume, unpack_dir/volume, verbose: verbose
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -27,15 +27,17 @@ module UnpackStrategy
|
|||||||
.returns(SystemCommand::Result)
|
.returns(SystemCommand::Result)
|
||||||
}
|
}
|
||||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||||
quiet_flags = verbose ? [] : ["-qq"]
|
with_env(TZ: "UTC") do
|
||||||
result = system_command! "unzip",
|
quiet_flags = verbose ? [] : ["-qq"]
|
||||||
args: [*quiet_flags, "-o", path, "-d", unpack_dir],
|
result = system_command! "unzip",
|
||||||
verbose: verbose,
|
args: [*quiet_flags, "-o", path, "-d", unpack_dir],
|
||||||
print_stderr: false
|
verbose: verbose,
|
||||||
|
print_stderr: false
|
||||||
|
|
||||||
FileUtils.rm_rf unpack_dir/"__MACOSX"
|
FileUtils.rm_rf unpack_dir/"__MACOSX"
|
||||||
|
|
||||||
result
|
result
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user