fix(snapshot): handle permission-denied files in workspace snapshot init#1907
fix(snapshot): handle permission-denied files in workspace snapshot init#1907
Conversation
When creating a working tree snapshot, `git add .` fails entirely if any file in the workspace is locked or permission-denied (common on Windows with open Office files). Add --ignore-errors flag so git continues indexing other files, and catch the non-zero exit for known indexing failures. Fixes ELECTRON-G6
Code Review:fix(snapshot): handle permission-denied files in workspace snapshot init (#1907)变更概述本 PR 修复了 Sentry 问题 ELECTRON-G6: 方案评估结论:✅ 方案合理
问题清单🔵 LOW — 错误字符串匹配存在潜在脆弱性文件: 问题代码: if (!stderr.includes('Permission denied') && !stderr.includes('unable to index file')) {
throw error;
}问题说明:通过字符串匹配 stderr 来判断错误类型存在边界情况:
这是 LOW 而非 HIGH,因为:实践中绝大多数 Windows git 安装均为英文版,且错误已涵盖 改善建议(可选,不阻塞合并): // 更宽松地检查:只要是部分索引失败(git 本身运行成功),就不 re-throw
// git add --ignore-errors 失败时 exit code 为 1-2;git not found 为 127
const exitCode = (error as { status?: number }).status ?? -1;
if (exitCode !== 1 && exitCode !== 2) {
throw error;
}🔵 LOW — Windows 平台上测试无法实际覆盖修复路径文件: 问题代码: await fs.chmod(unreadablePath, 0o000);问题说明: 改善建议(可选): it('init succeeds when a file is not readable (permission denied)', async () => {
// chmod(0o000) only prevents file access on Unix; skip on Windows
if (process.platform === 'win32') return;
// ... rest of test
});汇总
结论✅ 批准合并 — 两个问题均为 LOW,不阻塞合并;核心修复逻辑正确,单元测试覆盖了 Unix 平台的主要场景。 本报告由本地 CONCLUSION: APPROVED |
|
✅ 已自动 review,无阻塞性问题,正在触发自动合并。 |
Summary
WorkspaceSnapshotService.createWorkingTreeSnapshotrunsgit add .which fails entirely when any file in the workspace has permission denied (e.g., open Office files on Windows). Added--ignore-errorsflag so git continues indexing other files, and catch the non-zero exit for known indexing failures.initsucceeds when a file is not readable.Test plan
init succeeds when a file is not readable (permission denied)— passesbunx tsc --noEmit)