fix: ensure upgrade delivery enabled only for professional#371
Closed
zhaohuiw42 wants to merge 0 commit intolinuxdeepin:develop/intranet-updatefrom
Closed
fix: ensure upgrade delivery enabled only for professional#371zhaohuiw42 wants to merge 0 commit intolinuxdeepin:develop/intranet-updatefrom
zhaohuiw42 wants to merge 0 commit intolinuxdeepin:develop/intranet-updatefrom
Conversation
|
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
deepin pr auto review代码审查报告本次代码修改主要实现了"升级交付功能(Upgrade Delivery/P2P Update)"仅对专业版系统开放的功能。整体逻辑清晰,测试覆盖较全面,但在性能、安全性和代码健壮性方面存在一些改进空间。 1. 语法与逻辑
2. 代码质量
3. 代码性能
4. 代码安全
5. 改进代码示例针对上述"性能"和"代码质量"的建议,以下是优化后的代码片段示例: config.go 修改建议: // 在 Config 结构体中增加缓存字段
type Config struct {
// ... 其他字段
osVersion string // 缓存版本名
isPro bool // 缓存是否为专业版
versionLoaded bool // 标记是否已加载
}
// 封装读取逻辑,增加缓存
func (c *Config) checkIsProfessionalEdition() bool {
if c.versionLoaded {
return c.isPro
}
kf := keyfile.NewKeyFile()
// 使用常量或配置中的路径
err := kf.LoadFromFile(osVersionFile)
if err != nil {
logger.Warning("Failed to load os-version file:", err)
c.isPro = false
} else {
editionName, err := kf.GetString("Version", "EditionName")
if err != nil {
logger.Warning("Failed to get EditionName:", err)
c.isPro = false
} else {
c.isPro = (editionName == "Professional")
c.osVersion = editionName
}
}
c.versionLoaded = true
return c.isPro
}
// 修改辅助函数,依赖 Config 实例
func upgradeDeliveryEnabledForCurrentEdition(c *Config, enable bool) bool {
if !enable {
return false
}
return c.checkIsProfessionalEdition()
}
// 在 SetUpgradeDeliveryEnabled 中使用
func (c *Config) SetUpgradeDeliveryEnabled(enable bool) error {
// 传入 c 实例
actualEnabled := upgradeDeliveryEnabledForCurrentEdition(c, enable)
c.UpgradeDeliveryEnabled = actualEnabled
return c.save(dSettingsKeyUpgradeDeliveryEnabled, actualEnabled)
}总结: |
bad679b to
401ce58
Compare
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: zhaohuiw42 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Task: https://pms.uniontech.com/task-view-388365.html