From a9dc8d9cb38d7db633aa62f28a9f17c5c76fa96b Mon Sep 17 00:00:00 2001 From: ZacharyZcR Date: Thu, 25 Sep 2025 08:05:42 +0800 Subject: [PATCH] FIX: Implement proper 404 error handling for missing files in SSH file size check - Fix case-sensitive string matching for "no such file or directory" errors - Return 404 status with fileNotFound flag when files don't exist - Enable automatic cleanup of deleted files from recent/pinned lists - Improve error detection in file size check phase before file reading --- src/backend/ssh/file-manager.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/backend/ssh/file-manager.ts b/src/backend/ssh/file-manager.ts index 7ccc7ac8..13a9dd1f 100644 --- a/src/backend/ssh/file-manager.ts +++ b/src/backend/ssh/file-manager.ts @@ -569,10 +569,20 @@ app.get("/ssh/file_manager/ssh/readFile", (req, res) => { sizeStream.on("close", (sizeCode) => { if (sizeCode !== 0) { + // Check if it's a file not found error (case-insensitive) + const errorLower = sizeErrorData.toLowerCase(); + const isFileNotFound = errorLower.includes("no such file or directory") || + errorLower.includes("cannot access") || + errorLower.includes("not found") || + errorLower.includes("resource not found"); + fileLogger.error(`File size check failed: ${sizeErrorData}`); return res - .status(500) - .json({ error: `Cannot check file size: ${sizeErrorData}` }); + .status(isFileNotFound ? 404 : 500) + .json({ + error: `Cannot check file size: ${sizeErrorData}`, + fileNotFound: isFileNotFound + }); } const fileSize = parseInt(sizeData.trim(), 10);