diff --git a/src/internal/config/config.go b/src/internal/config/config.go index 5abb4586e..9c4fd6793 100644 --- a/src/internal/config/config.go +++ b/src/internal/config/config.go @@ -137,11 +137,6 @@ func NewConfig(configPath string) *Config { if dc.CheckInterval < MinCheckInterval { _ = dc.SetCheckInterval(MinCheckInterval) } - if dc.Repository == "" || dc.MirrorSource == "" { - info := system.DetectDefaultRepoInfo(system.RepoInfos) - _ = dc.SetRepository(info.Name) - _ = dc.SetMirrorSource("default") // info.Mirror - } if dc.Version == "" { _ = dc.SetVersion(ConfigVersion) _ = dc.SetCheckInterval(time.Hour * 24 * 7) @@ -499,11 +494,7 @@ func getConfigFromDSettings() *Config { } else { url = v.Value().(string) } - if len(url) == 0 { - c.PlatformUrl = "https://update-platform.uniontech.com" - } else { - c.PlatformUrl = url - } + c.PlatformUrl = url v, err = c.dsLastoreManager.Value(0, dSettingsKeyPlatformRepoComponents) if err != nil { diff --git a/src/internal/config/config_test.go b/src/internal/config/config_test.go index 9b932d47a..b30981847 100644 --- a/src/internal/config/config_test.go +++ b/src/internal/config/config_test.go @@ -26,7 +26,7 @@ func TestConfig(t *testing.T) { require.NoError(t, err) defer tmpfile.Close() - data := []byte(`{"Version":"0.1","AutoCheckUpdates":true,"DisableUpdateMetadata":false,"AutoDownloadUpdates":false,"AutoClean":true,"MirrorSource":"default","UpdateNotify":true,"CheckInterval":604800000000000,"CleanInterval":604800000000000,"UpdateMode":3,"CleanIntervalCacheOverLimit":86400000000000,"AppstoreRegion":"","LastCheckTime":"2021-06-17T14:10:21.896021304+08:00","LastCleanTime":"2021-06-17T09:18:31.515019638+08:00","LastCheckCacheSizeTime":"2021-06-17T09:18:31.5151104+08:00","Repository":"desktop","MirrorsUrl":"http://packages.deepin.com/mirrors/community.json","AllowInstallRemovePkgExecPaths":null}`) + data := []byte(`{"Version":"0.1","AutoCheckUpdates":true,"DisableUpdateMetadata":false,"AutoDownloadUpdates":false,"AutoClean":true,"MirrorSource":"default","UpdateNotify":true,"CheckInterval":604800000000000,"CleanInterval":604800000000000,"UpdateMode":3,"CleanIntervalCacheOverLimit":86400000000000,"AppstoreRegion":"","LastCheckTime":"2021-06-17T14:10:21.896021304+08:00","LastCleanTime":"2021-06-17T09:18:31.515019638+08:00","LastCheckCacheSizeTime":"2021-06-17T09:18:31.5151104+08:00","Repository":"desktop","MirrorsUrl":"","AllowInstallRemovePkgExecPaths":null}`) err = os.WriteFile(tmpfile.Name(), data, 0777) require.NoError(t, err) diff --git a/src/internal/dstore/dstore.go b/src/internal/dstore/dstore.go index e4c131b97..58355be79 100644 --- a/src/internal/dstore/dstore.go +++ b/src/internal/dstore/dstore.go @@ -5,6 +5,7 @@ package dstore import ( + "errors" "strings" "time" @@ -38,15 +39,15 @@ func NewStore() *Store { return s } -func (s *Store) GetMetadataServer() string { +func (s *Store) GetMetadataServer() (string, error) { var metadataServer string if s.sysCfg != nil { metadataServer = s.sysCfg.Section("General").Key("Server").String() } if metadataServer == "" { - metadataServer = "https://store.chinauos.com" + return "", errors.New("no metadata server") } - return metadataServer + return metadataServer, nil } type AppInfo struct { @@ -77,11 +78,17 @@ type packageApps map[string]*PackageInfo func (s *Store) GetPackageApplication(path string) (v []*PackageInfo, err error) { // cachePath := filepath.Join(system.VarLibDir, "packages.cache.json") cachePath := path + ".cache.json" - apiAppURL := s.GetMetadataServer() + "/api/public/packages" + server, err := s.GetMetadataServer() + if err != nil { + return nil, err + } + apiAppURL := server + "/api/public/packages" packages := make(packageApps) err = cacheFetchJSON(&packages, apiAppURL, cachePath, expireDelay) - + if err != nil { + return nil, err + } for dpk, app := range packages { app.PackageURI = dpk app.PackageName = strings.Replace(dpk, "dpk://deb/", "", -1) diff --git a/src/internal/mirrors/mirrors.go b/src/internal/mirrors/mirrors.go index 8672df108..6b3fc3cac 100644 --- a/src/internal/mirrors/mirrors.go +++ b/src/internal/mirrors/mirrors.go @@ -9,9 +9,11 @@ import ( "fmt" "net/http" "os" + "path" "path/filepath" "sort" + "github.com/linuxdeepin/lastore-daemon/src/internal/config" "github.com/linuxdeepin/lastore-daemon/src/internal/system" "github.com/linuxdeepin/lastore-daemon/src/internal/utils" ) @@ -92,6 +94,7 @@ func getUnpublishedMirrorSources(url string) ([]system.MirrorSource, error) { // LoadMirrorSources return supported MirrorSource from remote server func LoadMirrorSources(url string) ([]system.MirrorSource, error) { + config := config.NewConfig(path.Join("/var/lib/lastore", "config.json")) var mirrorsUrl string if url != "" { mirrorsUrl = url @@ -100,14 +103,14 @@ func LoadMirrorSources(url string) ([]system.MirrorSource, error) { data, err := os.ReadFile(filepath.Join(system.VarLibDir, "config.json")) if err != nil { if os.IsNotExist(err) { - mirrorsUrl = system.DefaultMirrorsUrl + mirrorsUrl = config.MirrorsUrl } else { return nil, err } } else { cfg := struct { MirrorsUrl string - }{system.DefaultMirrorsUrl} + }{config.MirrorsUrl} err = json.Unmarshal(data, &cfg) if err != nil { diff --git a/src/internal/system/system.go b/src/internal/system/system.go index d70123baf..19be75be3 100644 --- a/src/internal/system/system.go +++ b/src/internal/system/system.go @@ -11,7 +11,6 @@ import ( ) const VarLibDir = "/var/lib/lastore" -const DefaultMirrorsUrl = "http://packages.deepin.com/mirrors/community.json" type Status string diff --git a/src/internal/system/system_apt.go b/src/internal/system/system_apt.go index b57d5f35e..4c7e58838 100644 --- a/src/internal/system/system_apt.go +++ b/src/internal/system/system_apt.go @@ -9,7 +9,6 @@ lastore-daemon package system import ( - "bufio" "bytes" "errors" "fmt" @@ -358,16 +357,10 @@ func SystemArchitectures() ([]Architecture, error) { return r, nil } -var defaultRepoInfo = RepositoryInfo{ - Name: "desktop", - Url: "http://packages.deepin.com/deepin", - Mirror: "http://cdn.packages.deepin.com/deepin", -} - func init() { err := DecodeJson(path.Join(VarLibDir, "repository_info.json"), &RepoInfos) if err != nil { - RepoInfos = []RepositoryInfo{defaultRepoInfo} + RepoInfos = []RepositoryInfo{} } _ = os.Setenv("DEBIAN_FRONTEND", "noninteractive") _ = os.Setenv("DEBIAN_PRIORITY", "critical") @@ -375,35 +368,6 @@ func init() { _ = os.Setenv("IMMUTABLE_DISABLE_REMOUNT", "true") } -func DetectDefaultRepoInfo(rInfos []RepositoryInfo) RepositoryInfo { - f, err := os.Open("/etc/apt/sources.list") - if err != nil { - return defaultRepoInfo - } - defer func() { - _ = f.Close() - }() - - r := bufio.NewReader(f) - for { - bs, _, err := r.ReadLine() - if err != nil { - break - } - line := strings.TrimLeft(string(bs), " ") - if strings.IndexByte(line, '#') == 0 { - continue - } - - for _, repo := range rInfos { - if strings.Contains(line, " "+repo.Url+" ") { - return repo - } - } - } - return defaultRepoInfo -} - func guestBasePackageName(pkgId string) string { for _, sep := range []string{"-", ":", "_"} { index := strings.LastIndex(pkgId, sep) diff --git a/src/internal/updateplatform/message_report.go b/src/internal/updateplatform/message_report.go index a42d572e4..9e772570a 100644 --- a/src/internal/updateplatform/message_report.go +++ b/src/internal/updateplatform/message_report.go @@ -106,9 +106,6 @@ func NewUpdatePlatformManager(c *Config, updateToken bool) *UpdatePlatformManage platformUrl := c.PlatformUrl if len(platformUrl) == 0 { platformUrl = os.Getenv("UPDATE_PLATFORM_URL") - if len(platformUrl) == 0 { - platformUrl = "https://update-platform.uniontech.com" - } } if !utils.IsFileExist(CacheVersion) { diff --git a/src/lastore-daemon/manager_unit.go b/src/lastore-daemon/manager_unit.go index 897d73279..efebffff2 100644 --- a/src/lastore-daemon/manager_unit.go +++ b/src/lastore-daemon/manager_unit.go @@ -64,7 +64,7 @@ const ( type lastoreUnitMap map[UnitName][]string -// 定时任务和文件监听 +// 定时任务和文件监听map func (m *Manager) getLastoreSystemUnitMap() lastoreUnitMap { unitMap := make(lastoreUnitMap) if (m.config.GetLastoreDaemonStatus()&config.DisableUpdate) == 0 && !m.ImmutableAutoRecovery { // 更新禁用未开启且无忧还原未开启时 diff --git a/src/lastore-smartmirror-daemon/lastore_smartmirror_daemon_test.go b/src/lastore-smartmirror-daemon/lastore_smartmirror_daemon_test.go deleted file mode 100644 index 04dd7d626..000000000 --- a/src/lastore-smartmirror-daemon/lastore_smartmirror_daemon_test.go +++ /dev/null @@ -1,109 +0,0 @@ -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: GPL-3.0-or-later - -package main - -import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" -) - -var list = []string{ - "http://mirrors.163.com", - "http://mirror.cedia.org.ec", - "http://mirrors.hust.edu.cn", - "http://www.ftp.saix.net", - "http://deepin.ipacct.com", - "http://mirrors.up.pt", - "http://mirror.zetup.net", -} - -var mq = MirrorQuality{ - QualityMap: make(QualityMap), - reportList: make(chan []Report), -} - -var _ = Describe("LastoreSmartmirrorDaemon", func() { - It("sort list", func() { - mq.setQuality(list[0], &Quality{ - AverageDelay: 100, - DetectCount: 3, - }) - mq.setQuality(list[1], &Quality{ - AverageDelay: 50, - DetectCount: 2, - }) - mq.setQuality(list[2], &Quality{ - AverageDelay: 300, - DetectCount: 1, - }) - - result := []string{ - "http://www.ftp.saix.net", - "http://deepin.ipacct.com", - "http://mirrors.up.pt", - "http://mirror.zetup.net", - "http://mirrors.hust.edu.cn", - "http://mirror.cedia.org.ec", - "http://mirrors.163.com", - } - Expect(mq.mergeSort(list, mq.selectLessAccess)).To(Equal(result)) - - result = []string{ - "http://mirror.cedia.org.ec", - "http://mirrors.163.com", - "http://mirrors.hust.edu.cn", - "http://www.ftp.saix.net", - "http://deepin.ipacct.com", - "http://mirrors.up.pt", - "http://mirror.zetup.net", - } - Expect(mq.mergeSort(list, mq.compare)).To(Equal(result)) - }) - - // It("select mirror one", func() { - // result := []string{ - // "http://mirrors.163.com", - // "http://mirror.cedia.org.ec", - // "http://mirrors.hust.edu.cn", - // "http://www.ftp.saix.net", - // "http://deepin.ipacct.com", - // } - // Expect(mq.detectSelectMirror(list)).To(Equal(result)) - // }) - - // It("select mirror two", func() { - // result := []string{ - // "http://mirrors.up.pt", - // "http://mirror.zetup.net", - // "http://mirrors.163.com", - // "http://mirror.cedia.org.ec", - // "http://mirrors.hust.edu.cn", - // } - // Expect(mq.detectSelectMirror(list)).To(Equal(result)) - // }) - - // It("select mirror seven", func() { - // result := []string{ - // "http://mirrors.163.com", - // "http://mirror.cedia.org.ec", - // "http://mirrors.hust.edu.cn", - // "http://www.ftp.saix.net", - // "http://deepin.ipacct.com", - // } - // mq.detectSelectMirror(list) - // mq.detectSelectMirror(list) - // mq.detectSelectMirror(list) - // mq.detectSelectMirror(list) - // mq.detectSelectMirror(list) - // mq.detectSelectMirror(list) - // Expect(mq.detectSelectMirror(list)).To(Equal(result)) - // }) - - // It("SmartMirror init", func() { - // s := newSmartMirror(nil) - // // fmt.Println(s.mirrorQuality.sortSelectMirror(s.sourcesURL)) - // // fmt.Println(s.mirrorQuality.lessAccessSelectMirror(s.sourcesURL)) - // }) -}) diff --git a/src/lastore-tools/main.go b/src/lastore-tools/main.go index ffecb98f1..204516ed4 100644 --- a/src/lastore-tools/main.go +++ b/src/lastore-tools/main.go @@ -112,7 +112,7 @@ func main() { cli.StringFlag{ Name: "dstoreapi", Usage: "the dstore api server url. There has many jobs would use the to fetch data", - Value: "http://api.appstore.deepin.org", + Value: "", }, } app.Commands = []cli.Command{CMDUpdater, CMDTester, CMDSmartMirror, CMDMetadata, CMDQueryDesktop, CMDCheckPolicy, CMDPostUpgrade} diff --git a/src/lastore-tools/metadata.go b/src/lastore-tools/metadata.go index 3991e671d..c91c84015 100644 --- a/src/lastore-tools/metadata.go +++ b/src/lastore-tools/metadata.go @@ -37,7 +37,7 @@ var CMDMetadata = cli.Command{ }, cli.StringFlag{ Name: "remote", - Value: "http://cdn.packages.deepin.com/deepin/tree/lastore", + Value: "", Usage: "the remote to fetch metadata", }, }, diff --git a/src/lastore-tools/smartmirror.go b/src/lastore-tools/smartmirror.go index 086bc05d2..14283d454 100644 --- a/src/lastore-tools/smartmirror.go +++ b/src/lastore-tools/smartmirror.go @@ -21,7 +21,7 @@ var CMDSmartMirror = cli.Command{ Flags: []cli.Flag{ cli.StringFlag{ Name: "official", - Value: "http://packages.deepin.com/deepin", + Value: "", Usage: "the official package repository", }, cli.StringFlag{ @@ -121,7 +121,7 @@ func SubmainMirrorSynProgress(c *cli.Context) error { return err } -// appendSuffix 如果 r 没有后缀 suffix,则加上。 +// appendSuffix 如果 r 没有后缀 suffix,则加上。 func appendSuffix(r string, suffix string) string { if strings.HasSuffix(r, suffix) { return r diff --git a/var/lib/lastore/scripts/update_metadata_info b/var/lib/lastore/scripts/update_metadata_info index 40e5febad..703e1997f 100755 --- a/var/lib/lastore/scripts/update_metadata_info +++ b/var/lib/lastore/scripts/update_metadata_info @@ -3,7 +3,7 @@ # This script will be invoked by lastore-update-metadata-info.timer every 3 hours # 1. Trigger a apt-get update, so other component can update /var/lib/lastore/update_infos.json. # 2. Pull appstore.deepin.com's metadata by lastore-tools, -# inlcude a large ostree repo (http://packages.deepin.com/deepin/tree/lastore/) and some small json metadata. +# inlcude a large ostree repo and some small json metadata. function systemd_update_metadata_info() {