Skip to content

fix: unify system upgrade logic#335

Merged
zhaohuiw42 merged 1 commit intolinuxdeepin:masterfrom
zhaohuiw42:master
Mar 20, 2026
Merged

fix: unify system upgrade logic#335
zhaohuiw42 merged 1 commit intolinuxdeepin:masterfrom
zhaohuiw42:master

Conversation

@zhaohuiw42
Copy link
Contributor

Only enable incremental update when

  • intranet-update is false
  • incremental-update is true

Task: https://pms.uniontech.com/task-view-387631.html

Only enable incremental update when
- intranet-update is false
- incremental-update is true

Task: https://pms.uniontech.com/task-view-387631.html
@github-actions
Copy link

github-actions bot commented Mar 20, 2026

CLA Assistant Lite bot:
提交邮箱中包含我们的合作伙伴,但您似乎并非合作伙伴的成员或对接人,请联系相关对接人将您添加至组织之中,或由其重新发起 Pull Request。
The commit email domain belongs to one of our partners, but it seems you are not yet a member of the current organization, please contact the contact person to add you to the organization or let them submit the Pull Request.

You can retrigger this bot by commenting recheck in this Pull Request

@deepin-ci-robot
Copy link

deepin pr auto review

代码审查报告

1. 逻辑与语法审查

新增函数 UseIncrementalUpdate:

func (c *Config) UseIncrementalUpdate() bool {
	return !c.IntranetUpdate && c.IncrementalUpdate
}
  • 语法正确性:Go 语法完全正确。
  • 逻辑正确性:该函数封装了判断是否使用增量更新的逻辑。根据代码,只有当 IntranetUpdate(内网更新)为 falseIncrementalUpdate(增量更新开关)为 true 时,才返回 true。这符合业务逻辑,即内网环境下通常不走增量更新机制。

修改点

  • 将多处直接访问 cfg.IncrementalUpdate 修改为调用 cfg.UseIncrementalUpdate(),这使得判断逻辑更加集中和统一,符合 DRY(Don't Repeat Yourself)原则。

2. 代码质量

  • 封装性:将业务判断逻辑封装在 Config 结构体的方法中是一个很好的实践。它隐藏了内部状态(IntranetUpdateIncrementalUpdate)的组合逻辑,降低了调用方的认知负担。
  • 可维护性:如果将来判断"是否使用增量更新"的条件发生变化(例如增加新的开关或修改逻辑),只需修改 UseIncrementalUpdate 这一处,而不需要修改所有调用点。

3. 代码性能

  • 性能影响:微乎其微。这只是一个简单的布尔逻辑运算,且被调用处并非高频热点路径(主要涉及下载大小计算和更新清理),不会对程序性能产生负面影响。

4. 代码安全

  • 配置文件修改
    org.deepin.dde.lastore.json 中,默认值发生了变化:

    • upgrade-delivery-enabledtrue 变为 false
    • incremental-updatefalse 变为 true

    潜在风险

    • 行为变更:默认开启增量更新可能会对旧版本或特定环境(如内网环境)下的系统造成兼容性问题。虽然 UseIncrementalUpdate 包含了 !c.IntranetUpdate 的检查,但建议确认 IntranetUpdate 标志在所有环境下都能被正确初始化和读取,防止在内网环境下意外触发增量更新。
    • 回滚机制:如果增量更新导致问题,确保管理员可以通过配置文件轻松回滚(目前看来是支持的,因为配置项依然存在)。

5. 改进建议

  1. 添加注释
    建议为 UseIncrementalUpdate 函数添加注释,解释为什么需要同时检查这两个标志。例如:

    // UseIncrementalUpdate returns true if incremental update is enabled and the environment is not intranet.
    func (c *Config) UseIncrementalUpdate() bool {
        return !c.IntranetUpdate && c.IncrementalUpdate
    }
  2. 配置一致性检查
    建议在 Config 初始化或加载时,添加一致性检查逻辑。例如,如果检测到 IntranetUpdatetrue,强制将 IncrementalUpdate 设为 false 或发出警告,以避免配置冲突。

  3. 单元测试
    建议为 UseIncrementalUpdate 添加单元测试,覆盖以下场景:

    • IntranetUpdate = false, IncrementalUpdate = true -> 返回 true
    • IntranetUpdate = true, IncrementalUpdate = true -> 返回 false
    • IntranetUpdate = false, IncrementalUpdate = false -> 返回 false
    • IntranetUpdate = true, IncrementalUpdate = false -> 返回 false
  4. 日志记录
    在关键路径(如 lastore-daemon/main.goupdate_status.go)中,如果 UseIncrementalUpdate 返回 true,建议记录日志,便于调试和追踪增量更新的触发情况。

总结

本次修改通过引入 UseIncrementalUpdate 方法,提高了代码的可维护性和逻辑一致性。配置默认值的变更需要特别注意其对不同环境的影响,建议通过测试和日志确保其行为符合预期。整体而言,这是一次良好的重构。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: qiuzhiqian, zhaohuiw42

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@zhaohuiw42 zhaohuiw42 merged commit 30a1b54 into linuxdeepin:master Mar 20, 2026
13 of 17 checks passed
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.

3 participants