-
Notifications
You must be signed in to change notification settings - Fork 445
fix(file-scheme): add fallback save using content when saveByChange requests it #4697
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
功能概览该PR添加了文件保存失败时的回退机制,当按变更保存失败时自动回退到按完整内容保存,并将文件系统操作重构为使用 IFileService 接口。 变更详情
序列图sequenceDiagram
participant Client as 客户端
participant BrowserDoc as FileSchemeDocumentProvider
participant FileService as IFileService
participant NodeService as FileSchemeDocNodeService
Client->>BrowserDoc: saveDocumentModel(内容变更)
alt 内容较小 (≤ 阈值)
BrowserDoc->>FileService: setContent(完整内容)
FileService-->>BrowserDoc: SUCCESS
else 内容较大 (> 阈值)
BrowserDoc->>NodeService: $saveByChange(变更)
NodeService->>FileService: getFileStat(URI)
FileService-->>NodeService: stat
NodeService->>FileService: resolveContent(URI)
FileService-->>NodeService: 当前内容
NodeService->>NodeService: 计算MD5并对比
alt MD5一致且无冲突
NodeService->>FileService: setContent(应用变更后)
FileService-->>NodeService: SUCCESS
else 文件不存在或MD5不匹配
NodeService-->>BrowserDoc: ERROR (USE_BY_CONTENT)
end
alt 收到 USE_BY_CONTENT 错误
BrowserDoc->>NodeService: $saveByContent(完整内容)
NodeService->>FileService: setContent(完整内容)
FileService-->>NodeService: SUCCESS
NodeService-->>BrowserDoc: SUCCESS
else 其他错误
BrowserDoc-->>Client: 返回原错误
end
end
BrowserDoc-->>Client: 保存结果
代码审查工作量🎯 3 (中等) | ⏱️ ~20 分钟 建议标签
建议审查者
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4697 +/- ##
==========================================
+ Coverage 48.17% 52.88% +4.70%
==========================================
Files 1686 1686
Lines 104888 104890 +2
Branches 22953 22942 -11
==========================================
+ Hits 50535 55476 +4941
+ Misses 45032 41055 -3977
+ Partials 9321 8359 -962
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
/next |
|
🎉 PR Next publish successful! 3.9.1-next-1769591692.0 |
Types
Background
$saveByChangeinFileSchemeDocNodeServiceImplwas the only method still using raw fs-extra synchronous/asynchronous calls (existsSync, statSync, readFile, writeFile) and manual iconvEncode/iconvDecode for encoding conversion.Meanwhile, the sibling method
$saveByContentand$getMd5already use this.fileService APIs (getFileStat,resolveContent, setContent), which handle encoding internally and go through the unified file service layer. This
inconsistency meant
$saveByChangebypassed any file service middleware (permissions, event hooks, virtual file systems) and pulled in unnecessary direct filesystem dependencies.Solution
$saveByContentwhen$saveByChangeis failedChangelog
and iconv calls, aligning with $saveByContent's pattern.
Summary by CodeRabbit
发布说明
新功能
Bug修复
测试
✏️ Tip: You can customize this high-level summary in your review settings.