From a182676d3a67b36b5429b524cd1bc9874ff2b74d Mon Sep 17 00:00:00 2001 From: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Date: Wed, 14 Jan 2026 15:26:17 +0000 Subject: [PATCH] fix auto delete dont use try --- .../api/converters/ConvertOfficeController.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/app/core/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertOfficeController.java b/app/core/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertOfficeController.java index ad8501efe8..ab90d5d728 100644 --- a/app/core/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertOfficeController.java +++ b/app/core/src/main/java/stirling/software/SPDF/controller/api/converters/ConvertOfficeController.java @@ -71,12 +71,12 @@ public class ConvertOfficeController { } String extensionLower = extension.toLowerCase(Locale.ROOT); - // Use try-with-resources for automatic cleanup of work directory - try (TempDirectory workDirManager = new TempDirectory(tempFileManager)) { - Path workDir = workDirManager.getPath(); - Path inputPath = Files.createTempFile(workDir, "input_", "." + extensionLower); - Path outputPath = Files.createTempFile(workDir, "output_", ".pdf"); + // Create work directory - caller (processFileToPDF) is responsible for cleanup + Path workDir = Files.createTempDirectory("office2pdf_"); + Path inputPath = Files.createTempFile(workDir, "input_", "." + extensionLower); + Path outputPath = Files.createTempFile(workDir, "output_", ".pdf"); + try { // Check if the file is HTML and apply sanitization if needed if ("html".equals(extensionLower) || "htm".equals(extensionLower)) { // Read and sanitize HTML content @@ -161,6 +161,13 @@ public class ConvertOfficeController { } return outputPath.toFile(); + } finally { + // Clean up the temporary input file (output and workDir cleaned by caller) + try { + Files.deleteIfExists(inputPath); + } catch (IOException e) { + log.warn("Failed to delete temp input file: {}", inputPath, e); + } } }