Skip to content

fix(sync): (Codex) 修复 Google Drive 路径 ID 缓存在外部删除后失效的问题 | 前置PR #1406#1407

Open
cyfung1031 wants to merge 1 commit intofix/sync/012from
fix/sync/013
Open

fix(sync): (Codex) 修复 Google Drive 路径 ID 缓存在外部删除后失效的问题 | 前置PR #1406#1407
cyfung1031 wants to merge 1 commit intofix/sync/012from
fix/sync/013

Conversation

@cyfung1031
Copy link
Copy Markdown
Collaborator

标题

修复 Google Drive 路径 ID 缓存在外部删除后失效的问题

概述

本 PR 修复 Google Drive path-to-ID cache 在远端目录被外部删除后可能继续使用 stale ID 的问题。

主要改动:

  • 新增 clearPathCache(path?),用于清理 Google Drive 的路径到文件 ID 缓存。
  • Google Drive writer 在写入流程遇到 typed notFound 错误时:
    • 清空 path cache。
    • 重新解析目录 ID。
    • 重试写入一次。
  • Google Drive list() 在当前目录缓存 ID 失效并触发 typed notFound 时:
    • 清空 path cache。
    • 重新解析目录 ID。
    • 重试 list 一次。
  • 保留本地 delete 后清理相关缓存的行为,并改为复用新的 clearPathCache(path)
  • 补充测试覆盖 stale cache 恢复和非 404 错误不重试。

背景

Google Drive 文件系统会缓存路径到 Google Drive file ID 的映射,例如:

/Base -> folder-id-1
/Base/Sub -> folder-id-2

如果用户在 Google Drive 网页端或其他客户端删除了这些目录,本地缓存仍可能指向旧 ID。后续上传或列表请求会继续使用 stale parent ID,导致 Google Drive 返回 404。

在本 PR 之前,遇到这种情况时同步流程会失败,而不是清理缓存并重新发现或重建目录。

行为变化

Writer 写入

当 Google Drive writer 在以下阶段遇到 typed notFound 错误时,会清空 path cache 并重试一次:

  • 解析父目录。
  • 查找目标文件。
  • 更新已有文件。
  • 创建新文件。

重试时会重新解析目录路径。如果目录确实被外部删除,writer 会按原有逻辑重新创建缺失目录并继续上传。

List 列表

list() 使用缓存目录 ID 发起列表请求并遇到 typed notFound 时,会清空 path cache 并重试一次。

如果清空缓存后仍找不到目录,则继续按现有行为抛出目录不存在错误。

不改变的行为

  • 只在 typed notFound 错误下重试。
  • 非 404 错误不会重试,例如 auth、conflict、rate limit 或普通请求失败。
  • 不增加常规路径下的额外校验请求。
  • 不改变同步冲突处理或条件写逻辑。

实现说明

本 PR 在 404 后选择清空整个 Google Drive path cache,而不是只清理当前路径。

原因是 stale ID 可能来自上级目录。例如当前路径是:

/Base/Sub

但真正失效的是:

/Base

如果只清理 /Base/Sub,重试时仍会命中 stale /Base,导致再次失败。清空整个 cache 只发生在 provider 明确返回 404 后,避免常规路径增加额外开销。


需要先合并 #1406

@CodFrm
Copy link
Copy Markdown
Member

CodFrm commented May 6, 2026

怎么还在处理这块,有点害怕了

AI 总是会找出新问题的

@cyfung1031
Copy link
Copy Markdown
Collaborator Author

cyfung1031 commented May 6, 2026

怎么还在处理这块,有点害怕了

AI 总是会找出新问题的

不是呀。在 #1237 在2月开始已经有写
你没处理,现在用AI提交PR呀
上一次10个只是 6成左右吧
剩下4成 要先处理好之前6成才可以搞

#1237 每个标题都会在PR提交后补PR连结
#1237 写的问题处理完后都不搞了


#1237 (comment)_

@cyfung1031 cyfung1031 added the CloudSync Related to CloudSync label May 6, 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.

2 participants