diff --git a/src/internal/config/config.go b/src/internal/config/config.go
index 679fc1531..db005a5ef 100644
--- a/src/internal/config/config.go
+++ b/src/internal/config/config.go
@@ -6,6 +6,7 @@ package config
import (
"encoding/json"
+ "errors"
"os"
"sync"
"time"
@@ -235,775 +236,790 @@ func getConfigFromDSettings() *Config {
systemSigLoop := dbusutil.NewSignalLoop(sysBus, 10)
systemSigLoop.Start()
c.dsLastoreManager.InitSignalExt(systemSigLoop, true)
- // 从DSettings获取所有内容,更新config
- v, err := c.dsLastoreManager.Value(0, dSettingsKeyUseDSettings)
- if err != nil {
- logger.Warning(err)
- } else {
- c.useDSettings = v.Value().(bool)
- }
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyVersion)
- if err != nil {
- logger.Warning(err)
- } else {
- c.Version = v.Value().(string)
- }
+ c.reload()
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyAutoCheckUpdates)
+ // 从DSettings获取所有内容,更新config
+ _, err = c.dsLastoreManager.ConnectValueChanged(func(key string) {
+ switch key {
+ case DSettingsKeyLastoreDaemonStatus:
+ oldStatus := c.lastoreDaemonStatus
+ v, err := c.dsLastoreManager.Value(0, DSettingsKeyLastoreDaemonStatus)
+ if err != nil {
+ logger.Warning(err)
+ } else {
+ c.lastoreDaemonStatus = LastoreDaemonStatus(v.Value().(int64))
+ }
+ 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)
- } else {
- c.AutoCheckUpdates = v.Value().(bool)
}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyDisableUpdateMetadata)
+ err = c.recoveryAndApplyOemFlag(system.SystemUpdate)
if err != nil {
logger.Warning(err)
- } else {
- c.DisableUpdateMetadata = v.Value().(bool)
}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyAutoDownloadUpdates)
+ err = c.recoveryAndApplyOemFlag(system.SecurityUpdate)
if err != nil {
logger.Warning(err)
- } else {
- c.AutoDownloadUpdates = v.Value().(bool)
}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyAutoClean)
+ // classifiedCachePath和onlineCachePath两项数据没有存储在dconfig中,是因为数据量太大,dconfig不支持存储这么长的数据
+ content, err := os.ReadFile(classifiedCachePath)
if err != nil {
- logger.Warning(err)
+ if !os.IsNotExist(err) {
+ logger.Warning(err)
+ }
} else {
- c.AutoClean = v.Value().(bool)
+ c.ClassifiedUpdatablePackages = make(map[string][]string)
+ err = json.Unmarshal(content, &c.ClassifiedUpdatablePackages)
+ if err != nil {
+ logger.Warning(err)
+ }
}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyIncrementalUpdate)
+ content, err = os.ReadFile(onlineCachePath)
if err != nil {
- logger.Warning(err)
+ if !os.IsNotExist(err) {
+ logger.Warning(err)
+ }
} else {
- c.IncrementalUpdate = v.Value().(bool)
+ c.OnlineCache = string(content)
}
+ c.OtherSourceList = append(c.OtherSourceList, "/etc/apt/sources.list.d/driver.list")
+ c.SecuritySourceList = append(c.SecuritySourceList, system.SecuritySourceFile)
+ return c
+}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyIntranetUpdate)
- if err != nil {
- logger.Warning(err)
- } else {
- c.IntranetUpdate = v.Value().(bool)
- }
+func (c *Config) json2DSettings(oldConfig *Config) {
+ _ = c.UpdateLastCheckTime()
+ _ = c.UpdateLastCleanTime()
+ _ = c.UpdateLastCheckCacheSizeTime()
+ _ = c.SetVersion(oldConfig.Version)
+ _ = c.SetAutoCheckUpdates(oldConfig.AutoCheckUpdates)
+ _ = c.SetDisableUpdateMetadata(oldConfig.DisableUpdateMetadata)
+ _ = c.SetUpdateNotify(oldConfig.UpdateNotify)
+ _ = c.SetAutoDownloadUpdates(oldConfig.AutoDownloadUpdates)
+ _ = c.SetAutoClean(oldConfig.AutoClean)
+ _ = c.SetMirrorSource(oldConfig.MirrorSource)
+ _ = c.SetAppstoreRegion(oldConfig.AppstoreRegion)
+ _ = c.SetUpdateMode(oldConfig.UpdateMode)
+ _ = c.SetCleanIntervalCacheOverLimit(oldConfig.CleanIntervalCacheOverLimit)
+ _ = c.SetAutoInstallUpdates(oldConfig.AutoInstallUpdates)
+ _ = c.SetAutoInstallUpdateType(oldConfig.AutoInstallUpdateType)
+ _ = c.SetAllowPostSystemUpgradeMessageVersion(append(oldConfig.AllowPostSystemUpgradeMessageVersion, c.AllowPostSystemUpgradeMessageVersion...))
+ _ = c.SetCheckInterval(oldConfig.CheckInterval)
+ _ = c.SetCleanInterval(oldConfig.CleanInterval)
+ _ = c.SetRepository(oldConfig.Repository)
+ _ = c.SetMirrorsUrl(oldConfig.MirrorsUrl)
+ _ = c.SetAllowInstallRemovePkgExecPaths(append(oldConfig.AllowInstallRemovePkgExecPaths, c.AllowInstallRemovePkgExecPaths...))
+}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyMirrorSource)
- if err != nil {
- logger.Warning(err)
- } else {
- c.MirrorSource = v.Value().(string)
+func (c *Config) ConnectConfigChanged(key string, cb func(LastoreDaemonStatus, interface{})) {
+ if c.dsettingsChangedCbMap == nil {
+ c.dsettingsChangedCbMap = make(map[string]func(LastoreDaemonStatus, interface{}))
}
+ c.dsettingsChangedCbMapMu.Lock()
+ c.dsettingsChangedCbMap[key] = cb
+ c.dsettingsChangedCbMapMu.Unlock()
+}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyUpdateNotify)
- if err != nil {
- logger.Warning(err)
- } else {
- c.UpdateNotify = v.Value().(bool)
- }
+func (c *Config) UpdateLastCheckTime() error {
+ c.LastCheckTime = time.Now()
+ return c.save(dSettingsKeyLastCheckTime, c.LastCheckTime.Format(configTimeLayout))
+}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyCheckInterval)
- if err != nil {
- logger.Warning(err)
- } else {
- c.CheckInterval = time.Duration(v.Value().(int64))
- }
+func (c *Config) UpdateLastCleanTime() error {
+ c.LastCleanTime = time.Now()
+ return c.save(dSettingsKeyLastCleanTime, c.LastCleanTime.Format(configTimeLayout))
+}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyCleanInterval)
- if err != nil {
- logger.Warning(err)
- } else {
- c.CleanInterval = time.Duration(v.Value().(int64))
- }
+func (c *Config) UpdateLastCheckCacheSizeTime() error {
+ c.LastCheckCacheSizeTime = time.Now()
+ return c.save(dSettingsKeyLastCheckCacheSizeTime, c.LastCheckCacheSizeTime.Format(configTimeLayout))
+}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyUpdateMode)
- if err != nil {
- logger.Warning(err)
- } else {
- if (c.UpdateMode & system.OnlySecurityUpdate) != 0 {
- c.UpdateMode &= ^system.OnlySecurityUpdate
- c.UpdateMode |= system.SecurityUpdate
- }
- c.UpdateMode = system.UpdateType(v.Value().(int64))
- }
+func (c *Config) SetVersion(version string) error {
+ c.Version = version
+ return c.save(dSettingsKeyVersion, version)
+}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyCleanIntervalCacheOverLimit)
- if err != nil {
- logger.Warning(err)
- } else {
- c.CleanIntervalCacheOverLimit = time.Duration(v.Value().(int64))
- }
+func (c *Config) SetAutoCheckUpdates(enable bool) error {
+ c.AutoCheckUpdates = enable
+ return c.save(dSettingsKeyAutoCheckUpdates, enable)
+}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyAppstoreRegion)
- if err != nil {
- logger.Warning(err)
- } else {
- c.AppstoreRegion = v.Value().(string)
- }
+func (c *Config) SetDisableUpdateMetadata(disable bool) error {
+ c.DisableUpdateMetadata = disable
+ return c.save(dSettingsKeyDisableUpdateMetadata, disable)
+}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyLastCheckTime)
- if err != nil {
- logger.Warning(err)
- } else {
- s := v.Value().(string)
- c.LastCheckTime, err = time.Parse(configTimeLayout, s)
- if err != nil {
- logger.Warning(err)
- }
- }
+func (c *Config) SetUpdateNotify(enable bool) error {
+ c.UpdateNotify = enable
+ return c.save(dSettingsKeyUpdateNotify, enable)
+}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyLastCleanTime)
- if err != nil {
- logger.Warning(err)
- } else {
- s := v.Value().(string)
- c.LastCleanTime, err = time.Parse(configTimeLayout, s)
- if err != nil {
- logger.Warning(err)
- }
- }
+func (c *Config) SetAutoDownloadUpdates(enable bool) error {
+ c.AutoDownloadUpdates = enable
+ return c.save(dSettingsKeyAutoDownloadUpdates, enable)
+}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyLastCheckCacheSizeTime)
- if err != nil {
- logger.Warning(err)
- } else {
- s := v.Value().(string)
- c.LastCheckCacheSizeTime, err = time.Parse(configTimeLayout, s)
- if err != nil {
- logger.Warning(err)
- }
- }
+func (c *Config) SetAutoClean(enable bool) error {
+ c.AutoClean = enable
+ return c.save(dSettingsKeyAutoClean, enable)
+}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyRepository)
- if err != nil {
- logger.Warning(err)
- } else {
- c.Repository = v.Value().(string)
- }
+func (c *Config) SetIncrementalUpdate(enable bool) error {
+ c.IncrementalUpdate = enable
+ return c.save(dSettingsKeyIncrementalUpdate, enable)
+}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyMirrorsUrl)
- if err != nil {
- logger.Warning(err)
- } else {
- c.MirrorsUrl = v.Value().(string)
- }
+func (c *Config) UseIncrementalUpdate() bool {
+ return !c.IntranetUpdate && c.IncrementalUpdate
+}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyAllowInstallRemovePkgExecPaths)
- if err != nil {
- logger.Warning(err)
- } else {
- for _, s := range v.Value().([]dbus.Variant) {
- c.AllowInstallRemovePkgExecPaths = append(c.AllowInstallRemovePkgExecPaths, s.Value().(string))
- }
- }
+func (c *Config) SetMirrorSource(id string) error {
+ c.MirrorSource = id
+ return c.save(dSettingsKeyMirrorSource, id)
+}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyAutoInstallUpdates)
- if err != nil {
- logger.Warning(err)
- } else {
- c.AutoInstallUpdates = v.Value().(bool)
- }
+func (c *Config) SetAppstoreRegion(region string) error {
+ c.AppstoreRegion = region
+ return c.save(dSettingsKeyAppstoreRegion, region)
+}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyAutoInstallUpdateType)
- if err != nil {
- logger.Warning(err)
- } else {
- c.AutoInstallUpdateType = system.UpdateType(v.Value().(int64))
- }
+func (c *Config) SetUpdateMode(mode system.UpdateType) error {
+ c.UpdateMode = mode
+ return c.save(dSettingsKeyUpdateMode, mode)
+}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyAllowPostSystemUpgradeMessageVersion)
- if err != nil {
- logger.Warning(err)
- } else {
- for _, s := range v.Value().([]dbus.Variant) {
- c.AllowPostSystemUpgradeMessageVersion = append(c.AllowPostSystemUpgradeMessageVersion, s.Value().(string))
- }
- }
+func (c *Config) SetCheckUpdateMode(mode system.UpdateType) error {
+ c.CheckUpdateMode = mode
+ return c.save(dSettingsKeyCheckUpdateMode, mode)
+}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyUpgradeStatus)
- if err != nil {
- logger.Warning(err)
- } else {
- statusContent := v.Value().(string)
- err = json.Unmarshal([]byte(statusContent), &c.UpgradeStatus)
- if err != nil {
- logger.Warning(err)
- }
- }
+func (c *Config) SetCleanIntervalCacheOverLimit(duration time.Duration) error {
+ c.CleanIntervalCacheOverLimit = duration
+ return c.save(dSettingsKeyCleanIntervalCacheOverLimit, duration)
+}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyIdleDownloadConfig)
- if err != nil {
- logger.Warning(err)
- } else {
- c.IdleDownloadConfig = v.Value().(string)
- }
+func (c *Config) SetAutoInstallUpdates(autoInstall bool) error {
+ c.AutoInstallUpdates = autoInstall
+ return c.save(dSettingsKeyAutoInstallUpdates, autoInstall)
+}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeySystemSourceList)
- if err != nil {
- logger.Warning(err)
- } else {
- for _, s := range v.Value().([]dbus.Variant) {
- c.SystemSourceList = append(c.SystemSourceList, s.Value().(string))
- }
- }
+func (c *Config) SetAutoInstallUpdateType(updateType system.UpdateType) error {
+ c.AutoInstallUpdateType = updateType
+ return c.save(dSettingsKeyAutoInstallUpdateType, updateType)
+}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyNonUnknownList)
+func (c *Config) SetAllowPostSystemUpgradeMessageVersion(version []string) error {
+ c.AllowPostSystemUpgradeMessageVersion = version
+ return c.save(dSettingsKeyAllowPostSystemUpgradeMessageVersion, version)
+}
+
+func (c *Config) SetUpgradeStatusAndReason(status system.UpgradeStatusAndReason) error {
+ logger.Infof("Update UpgradeStatusAndReason to %+v", status)
+ c.UpgradeStatus = status
+ v, err := json.Marshal(status)
if err != nil {
logger.Warning(err)
- } else {
- for _, s := range v.Value().([]dbus.Variant) {
- c.NonUnknownList = append(c.NonUnknownList, s.Value().(string))
- }
}
+ return c.save(dSettingsKeyUpgradeStatus, string(v))
+}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyDownloadSpeedLimit)
- if err != nil {
- logger.Warning(err)
+func (c *Config) SetUseDSettings(use bool) error {
+ c.useDSettings = use
+ return c.save(dSettingsKeyUseDSettings, use)
+}
+
+func (c *Config) SetIdleDownloadConfig(idleConfig string) error {
+ c.IdleDownloadConfig = idleConfig
+ return c.save(dSettingsKeyIdleDownloadConfig, idleConfig)
+}
+
+func (c *Config) SetCheckInterval(interval time.Duration) error {
+ c.CheckInterval = interval
+ return c.save(dSettingsKeyCheckInterval, interval)
+}
+
+func (c *Config) SetCleanInterval(interval time.Duration) error {
+ c.CleanInterval = interval
+ return c.save(dSettingsKeyCleanInterval, interval)
+}
+
+func (c *Config) SetRepository(repository string) error {
+ c.Repository = repository
+ return c.save(dSettingsKeyRepository, repository)
+}
+
+func (c *Config) SetMirrorsUrl(mirrorsUrl string) error {
+ c.MirrorsUrl = mirrorsUrl
+ return c.save(dSettingsKeyMirrorsUrl, mirrorsUrl)
+}
+
+func (c *Config) SetAllowInstallRemovePkgExecPaths(paths []string) error {
+ c.AllowInstallRemovePkgExecPaths = paths
+ return c.save(dSettingsKeyAllowInstallRemovePkgExecPaths, paths)
+}
+
+// func (c *Config) SetNeedDownloadSize(size float64) error {
+// c.needDownloadSize = size
+// return c.save(dSettingsKeyNeedDownloadSize, size)
+// }
+
+func (c *Config) SetDownloadSpeedLimitConfig(config string) error {
+ c.DownloadSpeedLimitConfig = config
+ return c.save(dSettingsKeyDownloadSpeedLimit, config)
+}
+
+func (c *Config) SetLastoreDaemonStatus(status LastoreDaemonStatus) error {
+ c.statusMu.Lock()
+ c.lastoreDaemonStatus = status
+ c.statusMu.Unlock()
+ return c.save(DSettingsKeyLastoreDaemonStatus, status)
+}
+
+// UpdateLastoreDaemonStatus isSet: true 该位置1; false 该位清零
+func (c *Config) UpdateLastoreDaemonStatus(status LastoreDaemonStatus, isSet bool) error {
+ c.statusMu.Lock()
+ if isSet {
+ c.lastoreDaemonStatus |= status
} else {
- c.DownloadSpeedLimitConfig = v.Value().(string)
+ c.lastoreDaemonStatus &= ^status
}
+ c.statusMu.Unlock()
+ return c.save(DSettingsKeyLastoreDaemonStatus, c.lastoreDaemonStatus)
+}
- updateLastoreDaemonStatus := func() {
- v, err = c.dsLastoreManager.Value(0, DSettingsKeyLastoreDaemonStatus)
- if err != nil {
- logger.Warning(err)
- } else {
- c.lastoreDaemonStatus = LastoreDaemonStatus(v.Value().(int64))
- }
+func (c *Config) GetLastoreDaemonStatus() LastoreDaemonStatus {
+ c.statusMu.RLock()
+ defer c.statusMu.RUnlock()
+ return c.lastoreDaemonStatus
+}
+
+func (c *Config) GetLastoreDaemonStatusByBit(key LastoreDaemonStatus) LastoreDaemonStatus {
+ c.statusMu.RLock()
+ defer c.statusMu.RUnlock()
+ return c.lastoreDaemonStatus & key
+}
+
+func (c *Config) SetUpdateStatus(status string) error {
+ c.UpdateStatus = status
+ return c.save(dSettingsKeyUpdateStatus, status)
+}
+
+func (c *Config) SetInstallUpdateTime(delayed string) error {
+ c.UpdateTime = delayed
+ return c.save(dSettingsKeyUpdateTime, c.UpdateTime)
+}
+
+func (c *Config) SetSystemCustomSource(sources []string) error {
+ c.SystemCustomSource = sources
+ return c.save(dSettingsKeySystemCustomSource, sources)
+}
+
+func (c *Config) SetSecurityCustomSource(sources []string) error {
+ c.SecurityCustomSource = sources
+ return c.save(dSettingsKeySecurityCustomSource, sources)
+}
+
+func (c *Config) SetSystemRepoType(typ RepoType) error {
+ c.SystemRepoType = typ
+ return c.save(dSettingsKeySystemRepoType, typ)
+}
+
+func (c *Config) SetUpgradeDeliveryEnabled(enable bool) error {
+ c.UpgradeDeliveryEnabled = enable
+ return c.save(dSettingsKeyUpgradeDeliveryEnabled, enable)
+}
+
+func (c *Config) SetSecurityRepoType(typ RepoType) error {
+ c.SecurityRepoType = typ
+ return c.save(dSettingsKeySecurityRepoType, typ)
+}
+
+func (c *Config) SetCheckPolicyInterval(interval int) error {
+ c.CheckPolicyInterval = interval
+ return c.save(dSettingsKeyCheckPolicyInterval, interval)
+}
+
+func (c *Config) SetStartCheckRange(checkRange []int) error {
+ c.StartCheckRange = checkRange
+
+ // TODO: remove this after bug of dde-dconfig fixed
+ variants := make([]dbus.Variant, 0, len(checkRange))
+ for _, item := range checkRange {
+ variants = append(variants, dbus.MakeVariant(int64(item)))
}
- 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()
- }
- }
- })
+
+ return c.save(dSettingsKeyStartCheckRange, variants)
+}
+
+const (
+ onlineCachePath = "/tmp/platform_cache.json"
+ classifiedCachePath = "/tmp/classified_cache.json"
+)
+
+func (c *Config) SetClassifiedUpdatablePackages(pkgMap map[string][]string) error {
+ content, err := json.Marshal(pkgMap)
if err != nil {
logger.Warning(err)
+ return err
}
+ c.ClassifiedUpdatablePackages = pkgMap
+ return os.WriteFile(classifiedCachePath, content, 0644)
+}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyCheckUpdateMode)
- if err != nil {
- logger.Warning(err)
- } else {
- c.CheckUpdateMode = system.UpdateType(v.Value().(int64))
+func (c *Config) SetOnlineCache(cache string) error {
+ c.OnlineCache = cache
+ return os.WriteFile(onlineCachePath, []byte(cache), 0644)
+}
+
+func (c *Config) GetPlatformStatusDisable(status DisabledStatus) bool {
+ return c.PlatformDisabled&status == status
+}
+
+func (c *Config) ReloadConfig() error {
+ logger.Info("Reloading config from DSettings")
+ c.statusMu.Lock()
+ defer c.statusMu.Unlock()
+
+ if c.dsLastoreManager == nil {
+ logger.Warning("dsLastoreManager is nil, cannot reload config")
+ return errors.New("dsLastoreManager is nil")
}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyUpdateStatus)
+ c.reload()
+
+ system.IntranetUpdate = c.IntranetUpdate
+ logger.Info("Config reloaded successfully")
+ return nil
+}
+
+func (c *Config) reload() {
+ v, err := c.dsLastoreManager.Value(0, dSettingsKeyUseDSettings)
if err != nil {
- logger.Warning(err)
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyUseDSettings, err)
} else {
- c.UpdateStatus = v.Value().(string)
+ c.useDSettings = v.Value().(bool)
}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyPlatformUpdate)
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyVersion)
if err != nil {
- logger.Warning(err)
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyVersion, err)
} else {
- c.PlatformUpdate = v.Value().(bool)
+ c.Version = v.Value().(string)
}
- var url string
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyPlatformUrl)
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyAutoCheckUpdates)
if err != nil {
- logger.Warning(err)
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyAutoCheckUpdates, err)
} else {
- url = v.Value().(string)
+ c.AutoCheckUpdates = v.Value().(bool)
}
- c.PlatformUrl = url
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyPlatformRepoComponents)
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyDisableUpdateMetadata)
if err != nil {
- logger.Warning(err)
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyDisableUpdateMetadata, err)
} else {
- c.PlatformRepoComponents = v.Value().(string)
+ c.DisableUpdateMetadata = v.Value().(bool)
}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyPostUpgradeOnCalendar)
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyAutoDownloadUpdates)
if err != nil {
- logger.Warning(err)
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyAutoDownloadUpdates, err)
} else {
- c.PostUpgradeCron = v.Value().(string)
+ c.AutoDownloadUpdates = v.Value().(bool)
}
- var checkRange []int64
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyStartCheckRange)
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyAutoClean)
if err != nil {
- logger.Warning(err)
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyAutoClean, err)
} else {
- for _, s := range v.Value().([]dbus.Variant) {
- checkRange = append(checkRange, s.Value().(int64))
- }
+ c.AutoClean = v.Value().(bool)
}
- if len(checkRange) != 2 {
- c.StartCheckRange = []int{1800, 21600}
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyIncrementalUpdate)
+ if err != nil {
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyIncrementalUpdate, err)
} else {
- if checkRange[0] < checkRange[1] {
- c.StartCheckRange = []int{int(checkRange[0]), int(checkRange[1])}
- } else {
- c.StartCheckRange = []int{int(checkRange[1]), int(checkRange[0])}
- }
+ c.IncrementalUpdate = v.Value().(bool)
}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyIncludeDiskInfo)
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyIntranetUpdate)
if err != nil {
- logger.Warning(err)
- c.IncludeDiskInfo = true
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyIntranetUpdate, err)
} else {
- c.IncludeDiskInfo = v.Value().(bool)
+ c.IntranetUpdate = v.Value().(bool)
}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyUpdateTime)
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyMirrorSource)
if err != nil {
- logger.Warning(err)
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyMirrorSource, err)
} else {
- c.UpdateTime = v.Value().(string)
+ c.MirrorSource = v.Value().(string)
}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyPlatformDisabled)
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyUpdateNotify)
if err != nil {
- logger.Warning(err)
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyUpdateNotify, err)
} else {
- c.PlatformDisabled = DisabledStatus(v.Value().(int64))
+ c.UpdateNotify = v.Value().(bool)
}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyEnableVersionCheck)
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyCheckInterval)
if err != nil {
- logger.Warning(err)
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyCheckInterval, err)
} else {
- c.EnableVersionCheck = v.Value().(bool)
+ c.CheckInterval = time.Duration(v.Value().(int64))
}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyUpdateProcessUpload)
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyCleanInterval)
if err != nil {
- logger.Warning(err)
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyCleanInterval, err)
} else {
- c.UpdateProcessUpload = v.Value().(bool)
+ c.CleanInterval = time.Duration(v.Value().(int64))
}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyEnableCoreList)
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyUpdateMode)
if err != nil {
- logger.Warning(err)
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyUpdateMode, err)
} else {
- c.EnableCoreList = v.Value().(bool)
+ if (c.UpdateMode & system.OnlySecurityUpdate) != 0 {
+ c.UpdateMode &= ^system.OnlySecurityUpdate
+ c.UpdateMode |= system.SecurityUpdate
+ }
+ c.UpdateMode = system.UpdateType(v.Value().(int64))
}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyClientPackageName)
+
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyCleanIntervalCacheOverLimit)
if err != nil {
- logger.Warning(err)
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyCleanIntervalCacheOverLimit, err)
} else {
- c.ClientPackageName = v.Value().(string)
+ c.CleanIntervalCacheOverLimit = time.Duration(v.Value().(int64))
}
- updateUpgradeDeliveryEnabled := func() {
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyUpgradeDeliveryEnabled)
- if err != nil {
- logger.Warning(err)
- c.UpgradeDeliveryEnabled = false
- } else {
- c.UpgradeDeliveryEnabled = v.Value().(bool)
- }
- }
- updateUpgradeDeliveryEnabled()
- _, err = c.dsLastoreManager.ConnectValueChanged(func(key string) {
- switch key {
- case dSettingsKeyUpgradeDeliveryEnabled:
- updateUpgradeDeliveryEnabled()
- }
- })
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyAppstoreRegion)
if err != nil {
- logger.Warning(err)
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyAppstoreRegion, err)
+ } else {
+ c.AppstoreRegion = v.Value().(string)
}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeySystemCustomSource)
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyLastCheckTime)
if err != nil {
- logger.Warning(err)
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyLastCheckTime, err)
} else {
- for _, s := range v.Value().([]dbus.Variant) {
- c.SystemCustomSource = append(c.SystemCustomSource, s.Value().(string))
+ s := v.Value().(string)
+ c.LastCheckTime, err = time.Parse(configTimeLayout, s)
+ if err != nil {
+ logger.Warning("Failed to parse LastCheckTime")
}
}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeySecurityCustomSource)
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyLastCleanTime)
if err != nil {
- logger.Warning(err)
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyLastCleanTime, err)
} else {
- for _, s := range v.Value().([]dbus.Variant) {
- c.SecurityCustomSource = append(c.SecurityCustomSource, s.Value().(string))
+ s := v.Value().(string)
+ c.LastCleanTime, err = time.Parse(configTimeLayout, s)
+ if err != nil {
+ logger.Warning("Failed to parse LastCleanTime")
}
}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeySystemRepoType)
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyLastCheckCacheSizeTime)
if err != nil {
- logger.Warning(err)
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyLastCheckCacheSizeTime, err)
} else {
- c.SystemRepoType = RepoType(v.Value().(string))
+ s := v.Value().(string)
+ c.LastCheckCacheSizeTime, err = time.Parse(configTimeLayout, s)
+ if err != nil {
+ logger.Warning("Failed to parse LastCheckCacheSizeTime")
+ }
}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeySecurityRepoType)
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyRepository)
if err != nil {
- logger.Warning(err)
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyRepository, err)
} else {
- c.SecurityRepoType = RepoType(v.Value().(string))
+ c.Repository = v.Value().(string)
}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyGetHardwareIdByHelper)
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyMirrorsUrl)
if err != nil {
- logger.Warning(err)
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyMirrorsUrl, err)
} else {
- c.GetHardwareIdByHelper = v.Value().(bool)
+ c.MirrorsUrl = v.Value().(string)
}
- v, err = c.dsLastoreManager.Value(0, dSettingsKeyCheckPolicyInterval)
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyAllowInstallRemovePkgExecPaths)
if err != nil {
- logger.Warning(err)
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyAllowInstallRemovePkgExecPaths, err)
} else {
- if val, ok := v.Value().(int64); ok {
- c.CheckPolicyInterval = int(val)
- } else {
- logger.Warningf("dSettings key %s: value is not int64", dSettingsKeyCheckPolicyInterval)
+ c.AllowInstallRemovePkgExecPaths = []string{}
+ for _, s := range v.Value().([]dbus.Variant) {
+ c.AllowInstallRemovePkgExecPaths = append(c.AllowInstallRemovePkgExecPaths, s.Value().(string))
}
}
- err = c.recoveryAndApplyOemFlag(system.SystemUpdate)
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyAutoInstallUpdates)
if err != nil {
- logger.Warning(err)
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyAutoInstallUpdates, err)
+ } else {
+ c.AutoInstallUpdates = v.Value().(bool)
}
- err = c.recoveryAndApplyOemFlag(system.SecurityUpdate)
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyAutoInstallUpdateType)
if err != nil {
- logger.Warning(err)
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyAutoInstallUpdateType, err)
+ } else {
+ c.AutoInstallUpdateType = system.UpdateType(v.Value().(int64))
}
- // classifiedCachePath和onlineCachePath两项数据没有存储在dconfig中,是因为数据量太大,dconfig不支持存储这么长的数据
- content, err := os.ReadFile(classifiedCachePath)
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyAllowPostSystemUpgradeMessageVersion)
if err != nil {
- if !os.IsNotExist(err) {
- logger.Warning(err)
- }
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyAllowPostSystemUpgradeMessageVersion, err)
} else {
- c.ClassifiedUpdatablePackages = make(map[string][]string)
- err = json.Unmarshal(content, &c.ClassifiedUpdatablePackages)
- if err != nil {
- logger.Warning(err)
+ c.AllowPostSystemUpgradeMessageVersion = []string{}
+ for _, s := range v.Value().([]dbus.Variant) {
+ c.AllowPostSystemUpgradeMessageVersion = append(c.AllowPostSystemUpgradeMessageVersion, s.Value().(string))
}
}
- content, err = os.ReadFile(onlineCachePath)
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyUpgradeStatus)
if err != nil {
- if !os.IsNotExist(err) {
- logger.Warning(err)
- }
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyUpgradeStatus, err)
} else {
- c.OnlineCache = string(content)
- }
- c.OtherSourceList = append(c.OtherSourceList, "/etc/apt/sources.list.d/driver.list")
- c.SecuritySourceList = append(c.SecuritySourceList, system.SecuritySourceFile)
- return c
-}
-
-func (c *Config) json2DSettings(oldConfig *Config) {
- _ = c.UpdateLastCheckTime()
- _ = c.UpdateLastCleanTime()
- _ = c.UpdateLastCheckCacheSizeTime()
- _ = c.SetVersion(oldConfig.Version)
- _ = c.SetAutoCheckUpdates(oldConfig.AutoCheckUpdates)
- _ = c.SetDisableUpdateMetadata(oldConfig.DisableUpdateMetadata)
- _ = c.SetUpdateNotify(oldConfig.UpdateNotify)
- _ = c.SetAutoDownloadUpdates(oldConfig.AutoDownloadUpdates)
- _ = c.SetAutoClean(oldConfig.AutoClean)
- _ = c.SetMirrorSource(oldConfig.MirrorSource)
- _ = c.SetAppstoreRegion(oldConfig.AppstoreRegion)
- _ = c.SetUpdateMode(oldConfig.UpdateMode)
- _ = c.SetCleanIntervalCacheOverLimit(oldConfig.CleanIntervalCacheOverLimit)
- _ = c.SetAutoInstallUpdates(oldConfig.AutoInstallUpdates)
- _ = c.SetAutoInstallUpdateType(oldConfig.AutoInstallUpdateType)
- _ = c.SetAllowPostSystemUpgradeMessageVersion(append(oldConfig.AllowPostSystemUpgradeMessageVersion, c.AllowPostSystemUpgradeMessageVersion...))
- _ = c.SetCheckInterval(oldConfig.CheckInterval)
- _ = c.SetCleanInterval(oldConfig.CleanInterval)
- _ = 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{})) {
- if c.dsettingsChangedCbMap == nil {
- c.dsettingsChangedCbMap = make(map[string]func(LastoreDaemonStatus, interface{}))
+ statusContent := v.Value().(string)
+ err = json.Unmarshal([]byte(statusContent), &c.UpgradeStatus)
+ if err != nil {
+ logger.Warning("Failed to unmarshal upgrade status")
+ }
}
- c.dsettingsChangedCbMapMu.Lock()
- c.dsettingsChangedCbMap[key] = cb
- c.dsettingsChangedCbMapMu.Unlock()
-}
-
-func (c *Config) UpdateLastCheckTime() error {
- c.LastCheckTime = time.Now()
- return c.save(dSettingsKeyLastCheckTime, c.LastCheckTime.Format(configTimeLayout))
-}
-
-func (c *Config) UpdateLastCleanTime() error {
- c.LastCleanTime = time.Now()
- return c.save(dSettingsKeyLastCleanTime, c.LastCleanTime.Format(configTimeLayout))
-}
-
-func (c *Config) UpdateLastCheckCacheSizeTime() error {
- c.LastCheckCacheSizeTime = time.Now()
- return c.save(dSettingsKeyLastCheckCacheSizeTime, c.LastCheckCacheSizeTime.Format(configTimeLayout))
-}
-
-func (c *Config) SetVersion(version string) error {
- c.Version = version
- return c.save(dSettingsKeyVersion, version)
-}
-
-func (c *Config) SetAutoCheckUpdates(enable bool) error {
- c.AutoCheckUpdates = enable
- return c.save(dSettingsKeyAutoCheckUpdates, enable)
-}
-
-func (c *Config) SetDisableUpdateMetadata(disable bool) error {
- c.DisableUpdateMetadata = disable
- return c.save(dSettingsKeyDisableUpdateMetadata, disable)
-}
-
-func (c *Config) SetUpdateNotify(enable bool) error {
- c.UpdateNotify = enable
- return c.save(dSettingsKeyUpdateNotify, enable)
-}
-func (c *Config) SetAutoDownloadUpdates(enable bool) error {
- c.AutoDownloadUpdates = enable
- return c.save(dSettingsKeyAutoDownloadUpdates, enable)
-}
-
-func (c *Config) SetAutoClean(enable bool) error {
- c.AutoClean = enable
- return c.save(dSettingsKeyAutoClean, enable)
-}
-
-func (c *Config) SetIncrementalUpdate(enable bool) error {
- c.IncrementalUpdate = enable
- return c.save(dSettingsKeyIncrementalUpdate, enable)
-}
-
-func (c *Config) UseIncrementalUpdate() bool {
- return !c.IntranetUpdate && c.IncrementalUpdate
-}
-
-func (c *Config) SetMirrorSource(id string) error {
- c.MirrorSource = id
- return c.save(dSettingsKeyMirrorSource, id)
-}
-
-func (c *Config) SetAppstoreRegion(region string) error {
- c.AppstoreRegion = region
- return c.save(dSettingsKeyAppstoreRegion, region)
-}
-
-func (c *Config) SetUpdateMode(mode system.UpdateType) error {
- c.UpdateMode = mode
- return c.save(dSettingsKeyUpdateMode, mode)
-}
-
-func (c *Config) SetCheckUpdateMode(mode system.UpdateType) error {
- c.CheckUpdateMode = mode
- return c.save(dSettingsKeyCheckUpdateMode, mode)
-}
-
-func (c *Config) SetCleanIntervalCacheOverLimit(duration time.Duration) error {
- c.CleanIntervalCacheOverLimit = duration
- return c.save(dSettingsKeyCleanIntervalCacheOverLimit, duration)
-}
-
-func (c *Config) SetAutoInstallUpdates(autoInstall bool) error {
- c.AutoInstallUpdates = autoInstall
- return c.save(dSettingsKeyAutoInstallUpdates, autoInstall)
-}
-
-func (c *Config) SetAutoInstallUpdateType(updateType system.UpdateType) error {
- c.AutoInstallUpdateType = updateType
- return c.save(dSettingsKeyAutoInstallUpdateType, updateType)
-}
-
-func (c *Config) SetAllowPostSystemUpgradeMessageVersion(version []string) error {
- c.AllowPostSystemUpgradeMessageVersion = version
- return c.save(dSettingsKeyAllowPostSystemUpgradeMessageVersion, version)
-}
-
-func (c *Config) SetUpgradeStatusAndReason(status system.UpgradeStatusAndReason) error {
- logger.Infof("Update UpgradeStatusAndReason to %+v", status)
- c.UpgradeStatus = status
- v, err := json.Marshal(status)
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyIdleDownloadConfig)
if err != nil {
- logger.Warning(err)
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyIdleDownloadConfig, err)
+ } else {
+ c.IdleDownloadConfig = v.Value().(string)
}
- return c.save(dSettingsKeyUpgradeStatus, string(v))
-}
-
-func (c *Config) SetUseDSettings(use bool) error {
- c.useDSettings = use
- return c.save(dSettingsKeyUseDSettings, use)
-}
-func (c *Config) SetIdleDownloadConfig(idleConfig string) error {
- c.IdleDownloadConfig = idleConfig
- return c.save(dSettingsKeyIdleDownloadConfig, idleConfig)
-}
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeySystemSourceList)
+ if err != nil {
+ logger.Warningf("Failed to get %s: %v", dSettingsKeySystemSourceList, err)
+ } else {
+ c.SystemSourceList = []string{}
+ for _, s := range v.Value().([]dbus.Variant) {
+ c.SystemSourceList = append(c.SystemSourceList, s.Value().(string))
+ }
+ }
-func (c *Config) SetCheckInterval(interval time.Duration) error {
- c.CheckInterval = interval
- return c.save(dSettingsKeyCheckInterval, interval)
-}
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyNonUnknownList)
+ if err != nil {
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyNonUnknownList, err)
+ } else {
+ c.NonUnknownList = []string{}
+ for _, s := range v.Value().([]dbus.Variant) {
+ c.NonUnknownList = append(c.NonUnknownList, s.Value().(string))
+ }
+ }
-func (c *Config) SetCleanInterval(interval time.Duration) error {
- c.CleanInterval = interval
- return c.save(dSettingsKeyCleanInterval, interval)
-}
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyDownloadSpeedLimit)
+ if err != nil {
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyDownloadSpeedLimit, err)
+ } else {
+ c.DownloadSpeedLimitConfig = v.Value().(string)
+ }
-func (c *Config) SetRepository(repository string) error {
- c.Repository = repository
- return c.save(dSettingsKeyRepository, repository)
-}
+ v, err = c.dsLastoreManager.Value(0, DSettingsKeyLastoreDaemonStatus)
+ if err != nil {
+ logger.Warning(err)
+ } else {
+ c.lastoreDaemonStatus = LastoreDaemonStatus(v.Value().(int64))
+ }
-func (c *Config) SetMirrorsUrl(mirrorsUrl string) error {
- c.MirrorsUrl = mirrorsUrl
- return c.save(dSettingsKeyMirrorsUrl, mirrorsUrl)
-}
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyCheckUpdateMode)
+ if err != nil {
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyCheckUpdateMode, err)
+ } else {
+ c.CheckUpdateMode = system.UpdateType(v.Value().(int64))
+ }
-func (c *Config) SetAllowInstallRemovePkgExecPaths(paths []string) error {
- c.AllowInstallRemovePkgExecPaths = paths
- return c.save(dSettingsKeyAllowInstallRemovePkgExecPaths, paths)
-}
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyUpdateStatus)
+ if err != nil {
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyUpdateStatus, err)
+ } else {
+ c.UpdateStatus = v.Value().(string)
+ }
-// func (c *Config) SetNeedDownloadSize(size float64) error {
-// c.needDownloadSize = size
-// return c.save(dSettingsKeyNeedDownloadSize, size)
-// }
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyPlatformUpdate)
+ if err != nil {
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyPlatformUpdate, err)
+ } else {
+ c.PlatformUpdate = v.Value().(bool)
+ }
-func (c *Config) SetDownloadSpeedLimitConfig(config string) error {
- c.DownloadSpeedLimitConfig = config
- return c.save(dSettingsKeyDownloadSpeedLimit, config)
-}
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyPlatformUrl)
+ if err != nil {
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyPlatformUrl, err)
+ } else {
+ c.PlatformUrl = v.Value().(string)
+ }
-func (c *Config) SetLastoreDaemonStatus(status LastoreDaemonStatus) error {
- c.statusMu.Lock()
- c.lastoreDaemonStatus = status
- c.statusMu.Unlock()
- return c.save(DSettingsKeyLastoreDaemonStatus, status)
-}
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyPlatformRepoComponents)
+ if err != nil {
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyPlatformRepoComponents, err)
+ } else {
+ c.PlatformRepoComponents = v.Value().(string)
+ }
-// UpdateLastoreDaemonStatus isSet: true 该位置1; false 该位清零
-func (c *Config) UpdateLastoreDaemonStatus(status LastoreDaemonStatus, isSet bool) error {
- c.statusMu.Lock()
- if isSet {
- c.lastoreDaemonStatus |= status
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyPostUpgradeOnCalendar)
+ if err != nil {
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyPostUpgradeOnCalendar, err)
} else {
- c.lastoreDaemonStatus &= ^status
+ c.PostUpgradeCron = v.Value().(string)
}
- c.statusMu.Unlock()
- return c.save(DSettingsKeyLastoreDaemonStatus, c.lastoreDaemonStatus)
-}
-func (c *Config) GetLastoreDaemonStatus() LastoreDaemonStatus {
- c.statusMu.RLock()
- defer c.statusMu.RUnlock()
- return c.lastoreDaemonStatus
-}
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyStartCheckRange)
+ if err != nil {
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyStartCheckRange, err)
+ c.StartCheckRange = []int{1800, 21600}
+ } else {
+ for _, s := range v.Value().([]dbus.Variant) {
+ c.StartCheckRange = append(c.StartCheckRange, int(s.Value().(int64)))
+ }
-func (c *Config) GetLastoreDaemonStatusByBit(key LastoreDaemonStatus) LastoreDaemonStatus {
- c.statusMu.RLock()
- defer c.statusMu.RUnlock()
- return c.lastoreDaemonStatus & key
-}
+ if len(c.StartCheckRange) != 2 {
+ c.StartCheckRange = []int{1800, 21600}
+ }
-func (c *Config) SetUpdateStatus(status string) error {
- c.UpdateStatus = status
- return c.save(dSettingsKeyUpdateStatus, status)
-}
+ if c.StartCheckRange[0] > c.StartCheckRange[1] {
+ tmpValue := c.StartCheckRange[0]
+ c.StartCheckRange[0] = c.StartCheckRange[1]
+ c.StartCheckRange[1] = tmpValue
+ }
+ }
-func (c *Config) SetInstallUpdateTime(delayed string) error {
- c.UpdateTime = delayed
- return c.save(dSettingsKeyUpdateTime, c.UpdateTime)
-}
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyIncludeDiskInfo)
+ if err != nil {
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyIncludeDiskInfo, err)
+ } else {
+ c.IncludeDiskInfo = v.Value().(bool)
+ }
-func (c *Config) SetSystemCustomSource(sources []string) error {
- c.SystemCustomSource = sources
- return c.save(dSettingsKeySystemCustomSource, sources)
-}
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyUpdateTime)
+ if err != nil {
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyUpdateTime, err)
+ } else {
+ c.UpdateTime = v.Value().(string)
+ }
-func (c *Config) SetSecurityCustomSource(sources []string) error {
- c.SecurityCustomSource = sources
- return c.save(dSettingsKeySecurityCustomSource, sources)
-}
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyPlatformDisabled)
+ if err != nil {
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyPlatformDisabled, err)
+ } else {
+ c.PlatformDisabled = DisabledStatus(v.Value().(int64))
+ }
-func (c *Config) SetSystemRepoType(typ RepoType) error {
- c.SystemRepoType = typ
- return c.save(dSettingsKeySystemRepoType, typ)
-}
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyEnableVersionCheck)
+ if err != nil {
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyEnableVersionCheck, err)
+ } else {
+ c.EnableVersionCheck = v.Value().(bool)
+ }
-func (c *Config) SetUpgradeDeliveryEnabled(enable bool) error {
- c.UpgradeDeliveryEnabled = enable
- return c.save(dSettingsKeyUpgradeDeliveryEnabled, enable)
-}
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyUpdateProcessUpload)
+ if err != nil {
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyUpdateProcessUpload, err)
+ } else {
+ c.UpdateProcessUpload = v.Value().(bool)
+ }
-func (c *Config) SetSecurityRepoType(typ RepoType) error {
- c.SecurityRepoType = typ
- return c.save(dSettingsKeySecurityRepoType, typ)
-}
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyEnableCoreList)
+ if err != nil {
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyEnableCoreList, err)
+ } else {
+ c.EnableCoreList = v.Value().(bool)
+ }
-func (c *Config) SetCheckPolicyInterval(interval int) error {
- c.CheckPolicyInterval = interval
- return c.save(dSettingsKeyCheckPolicyInterval, interval)
-}
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyClientPackageName)
+ if err != nil {
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyClientPackageName, err)
+ } else {
+ c.ClientPackageName = v.Value().(string)
+ }
-func (c *Config) SetStartCheckRange(checkRange []int) error {
- c.StartCheckRange = checkRange
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyUpgradeDeliveryEnabled)
+ if err != nil {
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyUpgradeDeliveryEnabled, err)
+ } else {
+ c.UpgradeDeliveryEnabled = v.Value().(bool)
+ }
- // TODO: remove this after bug of dde-dconfig fixed
- variants := make([]dbus.Variant, 0, len(checkRange))
- for _, item := range checkRange {
- variants = append(variants, dbus.MakeVariant(int64(item)))
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeySystemCustomSource)
+ if err != nil {
+ logger.Warningf("Failed to get %s: %v", dSettingsKeySystemCustomSource, err)
+ } else {
+ c.SystemCustomSource = []string{}
+ for _, s := range v.Value().([]dbus.Variant) {
+ c.SystemCustomSource = append(c.SystemCustomSource, s.Value().(string))
+ }
}
- return c.save(dSettingsKeyStartCheckRange, variants)
-}
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeySecurityCustomSource)
+ if err != nil {
+ logger.Warningf("Failed to get %s: %v", dSettingsKeySecurityCustomSource, err)
+ } else {
+ c.SecurityCustomSource = []string{}
+ for _, s := range v.Value().([]dbus.Variant) {
+ c.SecurityCustomSource = append(c.SecurityCustomSource, s.Value().(string))
+ }
+ }
-const (
- onlineCachePath = "/tmp/platform_cache.json"
- classifiedCachePath = "/tmp/classified_cache.json"
-)
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeySystemRepoType)
+ if err != nil {
+ logger.Warningf("Failed to get %s: %v", dSettingsKeySystemRepoType, err)
+ } else {
+ c.SystemRepoType = RepoType(v.Value().(string))
+ }
-func (c *Config) SetClassifiedUpdatablePackages(pkgMap map[string][]string) error {
- content, err := json.Marshal(pkgMap)
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeySecurityRepoType)
if err != nil {
- logger.Warning(err)
- return err
+ logger.Warningf("Failed to get %s: %v", dSettingsKeySecurityRepoType, err)
+ } else {
+ c.SecurityRepoType = RepoType(v.Value().(string))
}
- c.ClassifiedUpdatablePackages = pkgMap
- return os.WriteFile(classifiedCachePath, content, 0644)
-}
-func (c *Config) SetOnlineCache(cache string) error {
- c.OnlineCache = cache
- return os.WriteFile(onlineCachePath, []byte(cache), 0644)
-}
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyGetHardwareIdByHelper)
+ if err != nil {
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyGetHardwareIdByHelper, err)
+ } else {
+ c.GetHardwareIdByHelper = v.Value().(bool)
+ }
-func (c *Config) GetPlatformStatusDisable(status DisabledStatus) bool {
- return c.PlatformDisabled&status == status
+ v, err = c.dsLastoreManager.Value(0, dSettingsKeyCheckPolicyInterval)
+ if err != nil {
+ logger.Warningf("Failed to get %s: %v", dSettingsKeyCheckPolicyInterval, err)
+ } else {
+ if val, ok := v.Value().(int64); ok {
+ c.CheckPolicyInterval = int(val)
+ } else {
+ logger.Warningf("dSettings key %s: value is not int64", dSettingsKeyCheckPolicyInterval)
+ }
+ }
}
func (c *Config) save(key string, v interface{}) error {
diff --git a/src/lastore-daemon/exported_methods_auto.go b/src/lastore-daemon/exported_methods_auto.go
index 3b8c6fff4..1b5e183c2 100644
--- a/src/lastore-daemon/exported_methods_auto.go
+++ b/src/lastore-daemon/exported_methods_auto.go
@@ -176,6 +176,10 @@ func (v *Manager) GetExportedMethods() dbusutil.ExportedMethods {
Fn: v.GetUpdateDetails,
InArgs: []string{"filename", "realtime"},
},
+ {
+ Name: "ReloadConfig",
+ Fn: v.ReloadConfig,
+ },
}
}
func (v *Updater) GetExportedMethods() dbusutil.ExportedMethods {
diff --git a/src/lastore-daemon/manager_ifc.go b/src/lastore-daemon/manager_ifc.go
index 907610f03..1c88dc108 100644
--- a/src/lastore-daemon/manager_ifc.go
+++ b/src/lastore-daemon/manager_ifc.go
@@ -710,3 +710,20 @@ func (m *Manager) GetUpdateDetails(sender dbus.Sender, fd dbus.UnixFD, realTime
}
return nil
}
+
+func (m *Manager) ReloadConfig(sender dbus.Sender) *dbus.Error {
+ m.service.DelayAutoQuit()
+
+ err := checkInvokePermission(m.service, sender)
+ if err != nil {
+ logger.Warning(err)
+ return dbusutil.ToError(err)
+ }
+
+ err = m.config.ReloadConfig()
+ if err != nil {
+ logger.Warningf("ReloadConfig failed: %v", err)
+ return dbusutil.ToError(err)
+ }
+ return nil
+}
diff --git a/usr/share/dbus-1/interfaces/org.deepin.dde.Lastore1.xml b/usr/share/dbus-1/interfaces/org.deepin.dde.Lastore1.xml
index ade709f71..df131cc6a 100644
--- a/usr/share/dbus-1/interfaces/org.deepin.dde.Lastore1.xml
+++ b/usr/share/dbus-1/interfaces/org.deepin.dde.Lastore1.xml
@@ -107,12 +107,14 @@
-
-
-
-
-
-
+
+
+
+
+
+
+
+