From 3e5dc34bbc6c6511effb201fc17fb69dfdf68f7e Mon Sep 17 00:00:00 2001 From: Anthony Stirling <77850077+Frooodle@users.noreply.github.com.> Date: Mon, 23 Jun 2025 23:03:10 +0100 Subject: [PATCH] changes --- .../service/TempFileCleanupService.java | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/common/src/main/java/stirling/software/common/service/TempFileCleanupService.java b/common/src/main/java/stirling/software/common/service/TempFileCleanupService.java index 9b496e90c..78ef79c2a 100644 --- a/common/src/main/java/stirling/software/common/service/TempFileCleanupService.java +++ b/common/src/main/java/stirling/software/common/service/TempFileCleanupService.java @@ -342,31 +342,29 @@ public class TempFileCleanupService { boolean isSystemTempFile = IS_SYSTEM_TEMP_FILE.test(fileName); boolean shouldDelete = isOurTempFile || (containerMode && isSystemTempFile); - // Special case for zero-byte files - these are often corrupted temp files + // Get file info for age checks + long lastModified = 0; + long currentTime = System.currentTimeMillis(); + boolean isEmptyFile = false; + try { + lastModified = Files.getLastModifiedTime(path).toMillis(); + // Special case for zero-byte files - these are often corrupted temp files if (Files.size(path) == 0) { + isEmptyFile = true; // For empty files, use a shorter timeout (5 minutes) - long lastModified = Files.getLastModifiedTime(path).toMillis(); - long currentTime = System.currentTimeMillis(); // Delete empty files older than 5 minutes if ((currentTime - lastModified) > 5 * 60 * 1000) { shouldDelete = true; } } } catch (IOException e) { - log.debug("Could not check file size, skipping: {}", path); + log.debug("Could not check file info, skipping: {}", path); } - // Check file age against maxAgeMillis - if (shouldDelete && maxAgeMillis > 0) { - try { - long lastModified = Files.getLastModifiedTime(path).toMillis(); - long currentTime = System.currentTimeMillis(); - shouldDelete = (currentTime - lastModified) > maxAgeMillis; - } catch (IOException e) { - log.debug("Could not check file age, skipping: {}", path); - shouldDelete = false; - } + // Check file age against maxAgeMillis only if it's not an empty file that we've already decided to delete + if (!isEmptyFile && shouldDelete && maxAgeMillis > 0) { + shouldDelete = (currentTime - lastModified) > maxAgeMillis; } return shouldDelete;