fix(file-scheme): add fallback save using content when saveByChange requests it#4697
fix(file-scheme): add fallback save using content when saveByChange requests it#4697coffeedeveloper merged 2 commits intomainfrom
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 52.88% 52.88%
=======================================
Files 1686 1686
Lines 104888 104890 +2
Branches 22953 22942 -11
=======================================
+ Hits 55471 55476 +5
+ Misses 41058 41055 -3
Partials 8359 8359
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.