Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.io.File;
import java.util.Arrays;
import java.util.Optional;

import org.apache.commons.lang3.StringUtils;

Expand Down Expand Up @@ -99,13 +100,13 @@ protected File doApply(MacPackager packager) throws Exception {
// mounts image
Logger.info("Mounting image: " + tempDmgFile.getAbsolutePath());
String result = execute("hdiutil", "attach", "-readwrite", "-noverify", "-noautoopen", tempDmgFile);
String deviceName = Arrays.asList(result.split("\n"))
.stream()
.filter(s -> s.contains(mountFolder.getAbsolutePath()))
.map(s -> StringUtils.normalizeSpace(s))
.map(s -> s.split(" ")[0])
.findFirst().get();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This call to get() will throw an exception in the case that mounting an image fails.

Logger.info("- Device name: " + deviceName);
Optional<String> optDeviceName = Arrays.asList(result.split("\n"))
.stream()
.filter(s -> s.contains(mountFolder.getAbsolutePath()))
.map(s -> StringUtils.normalizeSpace(s))
.map(s -> s.split(" ")[0])
.findFirst();
optDeviceName.ifPresent(deviceName -> Logger.info("- Device name: " + deviceName));

// pause to prevent occasional "Can't get disk" (-1728) issues
// https://github.com/seltzered/create-dmg/commit/5fe7802917bb85b40c0630b026d33e421db914ea
Expand Down