Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(desktop): use no-clobber link for migration marker publish

Yuewei-LLaa3473aa56ff
diff --git a/.gitignore b/.gitignore
index 7f812f37fe..cbba17ef31 100644
--- a/.gitignore
+++ b/.gitignore
@@ -180,5 +180,9 @@ apps/mobile/e2e/visual-baselines/
# worktree 回收豁免哨兵(会话工具生成,永不入仓)
.worktree-keep
+# 会话工具临时产物(永不入仓)
+tmp/
+github-result-*.json
+
# 内置插件种子已废弃(改走 plugin-store 安装);历史克隆含私有插件与凭证,永不入仓。
apps/desktop/resources/builtin-ghosts/
diff --git a/apps/desktop/src/main/cindy-brain/ghostInstallReceipt.ts b/apps/desktop/src/main/cindy-brain/ghostInstallReceipt.ts
index f90d51a94f..2e4539b878 100644
--- a/apps/desktop/src/main/cindy-brain/ghostInstallReceipt.ts
+++ b/apps/desktop/src/main/cindy-brain/ghostInstallReceipt.ts
@@ -545,7 +545,7 @@ export class GhostInstallReceiptStore {
// caller knows whether to roll it back on receipt write failure.
// EXISTENT: the marker is already in place (concurrent writer or
// surviving marker from a failed rollback) — safe to proceed.
- // ERROR: temp write or rename failed for a reason other than
+ // ERROR: temp write or link/rename failed for a reason other than
// EEXIST — fail the receipt write, do not publish the receipt
// without the per-id migration guard.
if (this.hasMigrationMarker(id)) return false;
@@ -555,7 +555,26 @@ export class GhostInstallReceiptStore {
const temp = path.join(root, `.migrated-${id}-${process.pid}-${crypto.randomBytes(4).toString('hex')}.tmp`);
try {
await fs.promises.writeFile(temp, '', { encoding: 'utf8', flag: 'wx', mode: 0o600 });
- await fs.promises.rename(temp, target);
+ // Publish via hard-link first so the operation is no-clobber:
+ // link fails with EEXIST if a concurrent writer already created
+ // the marker, while rename would silently replace it and claim
+ // ownership. If link is not available (EXDEV, cross-device),
+ // fall back to a pre-rename existence check + rename.
+ try {
+ await fs.promises.link(temp, target);
+ } catch (error) {
+ if ((error as NodeJS.ErrnoException).code === 'EEXIST') {
+ // Concurrent writer already published the marker — safe.
+ return false;
+ }
+ if ((error as NodeJS.ErrnoException).code === 'EXDEV') {
+ // Cross-device: re-check before rename so we don't clobber.
+ if (this.hasMigrationMarker(id)) return false;
+ await fs.promises.rename(temp, target);
+ } else {
+ throw error;
+ }
+ }
return true;
} catch (error) {
if ((error as NodeJS.ErrnoException).code === 'EEXIST') {