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
11 changes: 1 addition & 10 deletions src/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
17 changes: 12 additions & 5 deletions src/internal/dstore/dstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package dstore

import (
"errors"
"strings"
"time"

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions src/internal/mirrors/mirrors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion src/internal/system/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
)

const VarLibDir = "/var/lib/lastore"
const DefaultMirrorsUrl = "http://packages.deepin.com/mirrors/community.json"

type Status string

Expand Down
38 changes: 1 addition & 37 deletions src/internal/system/system_apt.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ lastore-daemon
package system

import (
"bufio"
"bytes"
"errors"
"fmt"
Expand Down Expand Up @@ -358,52 +357,17 @@ 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")
_ = os.Setenv("DEBCONF_NONINTERACTIVE_SEEN", "true")
_ = 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)
Expand Down
3 changes: 0 additions & 3 deletions src/internal/updateplatform/message_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/lastore-daemon/manager_unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 { // 更新禁用未开启且无忧还原未开启时
Expand Down
109 changes: 0 additions & 109 deletions src/lastore-smartmirror-daemon/lastore_smartmirror_daemon_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion src/lastore-tools/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion src/lastore-tools/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
Expand Down
4 changes: 2 additions & 2 deletions src/lastore-tools/smartmirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion var/lib/lastore/scripts/update_metadata_info
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down