fix: Retry cleanup again on system exit
This commit is contained in:
parent
8ef6234bc5
commit
8cd8963bca
1 changed files with 9 additions and 1 deletions
|
@ -41,12 +41,20 @@ public class OpenSSLCertificateResult implements CertificateUsage {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
|
cleanupDir(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cleanupDir(boolean retryOnExit) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
log.info("Cleaning up temporary output directory {}", tmpDir);
|
log.info("Cleaning up temporary output directory {}", tmpDir);
|
||||||
Files.walkFileTree(tmpDir, Set.of(), Integer.MAX_VALUE, new DeleteRecursiveFileVisitor());
|
Files.walkFileTree(tmpDir, Set.of(), Integer.MAX_VALUE, new DeleteRecursiveFileVisitor());
|
||||||
Files.deleteIfExists(tmpDir);
|
Files.deleteIfExists(tmpDir);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("Failed to clean up temporary output directory {}!", tmpDir, e);
|
log.error("Failed to clean up temporary output directory {}! (retry={})", tmpDir, retryOnExit, e);
|
||||||
|
if (retryOnExit) {
|
||||||
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> cleanupDir(false)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue