From 8dc6a8e73acd6f94851ed98a71c9887ca55eb30a Mon Sep 17 00:00:00 2001 From: haelyra <49814733+haelyra@users.noreply.github.com> Date: Thu, 13 Aug 2026 17:30:38 -0400 Subject: [PATCH] fix(uninstall): close quarantined files before removal --- scripts/lib/codex-legacy-sync.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/scripts/lib/codex-legacy-sync.js b/scripts/lib/codex-legacy-sync.js index ac6e7ad2a..f228afb20 100644 --- a/scripts/lib/codex-legacy-sync.js +++ b/scripts/lib/codex-legacy-sync.js @@ -110,6 +110,8 @@ function removeOpenedRegularFile(filePath, opened) { const openedStat = fs.fstatSync(opened.descriptor, { bigint: true }); const quarantinedStat = fs.fstatSync(quarantined.descriptor, { bigint: true }); fs.closeSync(quarantined.descriptor); + fs.closeSync(opened.descriptor); + opened.descriptor = null; if (quarantinedStat.dev !== openedStat.dev || quarantinedStat.ino !== openedStat.ino) { try { fs.linkSync(quarantinePath, filePath); @@ -319,7 +321,7 @@ function rollbackLegacyCodexSync(options) { try { replaceOpenedRegularFile(opened, previousContent, previousMode); } finally { - fs.closeSync(opened.descriptor); + if (opened.descriptor !== null) fs.closeSync(opened.descriptor); } } else { createRegularFileNoFollow(filePath, previousContent, previousMode); @@ -330,12 +332,12 @@ function rollbackLegacyCodexSync(options) { try { removeOpenedRegularFile(filePath, opened); } finally { - fs.closeSync(opened.descriptor); + if (opened.descriptor !== null) fs.closeSync(opened.descriptor); } } restoredPaths.push(filePath); } else { - if (opened) fs.closeSync(opened.descriptor); + if (opened && opened.descriptor !== null) fs.closeSync(opened.descriptor); retainedPaths.push(filePath); } } @@ -537,7 +539,7 @@ function uninstallLegacyCodexSync(options = {}) { ? crypto.createHash('sha256').update(currentContent).digest('hex') === entry.installedSha256 : false; if (!matches) { - fs.closeSync(opened.descriptor); + if (opened.descriptor !== null) fs.closeSync(opened.descriptor); retainedPaths.push(filePath); continue; } @@ -552,13 +554,13 @@ function uninstallLegacyCodexSync(options = {}) { } else if (entry.previousType === 'missing' || entry.previousType === undefined) { removeOpenedRegularFile(filePath, opened); } else { - fs.closeSync(opened.descriptor); + if (opened.descriptor !== null) fs.closeSync(opened.descriptor); retainedPaths.push(filePath); continue; } removedPaths.push(filePath); } - fs.closeSync(opened.descriptor); + if (opened.descriptor !== null) fs.closeSync(opened.descriptor); } if (state.installedHooksPath) {