Skip to content
This repository was archived by the owner on Aug 27, 2022. It is now read-only.
/ lanai Public archive

Commit fb8ea97

Browse files
author
Alexander Matveev
committedAug 5, 2020
8250646: hdiutil detach fix JDK-8245311 still fails sometimes
Reviewed-by: herrick, asemenyuk
1 parent 96fdc0e commit fb8ea97

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed
 

‎src/jdk.incubator.jpackage/macosx/classes/jdk/incubator/jpackage/internal/MacDmgBundler.java

+16-3
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,22 @@ private Path buildDMG( Map<String, ? super Object> params,
446446
// "hdiutil detach" might not work right away due to resource busy error, so
447447
// repeat detach several times.
448448
RetryExecutor retryExecutor = new RetryExecutor();
449-
// 10 times with 3 second delays.
450-
retryExecutor.setMaxAttemptsCount(10).setAttemptTimeoutMillis(3000)
451-
.execute(pb);
449+
// Image can get detach even if we got resource busy error, so stop
450+
// trying to detach it if it is no longer attached.
451+
retryExecutor.setExecutorInitializer(exec -> {
452+
if (!Files.exists(mountedRoot)) {
453+
retryExecutor.abort();
454+
}
455+
});
456+
try {
457+
// 10 times with 3 second delays.
458+
retryExecutor.setMaxAttemptsCount(10).setAttemptTimeoutMillis(3000)
459+
.execute(pb);
460+
} catch (IOException ex) {
461+
if (!retryExecutor.isAborted()) {
462+
throw ex;
463+
}
464+
}
452465
}
453466

454467
// Compress it to a new image

‎src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/RetryExecutor.java

+8
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ void abort() {
5353
aborted = true;
5454
}
5555

56+
boolean isAborted() {
57+
return aborted;
58+
}
59+
5660
static RetryExecutor retryOnKnownErrorMessage(String v) {
5761
RetryExecutor result = new RetryExecutor();
5862
return result.setExecutorInitializer(exec -> {
@@ -75,6 +79,10 @@ void execute(ProcessBuilder pb) throws IOException {
7579
private void executeLoop(Supplier<Executor> execSupplier) throws IOException {
7680
aborted = false;
7781
for (;;) {
82+
if (aborted) {
83+
break;
84+
}
85+
7886
try {
7987
Executor exec = execSupplier.get();
8088
if (executorInitializer != null) {

0 commit comments

Comments
 (0)