Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 117 additions & 42 deletions src/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ type Config struct {
filePath string
statusMu sync.RWMutex

dsettingsChangedCbMap map[string]func(LastoreDaemonStatus, interface{})
dsettingsChangedCbMap map[string]func(interface{}, interface{})
dsettingsChangedCbMapMu sync.Mutex
}

Expand Down Expand Up @@ -165,7 +165,7 @@ const (
dSettingsKeyVersion = "version"
dSettingsKeyAutoCheckUpdates = "auto-check-updates"
dSettingsKeyDisableUpdateMetadata = "disable-update-metadata"
dSettingsKeyAutoDownloadUpdates = "auto-download-updates"
DSettingsKeyAutoDownloadUpdates = "auto-download-updates"
dSettingsKeyAutoClean = "auto-clean"
dSettingsKeyMirrorSource = "mirror-source"
dSettingsKeyUpdateNotify = "update-notify"
Expand All @@ -192,8 +192,8 @@ const (
dSettingsKeyLocalDownloadSpeedLimit = "local-download-speed-limit"
DSettingsKeyLastoreDaemonStatus = "lastore-daemon-status"
dSettingsKeyUpdateStatus = "update-status"
dSettingsKeyPlatformUpdate = "platform-update"
dSettingsKeyPlatformUrl = "platform-url"
DSettingsKeyPlatformUpdate = "platform-update"
DSettingsKeyPlatformUrl = "platform-url"
dSettingsKeyStartCheckRange = "start-check-range"
dSettingsKeyIncludeDiskInfo = "include-disk-info"
dSettingsKeyPostUpgradeOnCalendar = "post-upgrade-on-calendar"
Expand All @@ -209,7 +209,7 @@ const (
dSettingsKeySystemRepoType = "system-repo-type"
dSettingsKeySecurityRepoType = "security-repo-type"
dSettingsKeyPlatformRepoComponents = "platform-repo-components"
dSettingsKeyIncrementalUpdate = "incremental-update"
DSettingsKeyIncrementalUpdate = "incremental-update"
dSettingsKeyIntranetUpdate = "intranet-update"
dSettingsKeyGetHardwareIdByHelper = "hardware-id-from-helper"
dSettingsKeyCheckPolicyInterval = "check-policy-interval"
Expand Down Expand Up @@ -266,7 +266,7 @@ func getConfigFromDSettings() *Config {
c.DisableUpdateMetadata = v.Value().(bool)
}

v, err = c.dsLastoreManager.Value(0, dSettingsKeyAutoDownloadUpdates)
v, err = c.dsLastoreManager.Value(0, DSettingsKeyAutoDownloadUpdates)
if err != nil {
logger.Warning(err)
} else {
Expand All @@ -280,7 +280,7 @@ func getConfigFromDSettings() *Config {
c.AutoClean = v.Value().(bool)
}

v, err = c.dsLastoreManager.Value(0, dSettingsKeyIncrementalUpdate)
v, err = c.dsLastoreManager.Value(0, DSettingsKeyIncrementalUpdate)
if err != nil {
logger.Warning(err)
} else {
Expand Down Expand Up @@ -485,25 +485,6 @@ func getConfigFromDSettings() *Config {
}
}
updateLastoreDaemonStatus()
_, err = c.dsLastoreManager.ConnectValueChanged(func(key string) {
switch key {
case DSettingsKeyLastoreDaemonStatus:
oldStatus := c.lastoreDaemonStatus
updateLastoreDaemonStatus()
newStatus := c.lastoreDaemonStatus
if (oldStatus & DisableUpdate) != (newStatus & DisableUpdate) {
c.dsettingsChangedCbMapMu.Lock()
cb := c.dsettingsChangedCbMap[key]
if cb != nil {
go cb(DisableUpdate, c.lastoreDaemonStatus)
}
c.dsettingsChangedCbMapMu.Unlock()
}
}
})
if err != nil {
logger.Warning(err)
}

v, err = c.dsLastoreManager.Value(0, dSettingsKeyCheckUpdateMode)
if err != nil {
Expand All @@ -519,15 +500,15 @@ func getConfigFromDSettings() *Config {
c.UpdateStatus = v.Value().(string)
}

v, err = c.dsLastoreManager.Value(0, dSettingsKeyPlatformUpdate)
v, err = c.dsLastoreManager.Value(0, DSettingsKeyPlatformUpdate)
if err != nil {
logger.Warning(err)
} else {
c.PlatformUpdate = v.Value().(bool)
}

var url string
v, err = c.dsLastoreManager.Value(0, dSettingsKeyPlatformUrl)
v, err = c.dsLastoreManager.Value(0, DSettingsKeyPlatformUrl)
if err != nil {
logger.Warning(err)
} else {
Expand Down Expand Up @@ -628,15 +609,6 @@ func getConfigFromDSettings() *Config {
}
}
updateUpgradeDeliveryEnabled()
_, err = c.dsLastoreManager.ConnectValueChanged(func(key string) {
switch key {
case dSettingsKeyUpgradeDeliveryEnabled:
updateUpgradeDeliveryEnabled()
}
})
if err != nil {
logger.Warning(err)
}

v, err = c.dsLastoreManager.Value(0, dSettingsKeySystemCustomSource)
if err != nil {
Expand Down Expand Up @@ -722,6 +694,110 @@ func getConfigFromDSettings() *Config {
}
c.OtherSourceList = append(c.OtherSourceList, "/etc/apt/sources.list.d/driver.list")
c.SecuritySourceList = append(c.SecuritySourceList, system.SecuritySourceFile)

_, err = c.dsLastoreManager.ConnectValueChanged(func(key string) {
logger.Infof("config update: key=%s", key)
switch key {
case dSettingsKeyIntranetUpdate:
v, err = c.dsLastoreManager.Value(0, dSettingsKeyIntranetUpdate)
if err != nil {
logger.Warning(err)
} else {
c.IntranetUpdate = v.Value().(bool)
}
case DSettingsKeyPlatformUpdate:
v, err = c.dsLastoreManager.Value(0, DSettingsKeyPlatformUpdate)
if err != nil {
logger.Warning(err)
} else {
oldValue := c.PlatformUpdate
newValue := v.Value().(bool)
c.PlatformUpdate = newValue
c.dsettingsChangedCbMapMu.Lock()
cb := c.dsettingsChangedCbMap[key]
if cb != nil {
go cb(oldValue, newValue)
}
c.dsettingsChangedCbMapMu.Unlock()
}
case DSettingsKeyPlatformUrl:
v, err = c.dsLastoreManager.Value(0, DSettingsKeyPlatformUrl)
if err != nil {
logger.Warning(err)
} else {
oldValue := c.PlatformUrl
newValue := v.Value().(string)
c.PlatformUrl = newValue
c.dsettingsChangedCbMapMu.Lock()
cb := c.dsettingsChangedCbMap[key]
if cb != nil {
go cb(oldValue, newValue)
}
c.dsettingsChangedCbMapMu.Unlock()
}
case dSettingsKeyGetHardwareIdByHelper:
v, err = c.dsLastoreManager.Value(0, dSettingsKeyGetHardwareIdByHelper)
if err != nil {
logger.Warning(err)
} else {
c.GetHardwareIdByHelper = v.Value().(bool)
}
case dSettingsKeyIncludeDiskInfo:
v, err = c.dsLastoreManager.Value(0, dSettingsKeyIncludeDiskInfo)
if err != nil {
logger.Warning(err)
} else {
c.IncludeDiskInfo = v.Value().(bool)
}
case DSettingsKeyIncrementalUpdate:
v, err = c.dsLastoreManager.Value(0, DSettingsKeyIncrementalUpdate)
if err != nil {
logger.Warning(err)
} else {
oldValue := c.IncrementalUpdate
newValue := v.Value().(bool)
c.IncrementalUpdate = newValue
c.dsettingsChangedCbMapMu.Lock()
cb := c.dsettingsChangedCbMap[key]
if cb != nil {
go cb(oldValue, newValue)
}
c.dsettingsChangedCbMapMu.Unlock()
}
case DSettingsKeyAutoDownloadUpdates:
v, err = c.dsLastoreManager.Value(0, DSettingsKeyAutoDownloadUpdates)
if err != nil {
logger.Warning(err)
} else {
oldValue := c.AutoDownloadUpdates
newValue := v.Value().(bool)
c.AutoDownloadUpdates = newValue
c.dsettingsChangedCbMapMu.Lock()
cb := c.dsettingsChangedCbMap[key]
if cb != nil {
go cb(oldValue, newValue)
}
c.dsettingsChangedCbMapMu.Unlock()
}
case dSettingsKeyUpgradeDeliveryEnabled:
updateUpgradeDeliveryEnabled()
case DSettingsKeyLastoreDaemonStatus:
oldStatus := c.lastoreDaemonStatus
updateLastoreDaemonStatus()
newStatus := c.lastoreDaemonStatus
if (oldStatus & DisableUpdate) != (newStatus & DisableUpdate) {
c.dsettingsChangedCbMapMu.Lock()
cb := c.dsettingsChangedCbMap[key]
if cb != nil {
go cb(oldStatus, newStatus)
}
c.dsettingsChangedCbMapMu.Unlock()
}
}
})
if err != nil {
logger.Warning(err)
}
return c
}

Expand All @@ -747,12 +823,11 @@ func (c *Config) json2DSettings(oldConfig *Config) {
_ = c.SetRepository(oldConfig.Repository)
_ = c.SetMirrorsUrl(oldConfig.MirrorsUrl)
_ = c.SetAllowInstallRemovePkgExecPaths(append(oldConfig.AllowInstallRemovePkgExecPaths, c.AllowInstallRemovePkgExecPaths...))
return
}

func (c *Config) ConnectConfigChanged(key string, cb func(LastoreDaemonStatus, interface{})) {
func (c *Config) ConnectConfigChanged(key string, cb func(interface{}, interface{})) {
if c.dsettingsChangedCbMap == nil {
c.dsettingsChangedCbMap = make(map[string]func(LastoreDaemonStatus, interface{}))
c.dsettingsChangedCbMap = make(map[string]func(interface{}, interface{}))
}
c.dsettingsChangedCbMapMu.Lock()
c.dsettingsChangedCbMap[key] = cb
Expand Down Expand Up @@ -796,7 +871,7 @@ func (c *Config) SetUpdateNotify(enable bool) error {

func (c *Config) SetAutoDownloadUpdates(enable bool) error {
c.AutoDownloadUpdates = enable
return c.save(dSettingsKeyAutoDownloadUpdates, enable)
return c.save(DSettingsKeyAutoDownloadUpdates, enable)
}

func (c *Config) SetAutoClean(enable bool) error {
Expand All @@ -806,7 +881,7 @@ func (c *Config) SetAutoClean(enable bool) error {

func (c *Config) SetIncrementalUpdate(enable bool) error {
c.IncrementalUpdate = enable
return c.save(dSettingsKeyIncrementalUpdate, enable)
return c.save(DSettingsKeyIncrementalUpdate, enable)
}

func (c *Config) UseIncrementalUpdate() bool {
Expand Down
4 changes: 0 additions & 4 deletions src/internal/system/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,6 @@ const (
)

func IsAuthorized() bool {
// TODO: only for test
if IntranetUpdate {
return true
}
edition, err := getEditionName()
if err != nil {
return false
Expand Down
2 changes: 0 additions & 2 deletions src/internal/system/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import (

const VarLibDir = "/var/lib/lastore"

var IntranetUpdate bool

type Status string

const (
Expand Down
5 changes: 5 additions & 0 deletions src/internal/updateplatform/message_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -1952,3 +1952,8 @@ func getTaskId() int {
}
return content
}

// UpdateRequestUrl 更新平台请求地址
func (m *UpdatePlatformManager) UpdateRequestUrl(url string) {
m.requestUrl = url
}
1 change: 0 additions & 1 deletion src/lastore-daemon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ func main() {
}
config := NewConfig(path.Join(system.VarLibDir, "config.json"))
logger.Info("intranet update:", config.IntranetUpdate)
system.IntranetUpdate = config.IntranetUpdate
if config.IntranetUpdate {
go func() {
out, err := exec.Command("/usr/bin/lastore-tools", "gatherinfo", "-type=post").CombinedOutput()
Expand Down
47 changes: 45 additions & 2 deletions src/lastore-daemon/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

"github.com/linuxdeepin/lastore-daemon/src/internal/config"
"github.com/linuxdeepin/lastore-daemon/src/internal/system"
"github.com/linuxdeepin/lastore-daemon/src/internal/system/dut"
"github.com/linuxdeepin/lastore-daemon/src/internal/updateplatform"

"github.com/godbus/dbus/v5"
Expand Down Expand Up @@ -212,11 +213,53 @@ func (m *Manager) initDbusSignalListen() {
}

func (m *Manager) initDSettingsChangedHandle() {
m.config.ConnectConfigChanged(config.DSettingsKeyLastoreDaemonStatus, func(bit config.LastoreDaemonStatus, value interface{}) {
if bit == config.DisableUpdate {
m.config.ConnectConfigChanged(config.DSettingsKeyLastoreDaemonStatus, func(oldValue, newValue interface{}) {
oldStatus := oldValue.(config.LastoreDaemonStatus)
newStatus := newValue.(config.LastoreDaemonStatus)
if (oldStatus & config.DisableUpdate) != (newStatus & config.DisableUpdate) {
logger.Infof("update timer: %s", lastoreAutoCheck)
_ = m.updateTimerUnit(lastoreAutoCheck)
}
})
m.config.ConnectConfigChanged(config.DSettingsKeyPlatformUpdate, func(oldValue, newValue interface{}) {
platformUpdate := newValue.(bool)
system.SetSystemUpdate(platformUpdate)
logger.Info("PlatformUpdate changed to:", platformUpdate, "SystemUpdateSource:", system.SystemUpdateSource)
})
m.config.ConnectConfigChanged(config.DSettingsKeyPlatformUrl, func(oldValue, newValue interface{}) {
platformUrl := newValue.(string)
if m.updatePlatform != nil {
m.updatePlatform.UpdateRequestUrl(platformUrl)
logger.Info("PlatformUrl changed to:", platformUrl)
}
})
m.config.ConnectConfigChanged(config.DSettingsKeyIncrementalUpdate, func(oldValue, newValue interface{}) {
incrementalUpdate := newValue.(bool)
m.UpdateIncrementalUpdate(incrementalUpdate)
logger.Info("IncrementalUpdate changed to:", incrementalUpdate)
})
m.config.ConnectConfigChanged(config.DSettingsKeyAutoDownloadUpdates, func(oldValue, newValue interface{}) {
autoDownloadUpdates := newValue.(bool)
if m.updater != nil {
_ = m.updater.SetAutoDownloadUpdates(autoDownloadUpdates)
logger.Info("AutoDownloadUpdates changed to:", autoDownloadUpdates)
}
})
}

// recreateSystem 重新创建system对象,用于incremental-update热更新
func (m *Manager) UpdateIncrementalUpdate(incrementalUpdate bool) {
if ds, ok := m.updateApi.(*dut.DutSystem); ok {
ds.APTSystem.IncrementalUpdate = incrementalUpdate
} else {
logger.Warning("UpdateIncrementalUpdate not supported for current system type")
}

if ds, ok := m.jobManager.system.(*dut.DutSystem); ok {
ds.APTSystem.IncrementalUpdate = incrementalUpdate
} else {
logger.Warning("UpdateIncrementalUpdate not supported for jobManager system type")
}
}

func (m *Manager) initStatusManager() {
Expand Down
Loading