Skip to content

Commit 4485329

Browse files
committed
feat: Support intranet update environment checks and notification
strategies - Added logic to determine intranet updates (IsPrivateLastore) and changed the method for obtaining update sources; - Implemented pre-checks for the update environment, executing scripts to verify and report results; - Added pre-check logic for backups; - Optimized cron job logic to use different trigger commands during intranet updates; - Adjusted notification sending logic to use专属 icons and expiration times for intranet updates; - Enriched update status workflow event reporting, covering stages such as backup, download, and installation; - Added error and status reporting at multiple points to ensure the update platform accurately captures status; - Introduced automated periodic event handling to enhance auto-update capabilities. Task: https://pms.uniontech.com/task-view-385321.html
1 parent f93d14c commit 4485329

12 files changed

Lines changed: 442 additions & 44 deletions

File tree

src/internal/system/system.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
)
1212

1313
const VarLibDir = "/var/lib/lastore"
14+
const IupPath = "/usr/lib/iup-daemon"
1415

1516
// TODO: Assign value later
1617
var IsPrivateLastore bool
@@ -57,8 +58,10 @@ const (
5758
)
5859

5960
const (
60-
NotifyExpireTimeoutDefault = -1
61-
NotifyExpireTimeoutNoHide = 0
61+
NotifyExpireTimeoutDefault = -1
62+
NotifyExpireTimeoutNoHide = 0
63+
NotifyExpireTimeoutPrivate = 10000
64+
NotifyExpireTimeoutPrivateLong = 600000
6265
)
6366

6467
type JobProgressInfo struct {

src/internal/system/update_type.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,15 @@ func UpdateOtherSystemSourceDir(otherSourceList []string) error {
305305
// CustomSourceWrapper 根据updateType组合source文件,doRealAction完成实际操作,unref用于释放资源
306306
func CustomSourceWrapper(updateType UpdateType, doRealAction func(path string, unref func()) error) error {
307307
var sourcePathList []string
308-
for _, t := range AllCheckUpdateType() {
309-
category := updateType & t
310-
if category != 0 {
311-
sourcePath := GetCategorySourceMap()[t]
312-
sourcePathList = append(sourcePathList, sourcePath)
308+
if IsPrivateLastore {
309+
sourcePathList = append(sourcePathList, SystemUpdateSource)
310+
} else {
311+
for _, t := range AllCheckUpdateType() {
312+
category := updateType & t
313+
if category != 0 {
314+
sourcePath := GetCategorySourceMap()[t]
315+
sourcePathList = append(sourcePathList, sourcePath)
316+
}
313317
}
314318
}
315319
// 由于103x版本兼容,检查更新时需要检查商店仓库
@@ -322,6 +326,9 @@ func CustomSourceWrapper(updateType UpdateType, doRealAction func(path string, u
322326
case 1:
323327
// 如果只有一个仓库,证明是单项的更新,可以直接使用默认的文件夹
324328
if doRealAction != nil {
329+
if IsPrivateLastore {
330+
return doRealAction(sourcePathList[0], nil)
331+
}
325332
return doRealAction(GetCategorySourceMap()[updateType], nil)
326333
}
327334
return errors.New("doRealAction is nil")

src/lastore-daemon/common.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ import (
2626
"github.com/linuxdeepin/dde-api/polkit"
2727
utils2 "github.com/linuxdeepin/go-lib/utils"
2828
"github.com/linuxdeepin/lastore-daemon/src/internal/config"
29+
. "github.com/linuxdeepin/lastore-daemon/src/internal/config"
2930
"github.com/linuxdeepin/lastore-daemon/src/internal/system"
3031
"github.com/linuxdeepin/lastore-daemon/src/internal/system/apt"
3132
"github.com/linuxdeepin/lastore-daemon/src/internal/utils"
32-
. "github.com/linuxdeepin/lastore-daemon/src/internal/config"
3333

3434
"github.com/godbus/dbus/v5"
3535
"github.com/linuxdeepin/go-lib/dbusutil"
@@ -39,6 +39,8 @@ import (
3939

4040
var _urlReg = regexp.MustCompile(`^[ ]*deb .*((?:https?|ftp|file|p2p)://[^ ]+)`)
4141

42+
const lastoreGatherInfo = "lastoreGatherInfo"
43+
4244
// 获取list文件或list.d文件夹中所有list文件的未被屏蔽的仓库地址
4345
func getUpgradeUrls(path string) []string {
4446
var upgradeUrls []string

src/lastore-daemon/dbusutil.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lastore-daemon/job.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"time"
1313

1414
"github.com/linuxdeepin/lastore-daemon/src/internal/system"
15+
"github.com/linuxdeepin/lastore-daemon/src/internal/updateplatform"
1516

1617
"github.com/linuxdeepin/go-lib/dbusutil"
1718
)
@@ -29,7 +30,8 @@ type Job struct {
2930
CreateTime int64
3031
DownloadSize int64
3132

32-
Type string
33+
Type string
34+
PolicyTyp int
3335

3436
Status system.Status
3537
caller methodCaller
@@ -119,6 +121,16 @@ func (j *Job) initDownloadSize() {
119121
j.PropsMu.Unlock()
120122
}
121123

124+
func (j *Job) setUpdatePolicy(policyTyp updateplatform.UpdateTp) {
125+
j.PropsMu.Lock()
126+
policy := int(policyTyp)
127+
if j.PolicyTyp != policy {
128+
j.PolicyTyp = policy
129+
_ = j.emitPropChangedUpdatePolicy(policy)
130+
}
131+
j.PropsMu.Unlock()
132+
}
133+
122134
func (j *Job) String() string {
123135
return fmt.Sprintf("Job{Id:%q:%q,Type:%q(%v,%v), %q(%.2f)}@%q",
124136
j.Id, j.Packages,

src/lastore-daemon/main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ func main() {
7373
if os.Getenv("DBUS_STARTER_BUS_TYPE") != "" {
7474
_ = os.Setenv("PATH", os.Getenv("PATH")+":/bin:/sbin:/usr/bin:/usr/sbin")
7575
}
76+
if system.IsPrivateLastore {
77+
go func() {
78+
out, err := exec.Command("/usr/bin/lastore-tools", "gatherinfo", "-type=post").CombinedOutput()
79+
if err != nil {
80+
logger.Warning(string(out))
81+
}
82+
}()
83+
}
7684

7785
config := NewConfig(path.Join(system.VarLibDir, "config.json"))
7886
aptImpl := dut.NewSystem(config.NonUnknownList, config.OtherSourceList, config.IncrementalUpdate)

src/lastore-daemon/manager.go

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ type Manager struct {
108108
checkDpkgCapabilityOnce sync.Once
109109
supportDpkgScriptIgnore bool
110110

111+
envIsValid bool
112+
preBackUpCheck bool
113+
111114
logFds []*os.File
112115
logFdsMu sync.Mutex
113116
logTmpFile *os.File
@@ -140,6 +143,8 @@ func NewManager(service *dbusutil.Service, updateApi system.System, c *config.Co
140143
abObj: abrecovery.NewABRecovery(service.Conn()),
141144
securitySourceConfig: make(UpdateSourceConfig),
142145
systemSourceConfig: make(UpdateSourceConfig),
146+
envIsValid: true,
147+
preBackUpCheck: true,
143148
}
144149
m.reloadOemConfig(true)
145150
m.signalLoop.Start()
@@ -149,8 +154,9 @@ func NewManager(service *dbusutil.Service, updateApi system.System, c *config.Co
149154
go m.handleOSSignal()
150155
m.updateJobList()
151156
m.initStatusManager()
152-
m.HardwareId = updateplatform.GetHardwareId(m.config.IncludeDiskInfo, m.config.GetHardwareIdByHelper)
153-
157+
go func() {
158+
m.setPropHardwareId(updateplatform.GetHardwareId(m.config.IncludeDiskInfo, m.config.GetHardwareIdByHelper))
159+
}()
154160
m.initDbusSignalListen()
155161
m.initDSettingsChangedHandle()
156162
m.syncThirdPartyDconfig()
@@ -160,10 +166,18 @@ func NewManager(service *dbusutil.Service, updateApi system.System, c *config.Co
160166
m.rebootTimeoutTimer = time.AfterFunc(600*time.Second, func() {
161167
// 启动后600s如果没有触发检查,那么上报更新失败
162168

169+
msg := "the check has not been triggered after reboot for 600 seconds"
163170
m.updatePlatform.PostStatusMessage(updateplatform.StatusMessage{
164171
Type: "error",
165-
Detail: "the check has not been triggered after reboot for 600 seconds",
172+
Detail: msg,
166173
}, true)
174+
procEvent := updateplatform.ProcessEvent{
175+
TaskID: 1,
176+
EventType: updateplatform.GetUpdateEvent,
177+
EventStatus: false,
178+
EventContent: msg,
179+
}
180+
m.updatePlatform.PostProcessEventMessage(procEvent)
167181

168182
err = m.delRebootCheckOption(all)
169183
if err != nil {
@@ -249,7 +263,8 @@ func (m *Manager) initAgent() {
249263

250264
func (m *Manager) initPlatformManager() {
251265
m.updatePlatform = updateplatform.NewUpdatePlatformManager(m.config, false)
252-
if isFirstBoot() {
266+
// TODO: 可能缺少 m.loadPlatformCache()
267+
if isFirstBoot() || system.IsPrivateLastore {
253268
// 不能阻塞初始化流程,防止dbus服务激活超时
254269
go m.updatePlatform.RetryPostHistory() // 此处调用还没有export以及dispatch job,因此可以判断是否需要check.
255270
}
@@ -654,6 +669,23 @@ func (m *Manager) categorySupportAutoInstall(category system.UpdateType) bool {
654669
return autoInstallUpdates && (autoInstallUpdateType&category != 0)
655670
}
656671

672+
// handleAutoCheckRegularlyEvent handles the regular automatic update check event.
673+
// It triggers a partial system upgrade when the system is in CanUpgrade state or
674+
// when local cache exists. The update platform type is set to UpdateRegularly
675+
// to indicate this is a scheduled regular update rather than a user-initiated one.
676+
func (m *Manager) handleAutoCheckRegularlyEvent() error {
677+
if m.statusManager.updateModeStatusObj[system.SystemUpgradeJobType] == system.CanUpgrade ||
678+
utils.IsFileExist(system.LocalCachePath) {
679+
m.updatePlatform.Tp = updateplatform.UpdateRegularly
680+
_, err := m.distUpgradePartly(dbus.Sender(m.service.Conn().Names()[0]), system.SystemUpdate, true)
681+
if err != nil {
682+
logger.Warning(err)
683+
return err
684+
}
685+
}
686+
return nil
687+
}
688+
657689
func (m *Manager) handleAutoCheckEvent() error {
658690
if m.config.AutoCheckUpdates && !m.ImmutableAutoRecovery {
659691
_, err := m.updateSource(dbus.Sender(m.service.Conn().Names()[0]))
@@ -835,8 +867,12 @@ const (
835867

836868
func (m *Manager) sendNotify(appName string, replacesId uint32, appIcon string, summary string, body string, actions []string, hints map[string]dbus.Variant, expireTimeout int32) uint32 {
837869
if !m.updater.UpdateNotify {
870+
logger.Info("UpdateNotify is false")
838871
return 0
839872
}
873+
if system.IsPrivateLastore {
874+
appIcon = "intranet-update-platform-notification"
875+
}
840876
agent := m.userAgents.getActiveLastoreAgent()
841877
if agent != nil {
842878
id, err := agent.SendNotify(0, appName, replacesId, appIcon, summary, body, actions, hints, expireTimeout)

src/lastore-daemon/manager_check.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,27 @@ func (m *Manager) checkUpgrade(sender dbus.Sender, checkMode system.UpdateType,
111111
},
112112
string(system.FailedStatus): func() error {
113113
m.updatePlatform.PostUpgradeStatus(uuid, updateplatform.UpgradeFailed, job.Description)
114+
// TODO 可能丢失调用 m.updatePlatform.SaveJobPostMsgByUUID(uuid, updateplatform.UpgradeFailed, job.Description)
114115
go func() {
115116
m.inhibitAutoQuitCountAdd()
116117
defer m.inhibitAutoQuitCountSub()
117118

119+
msg := fmt.Sprintf("%v postcheck error: %v", checkOrder.JobType(), job.Description)
118120
m.updatePlatform.PostStatusMessage(updateplatform.StatusMessage{
119121
Type: "error",
120122
UpdateType: checkOrder.JobType(),
121123
JobDescription: job.Description,
122-
Detail: fmt.Sprintf("%v postcheck error: %v", checkOrder.JobType(), job.Description),
124+
Detail: msg,
123125
}, false)
124126

127+
procEvent := updateplatform.ProcessEvent{
128+
TaskID: 1,
129+
EventType: updateplatform.CheckEnv,
130+
EventStatus: false,
131+
EventContent: msg,
132+
}
133+
m.updatePlatform.PostProcessEventMessage(procEvent)
134+
// TODO: 可能丢失调用 m.updatePlatform.PostSystemUpgradeMessage(uuid)
125135
m.reportLog(upgradeStatusReport, false, job.Description)
126136
}()
127137
inhibit(false)

0 commit comments

Comments
 (0)