fix(instance): remove new directory when failing to create instance#1321
fix(instance): remove new directory when failing to create instance#1321icgnos wants to merge 1 commit intoUNIkeEN:mainfrom
Conversation
|
发现你的代码里面在疯狂地添加 .map_err(|_| {
let _ = fs::remove_dir_all(&version_path);其实前面的时候这个目录都还没有创建。另外如此重复的写相同的代码十分地不优雅。 我的建议是,可以做成全局的错误捕捉,如把 |
UNIkeEN
left a comment
There was a problem hiding this comment.
另外,更重要的问题在于,下载任务创建但失败后,是否应该删除已经下载的部分文件(和文件夹),这个需要提请 UX 讨论,所以 issue 可能无法通过此 PR 关闭
src-tauri/src/instance/commands.rs
Outdated
There was a problem hiding this comment.
请通过断点检查,此行之前 version_path 是否已经被创建。在这之前的 remove_dir_all 可能是无效且无必要的
There was a problem hiding this comment.
请通过断点检查,此行之前
version_path是否已经被创建。在这之前的remove_dir_all可能是无效且无必要的
经测试在980行已被创建
src-tauri/src/instance/commands.rs
Outdated
| fs::write(options_path, format!("lang:{}\n", lang_code)) | ||
| .map_err(|_| InstanceError::FileCreationFailed)?; | ||
| fs::write(options_path, format!("lang:{}\n", lang_code)).map_err(|_| { | ||
| let _ = fs::remove_dir_all(&version_path); |
There was a problem hiding this comment.
这里原来有 map_err,但应改为静默处理。自动跳过语言失败不应该将整个实例过程以错误终止
静默处理即 let _ = ...
There was a problem hiding this comment.
静默处理即
let _ = ...
静默处理可以 log error
似乎下载任务创建之后就不会失败了,如果网络中断任务只会暂停,网络恢复后会继续下载。如果玩家手动取消任务,则会保留已下载的部分文件 |
Checklist
This PR is a ..
Related Issues
Description
Additional Context