system

package
v0.0.0-...-434a8ce Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2024 License: GPL-3.0 Imports: 24 Imported by: 0

Documentation

Overview

This is system package manager need implement for porting lastore-daemon

Index

Constants

View Source
const (
	ExitSuccess = 0
	ExitFailure = 1
	ExitPause   = 2
)
View Source
const (
	GrubTitleRollbackPrefix = "BEGIN /etc/grub.d/11_deepin_ab_recovery"
	GrubTitleRollbackSuffix = "END /etc/grub.d/11_deepin_ab_recovery"
	GrubTitleNormalPrefix   = "BEGIN /etc/grub.d/10_linux"
	GrubTitleNormalSuffix   = "END /etc/grub.d/10_linux"
)
View Source
const (
	DownloadJobType           = "download"
	InstallJobType            = "install"
	OnlyInstallJobType        = "only_install"
	RemoveJobType             = "remove"
	UpdateJobType             = "update"
	DistUpgradeJobType        = "dist_upgrade"
	PrepareDistUpgradeJobType = "prepare_dist_upgrade"
	UpdateSourceJobType       = "update_source"
	CleanJobType              = "clean"
	FixErrorJobType           = "fix_error"
	CheckSystemJobType        = "check_system"
	OfflineUpdateJobType      = "offline_update"

	// UpgradeJobType 创建任务时会根据四种下载和安装类型,分别创建带有不同参数的下载和更新任务
	PrepareSystemUpgradeJobType   = "prepare_system_upgrade"
	PrepareAppStoreUpgradeJobType = "prepare_appstore_upgrade"
	PrepareSecurityUpgradeJobType = "prepare_security_upgrade"
	PrepareUnknownUpgradeJobType  = "prepare_unknown_upgrade"
	SystemUpgradeJobType          = "system_upgrade"
	AppStoreUpgradeJobType        = "appstore_upgrade"
	SecurityUpgradeJobType        = "security_upgrade"
	UnknownUpgradeJobType         = "unknown_upgrade"
	OfflineUpgradeJobType         = "offline_update"
	OtherUpgradeJobType           = "other_system_update"
	AppendUpgradeJobTye           = "append_upgrade"
)
View Source
const (
	NotifyExpireTimeoutDefault = -1
	NotifyExpireTimeoutNoHide  = 0
)
View Source
const (
	LastoreAptOrgConfPath      = "/var/lib/lastore/apt.conf"
	LastoreAptV2ConfPath       = "/var/lib/lastore/apt_v2.conf"
	LastoreAptV2CommonConfPath = "/var/lib/lastore/apt_v2_common.conf" // 该配置指定了通过lastore更新的deb包缓存路径
)
View Source
const (
	DutOnlineMetaConfPath  = "/var/lib/lastore/online_meta.json"  // 在线更新元数据
	DutOfflineMetaConfPath = "/var/lib/lastore/offline_meta.json" // 离线更新元数据
)
View Source
const (
	OnlineListPath  = "/var/lib/apt/lists"
	OfflineListPath = "/var/lib/lastore/offline_list"
)
View Source
const (
	OriginSourceFile = "/etc/apt/sources.list"
	OriginSourceDir  = "/etc/apt/sources.list.d"

	AppStoreList       = "appstore.list"
	UnstableSourceList = "deepin-unstable-source.list"
	HweSourceList      = "hwe.list"
	DriverList         = "driver.list"
	SecurityList       = "security.list"

	AppStoreSourceFile = "/etc/apt/sources.list.d/" + AppStoreList
	UnstableSourceFile = "/etc/apt/sources.list.d/" + UnstableSourceList
	HweSourceFile      = "/etc/apt/sources.list.d/" + HweSourceList
	SecuritySourceFile = "/etc/apt/sources.list.d/" + SecurityList

	SoftLinkSystemSourceDir = "/var/lib/lastore/SystemSource.d" // 系统更新仓库
	SecuritySourceDir       = "/var/lib/lastore/SecuritySource.d"
	PlatFormSourceFile      = "/var/lib/lastore/platform.list"            // 从更新平台获取的仓库,为系统更新仓库,在message_report.go 中的 获取升级版本信息genUpdatePolicyByToken后即可 更新
	UnknownSourceDir        = "/var/lib/lastore/unknownSource.d"          // 未知来源更新的源个数不定,需要创建软链接放在同一目录内
	OtherSystemSourceDir    = "/var/lib/lastore/otherSystemSource.d"      // 其他需要检查的系统仓库
	OfflineSourceFile       = "/var/lib/lastore/offline.list"             // 在offline_repo.go 中的 UpdateOfflineSourceFile 更新
	AppendSourceDir         = "/etc/deepin/lastore-daemon/sources.list.d" // 追加仓库的路径
)
View Source
const (
	LastoreSourcesPath = "/var/lib/lastore/sources.list"   // 历史版本遗留,已废弃
	CustomSourceDir    = "/var/lib/lastore/sources.list.d" // 历史版本遗留,已废弃
)
View Source
const DefaultMirrorsUrl = "http://packages.deepin.com/mirrors/community.json"
View Source
const (
	LocalCachePath = "/var/cache/lastore/archives"
)
View Source
const NotFoundErrorMsg = "not found resource: "
View Source
const SizeDownloaded = 0
View Source
const SizeUnknown = -1
View Source
const VarLibDir = "/var/lib/lastore"

Variables

View Source
var NotSupportError = errors.New("not support operation")
View Source
var RepoInfos []RepositoryInfo
View Source
var ResourceExitError = errors.New("resource exists")
View Source
var SystemUpdateSource = SoftLinkSystemSourceDir

Functions

func CheckInstallAddSize

func CheckInstallAddSize(updateType UpdateType) bool

func CheckLock

func CheckLock(p string) (string, bool)

func CustomSourceWrapper

func CustomSourceWrapper(updateType UpdateType, doRealAction func(path string, unref func()) error) error

CustomSourceWrapper 根据updateType组合source文件,doRealAction完成实际操作,unref用于释放资源

func DecodeJson

func DecodeJson(fpath string, d interface{}) error

func EncodeJson

func EncodeJson(fpath string, d interface{}) error

func GetAppStoreAppName

func GetAppStoreAppName() string

func GetArchivesDir

func GetArchivesDir(configPath string) (string, error)

$ apt-config --format '%f=%v%n' dump Dir Dir=/ Dir::Cache=var/cache/apt Dir::Cache::archives=archives/ Dir::Cache::srcpkgcache=srcpkgcache.bin Dir::Cache::pkgcache=pkgcache.bin

func GetCategorySourceMap

func GetCategorySourceMap() map[UpdateType]string

GetCategorySourceMap 缺省更新类型与对应仓库的map

func GetGrubNormalTitle

func GetGrubNormalTitle(grubPath string) string

func GetGrubRollbackTitle

func GetGrubRollbackTitle(grubPath string) string

func HandleDelayPackage

func HandleDelayPackage(hold bool, packages []string)

func IsActiveCodeExist

func IsActiveCodeExist() bool

func IsAuthorized

func IsAuthorized() bool

func ListPackageFile

func ListPackageFile(packages ...string) []string

ListPackageFile list files path contained in the packages

func NormalFileExists

func NormalFileExists(fpath string) bool

func QueryFileCacheSize

func QueryFileCacheSize(path string) (float64, error)

QueryFileCacheSize parsing the file total size(kb) of the path

func QueryPackageDependencies

func QueryPackageDependencies(pkgId string) []string

QueryPackageDependencies return the directly dependencies

func QueryPackageDownloadSize

func QueryPackageDownloadSize(updateType UpdateType, packages ...string) (float64, float64, error)

QueryPackageDownloadSize parsing the total size of download archives when installing the packages. return arg0:需要下载的量;arg1:所有包的大小;arg2:error

func QueryPackageInstallable

func QueryPackageInstallable(pkgId string) bool

QueryPackageInstallable query whether the pkgId can be installed

func QueryPackageInstalled

func QueryPackageInstalled(pkgId string) bool

QueryPackageInstalled query whether the pkgId installed

func QuerySourceAddSize

func QuerySourceAddSize(updateType UpdateType) (float64, error)

func QuerySourceDownloadSize

func QuerySourceDownloadSize(updateType UpdateType, pkgList []string) (float64, float64, error)

QuerySourceDownloadSize 根据更新类型(仓库),获取需要的下载量,return arg0:需要下载的量;arg1:所有包的大小;arg2:error

func SetSystemUpdate

func SetSystemUpdate(platform bool)

func UpdateOtherSystemSourceDir

func UpdateOtherSystemSourceDir(otherSourceList []string) error

UpdateOtherSystemSourceDir otherSourceList 需要list文件的绝对路径

func UpdateSecurityDefaultSourceDir

func UpdateSecurityDefaultSourceDir(sourceList []string) error

func UpdateSourceDirUseUrl

func UpdateSourceDirUseUrl(updateType UpdateType, repoUrl []string, fileName string, annotation string) error

func UpdateSystemDefaultSourceDir

func UpdateSystemDefaultSourceDir(sourceList []string) error

UpdateSystemDefaultSourceDir systemSourceList需要list文件的绝对路径;更新系统仓库文件夹,如果从更新平台获取系统仓库,那么不需要调用这里

func UpdateUnknownSourceDir

func UpdateUnknownSourceDir(nonUnknownList strv.Strv) error

UpdateUnknownSourceDir 更新未知来源仓库文件夹

Types

type ABErrorType

type ABErrorType string
const (
	NoABError    ABErrorType = "noError"
	CanNotBackup ABErrorType = "canNotBackup"
	OtherError   ABErrorType = "otherError"
)

type ABStatus

type ABStatus string
const (
	NotBackup ABStatus = "notBackup"
	// NotSupportBackup ABStatus = "notSupportBackup"
	BackingUp    ABStatus = "backingUp"
	BackupFailed ABStatus = "backupFailed"
	HasBackedUp  ABStatus = "hasBackedUp"
)

type Architecture

type Architecture string

func SystemArchitectures

func SystemArchitectures() ([]Architecture, error)

SystemArchitectures return the system package manager supported architectures

type Command

type Command struct {
	JobId      string
	Cancelable bool

	CmdSet CommandSet

	Cmd *exec.Cmd

	ExitCode int

	Indicator         Indicator
	ParseProgressInfo ParseProgressInfo
	ParseJobError     ParseJobError

	Stdout   bytes.Buffer
	Stderr   bytes.Buffer
	AtExitFn func() bool
	// contains filtered or unexported fields
}

func (*Command) Abort

func (c *Command) Abort() error

func (*Command) AbortWithFailed

func (c *Command) AbortWithFailed() error

func (*Command) IndicateFailed

func (c *Command) IndicateFailed(errType JobErrorType, errDetail string, isFatalErr bool)

func (*Command) SetEnv

func (c *Command) SetEnv(envVarMap map[string]string)

func (*Command) Start

func (c *Command) Start() error

func (*Command) String

func (c *Command) String() string

func (*Command) Wait

func (c *Command) Wait() (err error)

type CommandSet

type CommandSet interface {
	AddCMD(cmd *Command)
	RemoveCMD(id string)
	FindCMD(id string) *Command
}

type Indicator

type Indicator func(JobProgressInfo)

type JobError

type JobError struct {
	ErrType      JobErrorType
	ErrDetail    string
	IsCheckError bool
	ErrorLog     []string
}

func (*JobError) Error

func (e *JobError) Error() string

func (*JobError) GetDetail

func (e *JobError) GetDetail() string

func (*JobError) GetType

func (e *JobError) GetType() string

type JobErrorType

type JobErrorType string
const (
	NoError                      JobErrorType = "NoError"
	ErrorUnknown                 JobErrorType = "ErrorUnknown"
	ErrorProgram                 JobErrorType = "ErrorProgram"
	ErrorFetchFailed             JobErrorType = "fetchFailed"
	ErrorDpkgError               JobErrorType = "dpkgError"
	ErrorPkgNotFound             JobErrorType = "pkgNotFound"
	ErrorDpkgInterrupted         JobErrorType = "dpkgInterrupted"
	ErrorDependenciesBroken      JobErrorType = "dependenciesBroken"
	ErrorUnmetDependencies       JobErrorType = "unmetDependencies"
	ErrorNoInstallationCandidate JobErrorType = "noInstallationCandidate"
	ErrorInsufficientSpace       JobErrorType = "insufficientSpace"
	ErrorUnauthenticatedPackages JobErrorType = "unauthenticatedPackages"
	ErrorOperationNotPermitted   JobErrorType = "operationNotPermitted"
	ErrorIndexDownloadFailed     JobErrorType = "IndexDownloadFailed"
	ErrorIO                      JobErrorType = "ioError"
	ErrorDamagePackage           JobErrorType = "damagePackage" // 包损坏,需要删除后重新下载或者安装
	ErrorInvalidSourcesList      JobErrorType = "invalidSourceList"
	ErrorPlatformUnreachable     JobErrorType = "platformUnreachable"
	ErrorOfflineCheck            JobErrorType = "offlineCheckError"

	ErrorMissCoreFile  JobErrorType = "missCoreFile"
	ErrorScript        JobErrorType = "scriptError"
	ErrorProgressCheck JobErrorType = "progressCheckError"

	// running状态
	ErrorNeedCheck JobErrorType = "needCheck"
)

func (JobErrorType) String

func (j JobErrorType) String() string

type JobProgressInfo

type JobProgressInfo struct {
	JobId       string
	Progress    float64
	Description string
	Status      Status
	Cancelable  bool
	Error       *JobError
	FatalError  bool
}

type MirrorSource

type MirrorSource struct {
	Id   string `json:"id"`
	Name string `json:"name"`
	Url  string `json:"url"`

	NameLocale  map[string]string `json:"name_locale"`
	Weight      int               `json:"weight"`
	Country     string            `json:"country"`
	AdjustDelay int               `json:"adjust_delay"` // ms
}

type NotFoundErrorType

type NotFoundErrorType string

func NotFoundError

func NotFoundError(w string) NotFoundErrorType

func (NotFoundErrorType) Error

func (e NotFoundErrorType) Error() string

type PackageInfo

type PackageInfo struct {
	Name    string `json:"name"`    // "软件包名"
	Version string `json:"version"` // "软件包版本"
	Need    string `json:"need"`    // 严格程度;strict:严格匹配,skipstate:忽略状态,skipversion:忽略版本,exist:存在即可
}

type ParseJobError

type ParseJobError func(stdErrStr string, stdOutStr string) *JobError

type ParseProgressInfo

type ParseProgressInfo func(id, line string) (JobProgressInfo, error)

type PlatformPackageInfo

type PlatformPackageInfo struct {
	Name           string    `json:"name"`    // "软件包名"
	AllArchVersion []Version `json:"version"` // "软件包版本"
	Need           string    `json:"need"`    // 严格程度;strict:严格匹配,skipstate:忽略状态,skipversion:忽略版本,exist:存在即可
}

type RepositoryInfo

type RepositoryInfo struct {
	Name   string `json:"name"`
	Url    string `json:"url"`
	Mirror string `json:"mirror"`
}

func DetectDefaultRepoInfo

func DetectDefaultRepoInfo(rInfos []RepositoryInfo) RepositoryInfo

type SourceUpgradeInfoMap

type SourceUpgradeInfoMap map[string][]UpgradeInfo

type Status

type Status string
const (
	ReadyStatus   Status = "ready"
	RunningStatus Status = "running"
	FailedStatus  Status = "failed"
	SucceedStatus Status = "succeed"
	PausedStatus  Status = "paused"
	EndStatus     Status = "end"
)

type System

type System interface {
	DownloadPackages(jobId string, packages []string, environ map[string]string, cmdArgs map[string]string) error
	DownloadSource(jobId string, packages []string, environ map[string]string, cmdArgs map[string]string) error
	Install(jobId string, packages []string, environ map[string]string, cmdArgs map[string]string) error
	Remove(jobId string, packages []string, environ map[string]string) error
	DistUpgrade(jobId string, packages []string, environ map[string]string, cmdArgs map[string]string) error
	UpdateSource(jobId string, environ map[string]string, cmdArgs map[string]string) error
	Clean(jobId string) error
	Abort(jobId string) error
	AbortWithFailed(jobId string) error
	AttachIndicator(Indicator)
	FixError(jobId string, errType string, environ map[string]string, cmdArgs map[string]string) error
	CheckSystem(jobId string, checkType string, environ map[string]string, cmdArgs map[string]string) error
}

type UiActiveState

type UiActiveState int32
const (
	Unknown         UiActiveState = -1 // 未知
	Unauthorized    UiActiveState = 0  // 未授权
	Authorized      UiActiveState = 1  // 已授权
	AuthorizedLapse UiActiveState = 2  // 授权失效
	TrialAuthorized UiActiveState = 3  // 试用期已授权
	TrialExpired    UiActiveState = 4  // 试用期已过期
)

type UpdateInfoError

type UpdateInfoError struct {
	Type   string
	Detail string
}

func (*UpdateInfoError) Error

func (err *UpdateInfoError) Error() string

type UpdateModeStatus

type UpdateModeStatus string
const (
	NoUpdate       UpdateModeStatus = "noUpdate"    // 无更新
	NotDownload    UpdateModeStatus = "notDownload" // 包含了有更新没下载
	IsDownloading  UpdateModeStatus = "isDownloading"
	DownloadPause  UpdateModeStatus = "downloadPause"
	DownloadErr    UpdateModeStatus = "downloadFailed"
	CanUpgrade     UpdateModeStatus = "downloaded"   // Downloaded
	WaitRunUpgrade UpdateModeStatus = "upgradeReady" // 进行备份+更新时,当处于更新未开始状态
	Upgrading      UpdateModeStatus = "upgrading"
	UpgradeErr     UpdateModeStatus = "upgradeFailed"
	Upgraded       UpdateModeStatus = "needReboot" // need reboot
)

type UpdateType

type UpdateType uint64
const (
	SystemUpdate       UpdateType = 1 << 0 // 系统仓库更新,检查该仓库,显示更新内容
	AppStoreUpdate     UpdateType = 1 << 1 // 应用仓库更新,检查该仓库,不显示更新内容
	SecurityUpdate     UpdateType = 1 << 2 // 安全仓库更新,检查该仓库,显示更新内容
	UnknownUpdate      UpdateType = 1 << 3 // 未知来源仓库更新:排除 系统、商店、安全、驱动、hwe仓库的其他仓库,不检查该仓库,不显示更新内容
	OnlySecurityUpdate UpdateType = 1 << 4 // 仅安全仓库更新,已经废弃,用于处理历史版本升级后的兼容问题
	OtherSystemUpdate  UpdateType = 1 << 5 // 其他来源系统的仓库更新:对应dconfig non-unknown-sources 字段去掉商店和安全仓库,通常为驱动、hwe仓库(hwe仓库应该从平台获取),检查该仓库,不显示更新内容

	AllCheckUpdate   = SystemUpdate | AppStoreUpdate | SecurityUpdate | UnknownUpdate | OtherSystemUpdate | AppendUpdate // 所有需要检查的仓库 TODO 该字段变动,需要检查所有使用者
	AllInstallUpdate = SystemUpdate | SecurityUpdate | UnknownUpdate                                                     // 所有控制中心需要显示的仓库

	OfflineUpdate UpdateType = 1 << 6 // 离线仓库,控制中心不检查、不显示;离线更新工具检查和显示;
	AppendUpdate  UpdateType = 1 << 7 // 追加仓库/etc/deepin/lastore-daemon/sources.list.d/ 用于打印管理追加离线包.检查该仓库,不显示更新内容
)

用于设置UpdateMode属性,最大支持64位

func AllCheckUpdateType

func AllCheckUpdateType() []UpdateType

AllCheckUpdateType 对应 system.AllCheckUpdate

func AllInstallUpdateType

func AllInstallUpdateType() []UpdateType

AllInstallUpdateType 对应 system.AllInstallUpdate

func AllUpdateType

func AllUpdateType() []UpdateType

func UpdateTypeBitToArray

func UpdateTypeBitToArray(mode UpdateType) []UpdateType

func (UpdateType) JobType

func (m UpdateType) JobType() string

type UpgradeInfo

type UpgradeInfo struct {
	Package        string
	CurrentVersion string
	LastVersion    string
	ChangeLog      string
	Category       string
}

type UpgradeStatus

type UpgradeStatus string

UpgradeStatus 整体更新安装的流程状态

const (
	UpgradeReady   UpgradeStatus = "ready"
	UpgradeRunning UpgradeStatus = "running"
	UpgradeFailed  UpgradeStatus = "failed"
)

type UpgradeStatusAndReason

type UpgradeStatusAndReason struct {
	Status     UpgradeStatus
	ReasonCode JobErrorType
}

UpgradeStatusAndReason 用于记录整体更新安装的流程状态和原因,dde-session-daemon和回滚界面会根据该配置进行提示

type Version

type Version struct {
	Version string `json:"version"`
	Arch    string `json:"arch"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL