-
-
Notifications
You must be signed in to change notification settings - Fork 116
fix: revert_settings返回false方便调用方重试 #585
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: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -981,28 +981,29 @@ namespace display_device { | |
| // 尝试恢复设置 | ||
| bool data_updated { false }; | ||
| bool success = try_revert_settings(*persistent_data, data_updated, skip_vdd_destroy); | ||
| if (!success) { | ||
|
|
||
| if (success) { | ||
| // 恢复成功,清理持久化数据 | ||
| remove_file(filepath); | ||
| persistent_data = nullptr; | ||
| BOOST_LOG(info) << "显示设备配置已恢复"; | ||
| } | ||
| else { | ||
| if (data_updated) { | ||
| save_settings(filepath, *persistent_data); // 忽略返回值 | ||
| save_settings(filepath, *persistent_data); // 保存部分恢复的状态以便重试 | ||
| } | ||
| BOOST_LOG(error) << "恢复显示设备设置失败!如有异常请尝试关闭基地显示器,或手动修改系统显示设置~"; | ||
| } | ||
|
|
||
| // 清理持久化数据 | ||
| remove_file(filepath); | ||
| persistent_data = nullptr; | ||
|
|
||
| // 释放音频数据 | ||
| // 不管成败都释放音频数据(串流已结束) | ||
| if (reason != revert_reason_e::topology_switch) { | ||
| if (audio_data) { | ||
| BOOST_LOG(debug) << "释放捕获的音频接收器"; | ||
| audio_data = nullptr; | ||
| } | ||
| } | ||
|
|
||
| if (success) { | ||
| BOOST_LOG(info) << "显示设备配置已恢复"; | ||
| } | ||
| return success; | ||
|
Comment on lines
+998
to
+1006
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 失败后仍释放
可参考的最小改动- // 不管成败都释放音频数据(串流已结束)
- if (reason != revert_reason_e::topology_switch) {
+ // 仅在恢复完成后释放音频数据;失败时保留,便于调用方继续重试
+ if (success && reason != revert_reason_e::topology_switch) {
if (audio_data) {
BOOST_LOG(debug) << "释放捕获的音频接收器";
audio_data = nullptr;
}
}As per coding guidelines, 🤖 Prompt for AI Agents |
||
| } | ||
| return true; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
持久化操作的失败不能被静默忽略。
这段新逻辑把“可重试”建立在
persistent_data的最新快照之上,但成功分支里无论remove_file(filepath)是否真的删掉文件都会立刻清掉内存态,失败分支里save_settings()的返回值也被忽略。只要任一持久化操作失败,进程重启后就可能按过期 JSON 继续回滚,重复执行已经成功的步骤。建议把删除/保存失败显式纳入结果处理,而不是只保留一个普通的success/false。🤖 Prompt for AI Agents