Skip to content

Commit b628192

Browse files
committed
fix: derive P2P update support from delivery repo prefix
Set P2PUpdateSupport based on whether the update repository uses the delivery:// prefix returned by the update platform. Preserve the server repository protocol when generating platform sources, and refresh P2P support after updating platform repository data. Bug: https://pms.uniontech.com/bug-view-356709.html
1 parent ceef1c2 commit b628192

File tree

5 files changed

+167
-10
lines changed

5 files changed

+167
-10
lines changed

src/internal/updateplatform/message_report.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,12 +1383,20 @@ func (m *UpdatePlatformManager) updateLogMetaSync() error {
13831383
}
13841384

13851385
func (m *UpdatePlatformManager) genDepositoryFromPlatform() {
1386-
var repos []string
1387-
for _, repo := range m.repoInfos {
1386+
repos := genPlatformReposFromRepoInfos(m.repoInfos, m.config.PlatformRepoComponents, m.config.UpgradeDeliveryEnabled, m.config.IntranetUpdate)
1387+
err := os.WriteFile(system.PlatFormSourceFile, []byte(strings.Join(repos, "\n")), 0644)
1388+
if err != nil {
1389+
logger.Warning("update source list file err")
1390+
}
1391+
1392+
}
13881393

1394+
func genPlatformReposFromRepoInfos(repoInfos []repoInfo, platformRepoComponents string, upgradeDeliveryEnabled bool, intranetUpdate bool) []string {
1395+
var repos []string
1396+
for _, repo := range repoInfos {
13891397
// If the public network has Delivery Optimization enabled,
13901398
// then it is necessary to change http(s):// to delivery://.
1391-
if m.config.UpgradeDeliveryEnabled && !m.config.IntranetUpdate {
1399+
if upgradeDeliveryEnabled && !intranetUpdate {
13921400
httpPrefix := "http://"
13931401
httpsPrefix := "https://"
13941402
deliveryPrefix := "delivery://"
@@ -1403,8 +1411,8 @@ func (m *UpdatePlatformManager) genDepositoryFromPlatform() {
14031411
prefix := "deb"
14041412
// v25上应该是这个
14051413
suffix := "main community commercial"
1406-
if m.config.PlatformRepoComponents != "" {
1407-
suffix = m.config.PlatformRepoComponents
1414+
if platformRepoComponents != "" {
1415+
suffix = platformRepoComponents
14081416
}
14091417
codeName := repo.CodeName
14101418
// 如果有cdn,则使用cdn,效率更高
@@ -1415,11 +1423,7 @@ func (m *UpdatePlatformManager) genDepositoryFromPlatform() {
14151423
repos = append(repos, fmt.Sprintf("%s %s %s %s", prefix, uri, codeName, suffix))
14161424
}
14171425
}
1418-
err := os.WriteFile(system.PlatFormSourceFile, []byte(strings.Join(repos, "\n")), 0644)
1419-
if err != nil {
1420-
logger.Warning("update source list file err")
1421-
}
1422-
1426+
return repos
14231427
}
14241428

14251429
func getAptAuthConf(domain string) (user, password string) {
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
2+
//
3+
// SPDX-License-Identifier: GPL-3.0-or-later
4+
5+
package updateplatform
6+
7+
import "testing"
8+
9+
func TestGenPlatformReposFromRepoInfosConvertsToDeliveryWhenDeliveryEnabled(t *testing.T) {
10+
repos := genPlatformReposFromRepoInfos([]repoInfo{
11+
{
12+
Uri: "https://professional-packages.chinauos.com/desktop-professional",
13+
CodeName: "eagle",
14+
},
15+
}, "main", true, false)
16+
17+
if len(repos) != 1 {
18+
t.Fatalf("len(repos) = %d, want 1", len(repos))
19+
}
20+
want := "deb delivery://professional-packages.chinauos.com/desktop-professional eagle main"
21+
if repos[0] != want {
22+
t.Fatalf("repos[0] = %q, want %q", repos[0], want)
23+
}
24+
}
25+
26+
func TestGenPlatformReposFromRepoInfosKeepsServerRepoPrefixWhenDeliveryDisabled(t *testing.T) {
27+
repos := genPlatformReposFromRepoInfos([]repoInfo{
28+
{
29+
Uri: "https://professional-packages.chinauos.com/desktop-professional",
30+
CodeName: "eagle",
31+
},
32+
}, "main", false, false)
33+
34+
if len(repos) != 1 {
35+
t.Fatalf("len(repos) = %d, want 1", len(repos))
36+
}
37+
want := "deb https://professional-packages.chinauos.com/desktop-professional eagle main"
38+
if repos[0] != want {
39+
t.Fatalf("repos[0] = %q, want %q", repos[0], want)
40+
}
41+
}
42+
43+
func TestGenPlatformReposFromRepoInfosKeepsServerRepoPrefixForIntranet(t *testing.T) {
44+
repos := genPlatformReposFromRepoInfos([]repoInfo{
45+
{
46+
Uri: "https://professional-packages.chinauos.com/desktop-professional",
47+
CodeName: "eagle",
48+
},
49+
}, "main", true, true)
50+
51+
if len(repos) != 1 {
52+
t.Fatalf("len(repos) = %d, want 1", len(repos))
53+
}
54+
want := "deb https://professional-packages.chinauos.com/desktop-professional eagle main"
55+
if repos[0] != want {
56+
t.Fatalf("repos[0] = %q, want %q", repos[0], want)
57+
}
58+
}
59+
60+
func TestGenPlatformReposFromRepoInfosKeepsDeliverySource(t *testing.T) {
61+
repos := genPlatformReposFromRepoInfos([]repoInfo{
62+
{
63+
Source: "deb delivery://professional-packages.chinauos.com/desktop-professional eagle main",
64+
},
65+
}, "", false, false)
66+
67+
if len(repos) != 1 {
68+
t.Fatalf("len(repos) = %d, want 1", len(repos))
69+
}
70+
want := "deb delivery://professional-packages.chinauos.com/desktop-professional eagle main"
71+
if repos[0] != want {
72+
t.Fatalf("repos[0] = %q, want %q", repos[0], want)
73+
}
74+
}

src/lastore-daemon/manager_update.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,9 @@ func (m *Manager) updateSource(sender dbus.Sender) (*Job, error) {
372372
return nil
373373
}
374374
}
375+
if m.updater != nil {
376+
m.updater.refreshUpgradeDeliveryService()
377+
}
375378
if updateplatform.IsForceUpdate(m.updatePlatform.Tp) && m.updatePlatform.Tp != updateplatform.UpdateRegularly {
376379
m.stopTimerUnit(lastoreRegularlyUpdate)
377380
}

src/lastore-daemon/updater.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
systemd1 "github.com/linuxdeepin/go-dbus-factory/system/org.freedesktop.systemd1"
2525
"github.com/linuxdeepin/go-lib/dbusutil"
2626
"github.com/linuxdeepin/go-lib/strv"
27+
utils2 "github.com/linuxdeepin/go-lib/utils"
2728
)
2829

2930
const (
@@ -126,6 +127,10 @@ func SetAPTSmartMirror(url string) error {
126127
}
127128

128129
func (u *Updater) refreshUpgradeDeliveryService() {
130+
if !updateSourceSupportsP2P("/var/lib/lastore/platform.list") {
131+
u.setPropP2PUpdateSupport(false)
132+
return
133+
}
129134
// 检查upgrade服务是否被正常安装
130135
_, err := u.service.NameHasOwner("org.deepin.upgradedelivery")
131136
if err != nil {
@@ -169,6 +174,15 @@ func (u *Updater) refreshUpgradeDeliveryService() {
169174
}
170175
}
171176

177+
func updateSourceSupportsP2P(sourcePath string) bool {
178+
if !utils2.IsFileExist(sourcePath) {
179+
return false
180+
}
181+
182+
data, err := os.ReadFile(sourcePath)
183+
return err == nil && strings.Contains(string(data), "delivery://")
184+
}
185+
172186
type LocaleMirrorSource struct {
173187
Id string
174188
Url string

src/lastore-daemon/updater_test.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
2+
//
3+
// SPDX-License-Identifier: GPL-3.0-or-later
4+
5+
package main
6+
7+
import (
8+
"os"
9+
"path/filepath"
10+
"testing"
11+
)
12+
13+
func TestUpdateSourceSupportsP2PFromDeliveryPrefix(t *testing.T) {
14+
tests := []struct {
15+
name string
16+
content string
17+
want bool
18+
}{
19+
{
20+
name: "delivery repo",
21+
content: "deb delivery://professional-packages.chinauos.com/desktop-professional eagle main\n",
22+
want: true,
23+
},
24+
{
25+
name: "delivery repo with apt options",
26+
content: "deb [trusted=yes] delivery://professional-packages.chinauos.com/desktop-professional eagle main\n",
27+
want: true,
28+
},
29+
{
30+
name: "http repo",
31+
content: "deb https://professional-packages.chinauos.com/desktop-professional eagle main\n",
32+
want: false,
33+
},
34+
{
35+
name: "commented delivery repo",
36+
content: "# deb delivery://professional-packages.chinauos.com/desktop-professional eagle main\ndeb https://professional-packages.chinauos.com/desktop-professional eagle main\n",
37+
want: false,
38+
},
39+
}
40+
41+
for _, tt := range tests {
42+
t.Run(tt.name, func(t *testing.T) {
43+
sourcePath := filepath.Join(t.TempDir(), "platform.list")
44+
if err := os.WriteFile(sourcePath, []byte(tt.content), 0644); err != nil {
45+
t.Fatal(err)
46+
}
47+
48+
got := updateSourceSupportsP2P(sourcePath)
49+
if got != tt.want {
50+
t.Fatalf("updateSourceSupportsP2P() = %v, want %v", got, tt.want)
51+
}
52+
})
53+
}
54+
}
55+
56+
func TestUpdateSourceSupportsP2PReturnsFalseForMissingSource(t *testing.T) {
57+
sourcePath := filepath.Join(t.TempDir(), "missing.list")
58+
59+
if updateSourceSupportsP2P(sourcePath) {
60+
t.Fatal("updateSourceSupportsP2P() = true, want false")
61+
}
62+
}

0 commit comments

Comments
 (0)