Skip to content

fix: Security updates use the system update sources#313

Merged
qiuzhiqian merged 1 commit into
masterfrom
fix_intranet
Feb 2, 2026
Merged

fix: Security updates use the system update sources#313
qiuzhiqian merged 1 commit into
masterfrom
fix_intranet

Conversation

@qiuzhiqian

Copy link
Copy Markdown
Contributor

@github-actions

github-actions Bot commented Feb 2, 2026

Copy link
Copy Markdown

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.

xml seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You can retrigger this bot by commenting recheck in this Pull Request

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

我对这段 Git diff 代码进行了仔细审查,以下是针对语法逻辑、代码质量、代码性能和代码安全的改进意见:

1. 文件:src/internal/system/update_type.go

变更概述:
该文件修改了 CustomSourceWrapper 函数,移除了对 IntranetUpdate(内网更新)全局变量的直接判断,改为统一遍历 AllCheckUpdateType 来构建源路径列表,并简化了单项更新时的逻辑。

代码逻辑与质量分析:

  1. 逻辑变更(内网更新处理下沉):

    • 原逻辑:在 CustomSourceWrapper 内部判断 IntranetUpdate。如果是内网,只追加 SystemUpdateSource;否则遍历所有类型追加路径。
    • 新逻辑:移除内部判断,统一遍历 AllCheckUpdateType。这意味着调用者(如 manager_update.go)需要负责传入正确的 updateType(例如内网时只传入 SystemUpdate)。
    • 评价:这是一个好的改进。它遵循了"控制反转"原则,使得 CustomSourceWrapper 更加纯粹,只负责根据传入的类型执行逻辑,而不需要感知"内网"还是"外网"的业务状态。这提高了函数的内聚性和复用性。
  2. 单项更新逻辑简化:

    • 原逻辑:当仓库数量为1时,如果是内网更新,直接使用 sourcePathList[0];否则使用 GetCategorySourceMap()[updateType]
    • 新逻辑:当仓库数量为1时,统一使用 GetCategorySourceMap()[updateType]
    • 评价:逻辑更清晰。由于外层已经控制了 updateType 的传入,这里直接根据类型获取路径是合理的。

改进意见:

  • 潜在的性能问题GetCategorySourceMap() 在循环中被调用。如果这个函数内部涉及复杂的计算或锁操作(例如每次都重新生成 map),可能会影响性能。建议检查该函数实现,如果 map 是静态的,建议缓存为局部变量或包级变量。
  • 代码健壮性sourcePath := GetCategorySourceMap()[t] 这一行假设 map 中一定包含 t。如果 AllCheckUpdateType() 返回的类型与 Map 中的 Key 不一致,可能会导致 panic 或空指针。建议增加对 ok 的判断:
    sourcePath, ok := GetCategorySourceMap()[t]
    if !ok {
        log.Warningf("Update type %v not found in source map", t)
        continue
    }

2. 文件:src/lastore-daemon/job.go

变更概述:
_InitProgressRange 方法中,当进度范围初始化失败时,将 panic 的信息从简单的字符串改为包含具体数值的格式化字符串。

代码逻辑与质量分析:

  • 评价:这是一个非常好的改进。在发生 panic 时,能够直接看到导致错误的 beginend 的具体数值,极大地提高了问题排查的效率。这是调试友好的代码实践。

改进意见:

  • 代码风格:无。
  • 安全性:panic 通常用于不可恢复的错误。这里保留 panic 是合理的,因为进度范围错误通常是编程逻辑错误,运行时无法恢复。

3. 文件:src/lastore-daemon/manager_update.go

变更概述:
updateSource 方法中,调用 system.CustomSourceWrapper 之前,根据 m.config.IntranetUpdate 的配置决定传入的 updateType。如果是内网,限制为 system.SystemUpdate;否则使用 system.AllCheckUpdate

代码逻辑与质量分析:

  • 逻辑一致性:这个变更完美配合了 update_type.go 的修改。将业务逻辑判断(是否内网)上移到了 Manager 层,使得底层的 CustomSourceWrapper 保持通用。
  • 可读性:代码逻辑清晰,注释 "Intranet updates are limited to system updates only" 准确解释了意图。

改进意见:

  • 变量作用域updateType 是局部变量,作用域仅限于该函数块,这是合理的。
  • 魔法值system.SystemUpdatesystem.SystemUpdate 是常量或枚举,使用得当。

综合建议

  1. 安全性

    • 整体代码安全性良好。逻辑变更没有引入明显的安全漏洞。
    • 内网更新的限制逻辑从底层移至业务层,使得权限控制更加集中和明确。
  2. 性能

    • 如前所述,建议关注 GetCategorySourceMap() 的实现开销。如果在高频调用路径上,应确保其访问是 O(1) 且无锁或低锁开销。
  3. 测试建议

    • 由于修改了内网更新的控制流,建议重点测试内网环境下的系统更新场景,确保行为符合预期(即只检查系统更新,不检查应用更新)。
    • 测试边界情况:当 updateType 组合导致 sourcePathList 为空时的行为。

总结
这是一次高质量的代码重构。它通过移除底层函数对全局状态的依赖,提高了代码的模块化和可测试性。同时,job.go 中的日志增强也有助于运维。唯一需要注意的是 GetCategorySourceMap 的访问效率及健壮性。

@deepin-ci-robot

Copy link
Copy Markdown

[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

@qiuzhiqian qiuzhiqian merged commit 5ccfe78 into master Feb 2, 2026
25 of 28 checks passed
@qiuzhiqian qiuzhiqian deleted the fix_intranet branch February 2, 2026 08:33
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