本文整理汇总了Golang中github.com/snapcore/snapd/overlord/state.State.NewChange方法的典型用法代码示例。如果您正苦于以下问题:Golang State.NewChange方法的具体用法?Golang State.NewChange怎么用?Golang State.NewChange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/snapcore/snapd/overlord/state.State
的用法示例。
在下文中一共展示了State.NewChange方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: newChange
func newChange(st *state.State, kind, summary string, tsets []*state.TaskSet, snapNames []string) *state.Change {
chg := st.NewChange(kind, summary)
for _, ts := range tsets {
chg.AddAll(ts)
}
if snapNames != nil {
chg.Set("snap-names", snapNames)
}
return chg
}
示例2: UpdateBootRevisions
// UpdateBootRevisions synchronizes the active kernel and OS snap versions
// with the versions that actually booted. This is needed because a
// system may install "os=v2" but that fails to boot. The bootloader
// fallback logic will revert to "os=v1" but on the filesystem snappy
// still has the "active" version set to "v2" which is
// misleading. This code will check what kernel/os booted and set
// those versions active.To do this it creates a Change and kicks
// start it directly.
func UpdateBootRevisions(st *state.State) error {
const errorPrefix = "cannot update revisions after boot changes: "
if release.OnClassic {
return nil
}
bootloader, err := partition.FindBootloader()
if err != nil {
return fmt.Errorf(errorPrefix+"%s", err)
}
m, err := bootloader.GetBootVars("snap_kernel", "snap_core")
if err != nil {
return fmt.Errorf(errorPrefix+"%s", err)
}
var tsAll []*state.TaskSet
for _, snapNameAndRevno := range []string{m["snap_kernel"], m["snap_core"]} {
name, rev, err := nameAndRevnoFromSnap(snapNameAndRevno)
if err != nil {
logger.Noticef("cannot parse %q: %s", snapNameAndRevno, err)
continue
}
info, err := CurrentInfo(st, name)
if err != nil {
logger.Noticef("cannot get info for %q: %s", name, err)
continue
}
if rev != info.SideInfo.Revision {
// FIXME: check that there is no task
// for this already in progress
ts, err := RevertToRevision(st, name, rev, Flags{})
if err != nil {
return err
}
tsAll = append(tsAll, ts)
}
}
if len(tsAll) == 0 {
return nil
}
msg := fmt.Sprintf("Update kernel and core snap revisions")
chg := st.NewChange("update-revisions", msg)
for _, ts := range tsAll {
chg.AddAll(ts)
}
st.EnsureBefore(0)
return nil
}