Skip to content

fix: prevent stale cache causing rename-on-source after copy#2505

Open
tide-wait wants to merge 3 commits into
OpenListTeam:mainfrom
tide-wait:fix/115-cache-race
Open

fix: prevent stale cache causing rename-on-source after copy#2505
tide-wait wants to merge 3 commits into
OpenListTeam:mainfrom
tide-wait:fix/115-cache-race

Conversation

@tide-wait
Copy link
Copy Markdown

@tide-wait tide-wait commented May 25, 2026

Summary / 摘要

Two fixes for the 115_open driver (Open API token-based 115 cloud storage):

1. Copy→Rename race condition — source file renamed instead of copy

When 115_open's Copy method returns the source object (the API does not return new file info), the directory cache in internal/op/fs.go was populated without a Temp mask. Subsequent Rename operations using excludeTempObj=true would hit the stale cache entry carrying the source file's FileID, causing the rename to target the source instead of the copy. The Move path had the same vulnerability.
Fix: Apply Temp mask uniformly to all post-Copy and post-Move cache entries, so the existing excludeTempObj mechanism correctly triggers a fresh API list during subsequent Rename/Move.

2. Mkdir failure — GetFolderInfo JSON unmarshal error

The 115 Open API endpoint folder/get_info now returns data as a JSON array [{...}] instead of a single object {...}. The SDK (115-sdk-go v0.2.3) still unmarshals into GetFolderInfoResp (a single struct), causing json.Unmarshal to fail. Mkdir calls Get() to check existence, which hits this error.
Fix: Catch the unmarshal error in the driver's Get method and return errs.NotSupport, allowing the upper-level op.Get to gracefully fall back to listing the parent directory.

Changes

File Change
internal/op/fs.go Unify Temp mask application for both nil and non-nil newObj after Copy and Move
drivers/115_open/driver.go Catch unmarshal error in Get(), return errs.NotSupport; add errs import
  • This PR has breaking changes.
  • This PR changes public API, config, storage format, or migration behavior.
  • This PR requires corresponding changes in related repositories.

Related Issues / 关联 Issue

Fixes #2506

Testing / 测试

  • go build ./internal/op/ ./drivers/115_open/
  • Manual test / 手动测试: 原始错误由生产环境复现,修复后编译通过

Checklist / 检查清单

  • I have read CONTRIBUTING.
  • I confirm this contribution follows the repository license, contribution policy, and code of conduct.
  • I have formatted the changed code with gofmt, go fmt, or prettier where applicable.
  • I have requested review from relevant maintainers or code owners where applicable.

AI Disclosure / AI 使用声明

  • This PR includes AI-assisted content.
    Tools used / 使用工具:
  • Other (please specify): OpenCode / DeepSeek-V4-Pro
    Usage scope / 使用范围:
  • Code generation / 代码生成
  • Refactoring / 重构
  • Documentation / 文档
  • Review assistance / 审查辅助
  • I have reviewed and validated all AI-assisted content included in this PR.
  • I have ensured that all AI-assisted commits include Co-Authored-By attribution.
  • I can reproduce all AI-assisted content included in this PR without any AI tools.

@jyxjjj
Copy link
Copy Markdown
Member

jyxjjj commented May 25, 2026

Could you please format the PR description using the template, run go fmt before submitting, and disclose any AI-generated contributions if applicable?

We are currently working on clearer guidelines for AI-assisted contributions, so apologies for the inconvenience.

Thanks for the contribution.

tide-wait added 3 commits May 25, 2026 21:09
When a driver implementing CopyResult returns the source object instead
of the actual new copy (e.g. 115_open), the directory cache was populated
without a Temp mask. Subsequent Rename operations using excludeTempObj=true
would hit the stale cache entry carrying the source file ID, causing the
rename to target the source file instead of the copy.

This ensures all post-copy and post-move cache entries carry the Temp flag,
allowing Rename and Move to correctly trigger a fresh list via the existing
excludeTempObj mechanism.
The 115 Open API endpoint folder/get_info now returns the data field as a
JSON array instead of a single object. The SDK (115-sdk-go v0.2.3) still
unmarshals into a single struct, causing a "cannot unmarshal array" error.

Catch this error in the driver Get method and return errs.NotSupport,
which causes the upper-level op.Get to fall back to listing the parent
directory to resolve the target object.
@tide-wait tide-wait force-pushed the fix/115-cache-race branch from f8d79d3 to 43d0679 Compare May 25, 2026 13:09
@tide-wait
Copy link
Copy Markdown
Author

@jyxjjj Thanks for the review. I've updated the PR description using the template, run go fmt, and added the AI disclosure section. Please take another look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 115网盘 Copy 后 Rename 误操作源文件

2 participants