fix: Retry cleanup again on system exit

This commit is contained in:
Magnus Leßmann (@MarkL4YG) 2024-11-23 13:16:44 +01:00
parent 8ef6234bc5
commit 8cd8963bca

View file

@ -41,12 +41,20 @@ public class OpenSSLCertificateResult implements CertificateUsage {
@Override
public void close() {
cleanupDir(true);
}
private void cleanupDir(boolean retryOnExit) {
try {
log.info("Cleaning up temporary output directory {}", tmpDir);
Files.walkFileTree(tmpDir, Set.of(), Integer.MAX_VALUE, new DeleteRecursiveFileVisitor());
Files.deleteIfExists(tmpDir);
} 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)));
}
}
}
}