Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(bots): 只有 link 明确报不支持硬链接时才走 rename 补种回退
Claude8eee5b9e7a14
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/botProfileFolder.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/botProfileFolder.test.tsindex 08234b9808..58eaa67b31 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/botProfileFolder.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/botProfileFolder.test.ts@@ -297,6 +297,23 @@ describe('搬家', () => {expect(leftovers).toEqual([]);});+ it('link 报权限、空间等其他错误时不走 rename 回退,原样抛出,不补种', async () => {+ const link = vi.spyOn(fs, 'link').mockRejectedValue(Object.assign(new Error('ENOSPC'), { code: 'ENOSPC' }));+ const rename = vi.spyOn(fs, 'rename');+ const home = botProfileDir(root, 'bot-a');+ try {+ await expect(migrateBotProfileFolder(root, 'bot-a', SEED)).rejects.toMatchObject({ code: 'ENOSPC' });+ // No replacing rename onto a target path.+ expect(rename).not.toHaveBeenCalled();+ } finally {+ link.mockRestore();+ rename.mockRestore();+ }+ await expect(fs.access(path.join(home, 'SOUL.md'))).rejects.toBeTruthy();+ await expect(fs.access(path.join(home, 'memories', 'USER.md'))).rejects.toBeTruthy();+ expect((await fs.readdir(path.join(home, 'memories'))).filter((name) => name.includes('.tmp-'))).toEqual([]);+ });+it('不支持硬链接且 rename 失败时不留半截目标,下一次补种照常补齐', async () => {const link = vi.spyOn(fs, 'link').mockRejectedValue(Object.assign(new Error('EPERM'), { code: 'EPERM' }));const realRename = fs.rename.bind(fs);diff --git a/apps/desktop/src/main/maker-ipc/botProfileFolder.ts b/apps/desktop/src/main/maker-ipc/botProfileFolder.tsindex 322054202e..e352723e89 100644--- a/apps/desktop/src/main/maker-ipc/botProfileFolder.ts+++ b/apps/desktop/src/main/maker-ipc/botProfileFolder.ts@@ -79,6 +79,11 @@ import path from 'node:path';/** 原子写的临时文件序号,进程内自增 —— 见 writeTextAtomic 里的并发说明。 */let writeSeq = 0;+/**+ * link 报这些错误码表示这个文件系统不支持硬链接:Linux 的 vfat / exFAT 报 EPERM,+ * macOS 与部分网络盘报 ENOTSUP / EOPNOTSUPP,Windows 的 FAT 系列经 libuv 映射为 EISDIR。+ */+const HARD_LINK_UNSUPPORTED_CODES = new Set(['EPERM', 'ENOTSUP', 'EOPNOTSUPP', 'ENOSYS', 'EISDIR']);const LEGACY_OWNER_CLAIM = '.cindy-owner-claim-v1.json';/** 单个文本槽的上限。灵魂与画像是「说明」,不是知识库。 */@@ -225,7 +230,8 @@ async function writeTextAtomic(absPath: string, content: string): Promise<void>* 不支持硬链接的文件系统(exFAT、部分网络盘):Node 不提供 NOREPLACE 的 rename,不存在* 既原子又不替换的写法。这里确认目标不存在后 rename:崩溃时目标要么不存在要么完整,* 不需要任何「写到一半」的猜测与恢复;代价是确认与 rename 两次系统调用之间若有人恰好- * 新建了同名文件会被替换 —— 只在这类文件系统、只在该文件本来缺失时存在。+ * 新建了同名文件会被替换 —— 只在这类文件系统、只在该文件本来缺失时存在。所以只有 link+ * 明确报「不支持硬链接」时才走这条回退;权限、空间、I/O 等其他错误原样抛出,这次不补种。*/async function writeTextIfAbsent(absPath: string, content: string): Promise<boolean> {if (Buffer.byteLength(content, 'utf8') > BOT_PROFILE_TEXT_MAX_BYTES) {@@ -242,7 +248,9 @@ async function writeTextIfAbsent(absPath: string, content: string): Promise<boolawait fs.link(tmp, absPath);return true;} catch (cause) {- if ((cause as NodeJS.ErrnoException).code === 'EEXIST') return false;+ const code = (cause as NodeJS.ErrnoException).code;+ if (code === 'EEXIST') return false;+ if (!code || !HARD_LINK_UNSUPPORTED_CODES.has(code)) throw cause;}try {await fs.access(absPath);