From 4ce6616f2eff36afb7ed3effc35f7ee0c108e266 Mon Sep 17 00:00:00 2001 From: Trevor Powell Date: Sun, 22 Jan 2017 22:52:11 -0600 Subject: [PATCH 1/2] Fix "Failed to eject" errors with DMGs Use "diskutil unmount force" to unmount DMGs. --- Library/Homebrew/cask/lib/hbc/container/dmg.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/container/dmg.rb b/Library/Homebrew/cask/lib/hbc/container/dmg.rb index 987455ad72..49543844aa 100644 --- a/Library/Homebrew/cask/lib/hbc/container/dmg.rb +++ b/Library/Homebrew/cask/lib/hbc/container/dmg.rb @@ -45,10 +45,10 @@ module Hbc begin tries ||= 2 @command.run("/usr/sbin/diskutil", - args: ["eject", mountpath], + args: ["unmount", "force", mountpath], print_stderr: false) - raise CaskError, "Failed to eject #{mountpath}" if mountpath.exist? + raise CaskError, "Failed to unmount #{mountpath}" if mountpath.exist? rescue CaskError => e raise e if (tries -= 1).zero? sleep 1 From e11b8b68cdf2b021dce4a11c40afddc306dab7d4 Mon Sep 17 00:00:00 2001 From: Trevor Powell Date: Mon, 30 Jan 2017 22:31:09 -0600 Subject: [PATCH 2/2] Update dmg.rb based on feedback Try "diskutil eject" twice before "diskutil unmount force". --- Library/Homebrew/cask/lib/hbc/container/dmg.rb | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/container/dmg.rb b/Library/Homebrew/cask/lib/hbc/container/dmg.rb index 49543844aa..815f8f0102 100644 --- a/Library/Homebrew/cask/lib/hbc/container/dmg.rb +++ b/Library/Homebrew/cask/lib/hbc/container/dmg.rb @@ -43,12 +43,17 @@ module Hbc next unless mountpath.exist? begin - tries ||= 2 - @command.run("/usr/sbin/diskutil", - args: ["unmount", "force", mountpath], - print_stderr: false) - - raise CaskError, "Failed to unmount #{mountpath}" if mountpath.exist? + tries ||= 3 + if tries > 1 + @command.run("/usr/sbin/diskutil", + args: ["eject", mountpath], + print_stderr: false) + else + @command.run("/usr/sbin/diskutil", + args: ["unmount", "force", mountpath], + print_stderr: false) + end + raise CaskError, "Failed to eject #{mountpath}" if mountpath.exist? rescue CaskError => e raise e if (tries -= 1).zero? sleep 1