Skip to content

fix(sync): (Codex) Google Drive ensureDirExists() 接口语义不一致#1391

Open
cyfung1031 wants to merge 1 commit intomainfrom
fix/sync/006
Open

fix(sync): (Codex) Google Drive ensureDirExists() 接口语义不一致#1391
cyfung1031 wants to merge 1 commit intomainfrom
fix/sync/006

Conversation

@cyfung1031
Copy link
Copy Markdown
Collaborator

原本 ensureDirExists(dirPath) 名字表示“确保目录存在”,但实际只做查找;目录不存在就抛错。现在改成真正逐级确保目录存在,并返回最终目录 ID。

  • createDir()ensureDirExists() 现在共用同一套内部逻辑 ensureDirPath()
  • ensureDirPath() 从 Google Drive appDataFolder 根目录开始逐级查找目录
  • 找到就复用并缓存 ID
  • 找不到就调用 createFolder() 创建,再缓存 ID
  • ensureDirExists("/A/B") 现在会真的确保 /A/B 存在,并返回 B 的 folder id

这个修正主要解决 writer 路径问题。GoogleDriveFileWriter.write() 原本依赖 ensureDirExists(),但如果上层没先建目录,写入会失败。现在 writer 自己调用 ensureDirExists() 时,目录缺失也能正确创建。

同时避免了一个陷阱:没有让 ensureDirExists() 直接调用 createDir(),因为在 openDir("/Base") 后写文件时,直接调用 createDir("/Base") 可能被拼成重复路径 /Base/Base。所以这次抽了 root-based 的内部 helper。

测试补在 googledrive.test.ts

  • 验证 ensureDirExists("/A/B") 会创建缺失的嵌套目录并返回最终 ID
  • 验证在子目录 filesystem 里写文件时,writer 使用的是 /Base,不会变成重复路径

@cyfung1031 cyfung1031 changed the title fix(sync): Google Drive ensureDirExists() 接口语义不一致 fix(sync): (Codex) Google Drive ensureDirExists() 接口语义不一致 May 1, 2026
@cyfung1031 cyfung1031 added the CloudSync Related to CloudSync label May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CloudSync Related to CloudSync

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant