Merge pull request #10958 from cho-m/cask-eject-apfs-dmg

cask install: fix APFS DMG eject to use physical disk
This commit is contained in:
Markus Reiter 2021-04-03 20:38:12 +02:00 committed by GitHub
commit 051d4378b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 5 deletions

View File

@ -16,7 +16,7 @@ describe Cask::Installer, :cask do
expect(caffeine.config.appdir.join("Caffeine.app")).to be_a_directory
end
it "works with dmg-based Casks" do
it "works with HFS+ dmg-based Casks" do
asset = Cask::CaskLoader.load(cask_path("container-dmg"))
described_class.new(asset).install
@ -25,6 +25,24 @@ describe Cask::Installer, :cask do
expect(asset.config.appdir.join("container")).to be_a_file
end
it "works with APFS dmg-based Casks" do
asset = Cask::CaskLoader.load(cask_path("container-apfs-dmg"))
diskutil_list_command = "diskutil list | grep '/dev'"
sleep 5
original_diskutil_list = `#{diskutil_list_command}`
described_class.new(asset).install
expect(Cask::Caskroom.path.join("container-apfs-dmg", asset.version)).to be_a_directory
expect(asset.config.appdir.join("container")).to be_a_file
sleep 5
expect { system diskutil_list_command }
.to output(original_diskutil_list)
.to_stdout_from_any_process
end
it "works with tar-gz-based Casks" do
asset = Cask::CaskLoader.load(cask_path("container-tar-gz"))

View File

@ -0,0 +1,9 @@
cask "container-apfs-dmg" do
version "1.2.3"
sha256 "0630aa1145e8c3fa77aeb6ec414fee35204e90f224d6d06cb23e18a4d6112a5d"
url "file://#{TEST_FIXTURE_DIR}/cask/container-apfs.dmg"
homepage "https://brew.sh/container-apfs-dmg"
app "container"
end

View File

@ -87,10 +87,27 @@ module UnpackStrategy
return unless path.exist?
if tries > 1
system_command! "diskutil",
args: ["eject", path],
print_stderr: false,
verbose: verbose
disk_info = system_command!(
"diskutil",
args: ["info", "-plist", path],
print_stderr: false,
verbose: verbose,
)
# For HFS, just use <mount-path>
# For APFS, find the <physical-store> corresponding to <mount-path>
eject_paths = disk_info.plist
.fetch("APFSPhysicalStores", [])
.map { |store| store["APFSPhysicalStore"] }
.compact
.presence || [path]
eject_paths.each do |eject_path|
system_command! "diskutil",
args: ["eject", eject_path],
print_stderr: false,
verbose: verbose
end
else
system_command! "diskutil",
args: ["unmount", "force", path],