8373105: Test tools/jpackage/share/AsyncTest.java failed: problem running hdiutil

Reviewed-by: asemenyuk
Backport-of: 2d0928406027a848cf2d2d0574024970b8fb535c
This commit is contained in:
Alexander Matveev 2026-01-14 23:35:49 +00:00
parent 9f78c71f88
commit f4ddafcd70

View File

@ -81,12 +81,18 @@ public final class MacHelper {
ThrowingConsumer<Path> consumer) {
cmd.verifyIsOfType(PackageType.MAC_DMG);
// Mount DMG under random temporary folder to avoid collisions when
// mounting DMG with same name asynchroniusly multiple times.
// See JDK-8373105. "hdiutil" does not handle such cases very good.
final var mountRoot = TKit.createTempDirectory("mountRoot");
// Explode DMG assuming this can require interaction, thus use `yes`.
String attachCMD[] = {
"sh", "-c",
String.join(" ", "yes", "|", "/usr/bin/hdiutil", "attach",
JPackageCommand.escapeAndJoin(
cmd.outputBundle().toString()), "-plist")};
JPackageCommand.escapeAndJoin(cmd.outputBundle().toString()),
"-mountroot", PathUtils.normalizedAbsolutePathString(mountRoot),
"-nobrowse", "-plist")};
RetryExecutor attachExecutor = new RetryExecutor();
try {
// 10 times with 6 second delays.