From 19b92895aaa0c2a84032214c1e8cdb78bad42946 Mon Sep 17 00:00:00 2001 From: Mowdep Date: Mon, 11 May 2026 01:42:09 +0200 Subject: [PATCH] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- packages/core/src/node/fs.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/core/src/node/fs.ts b/packages/core/src/node/fs.ts index 4b41cd7a..194317e4 100644 --- a/packages/core/src/node/fs.ts +++ b/packages/core/src/node/fs.ts @@ -12,15 +12,21 @@ type FileMode = (typeof FILE_MODES)[keyof typeof FILE_MODES]; * correct mode or does not exist. */ export const ensureFileMode = async (filePath: string, mode: FileMode): Promise => { + let stat; try { - const stat = await fs.stat(filePath); - if ((stat.mode & 0o777) !== mode) { - await fs.chmod(filePath, mode); - return true; + stat = await fs.stat(filePath); + } catch (error) { + if ((error as NodeJS.ErrnoException).code === "ENOENT") { + return false; } - } catch { - // File does not exist or cannot be stat'd — nothing to fix. + throw error; } + + if ((stat.mode & 0o777) !== mode) { + await fs.chmod(filePath, mode); + return true; + } + return false; };