代码拉取完成,页面将自动刷新
同步操作将从 tupelo-shen/mysnapd 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
// -*- Mode: Go; indent-tabs-mode: t -*-
/*
* Copyright (C) 2018-2022 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package devicestate
import (
"errors"
"gitee.com/mysnapcore/mysnapd/asserts"
"gitee.com/mysnapcore/mysnapd/overlord/snapstate"
"gitee.com/mysnapcore/mysnapd/overlord/state"
)
// DeviceCtx picks a device context from state, optional task or an
// optionally pre-provided one. Returns ErrNoState if a model
// assertion is not yet known.
// In particular if task belongs to a remodeling change this will find
// the appropriate remodel context.
func DeviceCtx(st *state.State, task *state.Task, providedDeviceCtx snapstate.DeviceContext) (snapstate.DeviceContext, error) {
if providedDeviceCtx != nil {
return providedDeviceCtx, nil
}
// use the remodelContext if the task is part of a remodel change
remodCtx, err := remodelCtxFromTask(task)
if err == nil {
return remodCtx, nil
}
if err != nil && !errors.Is(err, state.ErrNoState) {
return nil, err
}
modelAs, err := findModel(st)
if err != nil {
return nil, err
}
devMgr := deviceMgr(st)
return newModelDeviceContext(devMgr, modelAs), nil
}
type groundDeviceContext struct {
model *asserts.Model
systemMode string
}
func (dc *groundDeviceContext) Model() *asserts.Model {
return dc.model
}
func (dc *groundDeviceContext) GroundContext() snapstate.DeviceContext {
return dc
}
func (dc *groundDeviceContext) Store() snapstate.StoreService {
panic("retrieved ground context is not intended to drive store operations")
}
func (dc *groundDeviceContext) ForRemodeling() bool {
return false
}
func (dc *groundDeviceContext) SystemMode() string {
return dc.systemMode
}
func (dc groundDeviceContext) Classic() bool {
return dc.model.Classic()
}
func (dc groundDeviceContext) Kernel() string {
return dc.model.Kernel()
}
func (dc groundDeviceContext) Base() string {
return dc.model.Base()
}
func (dc groundDeviceContext) Gadget() string {
return dc.model.Gadget()
}
func (dc groundDeviceContext) RunMode() bool {
return dc.systemMode == "run"
}
// HasModeenv is true if the grade is set
func (dc groundDeviceContext) HasModeenv() bool {
return dc.model.Grade() != asserts.ModelGradeUnset
}
// IsCoreBoot is true if the model sports a kernel.
func (d *groundDeviceContext) IsCoreBoot() bool {
return d.model.Kernel() != ""
}
// IsClassicBoot is true for classic systems with classic initramfs
// (there are no system modes in this case). If true, the kernel comes
// from debian packages.
func (d *groundDeviceContext) IsClassicBoot() bool {
return !d.IsCoreBoot()
}
// expected interface is implemented
var _ snapstate.DeviceContext = &groundDeviceContext{}
type modelDeviceContext struct {
groundDeviceContext
}
func newModelDeviceContext(devMgr *DeviceManager, modelAs *asserts.Model) *modelDeviceContext {
return &modelDeviceContext{groundDeviceContext{
model: modelAs,
systemMode: devMgr.SystemMode(SysAny),
}}
}
func (dc *modelDeviceContext) Store() snapstate.StoreService {
return nil
}
// expected interface is implemented
var _ snapstate.DeviceContext = &modelDeviceContext{}
// SystemModeInfoFromState returns details about the system mode the device is in.
func SystemModeInfoFromState(st *state.State) (*SystemModeInfo, error) {
return deviceMgr(st).SystemModeInfo()
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。