Update GeneralUtils.java

This commit is contained in:
Ludy87 2025-07-19 02:24:15 +02:00
parent d395ce6a4f
commit 8d894f2d73
No known key found for this signature in database
GPG Key ID: 92696155E0220F94

View File

@ -467,18 +467,13 @@ public class GeneralUtils {
// 2. create a temporary directory // 2. create a temporary directory
Path tmpDir = Files.createTempDirectory("stirling-pdf-scripts"); Path tmpDir = Files.createTempDirectory("stirling-pdf-scripts");
Path scriptFile = tmpDir.resolve(scriptName); tmpDir.toFile().deleteOnExit();
// 3. copy the script to the temporary directory
Path scriptFile = tmpDir.resolve(scriptName);
try (InputStream in = resource.getInputStream()) { try (InputStream in = resource.getInputStream()) {
Files.copy(in, scriptFile, StandardCopyOption.REPLACE_EXISTING); Files.copy(in, scriptFile, StandardCopyOption.REPLACE_EXISTING);
return scriptFile; return scriptFile;
} finally {
try {
Files.deleteIfExists(scriptFile);
Files.deleteIfExists(tmpDir);
} catch (IOException e) {
log.warn("Failed to delete temporary files: {}", e.getMessage());
}
} }
} }