Skip to content

Commit 0ab511e

Browse files
committed
fixup! o/snapstate: only create link-component tasks when needed
1 parent 1431074 commit 0ab511e

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

overlord/snapstate/component.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -453,33 +453,40 @@ func (cc *componentInstallChoreographer) canDiscardOldRevision() bool {
453453
}
454454

455455
// targetSnapAlreadyHasComponentRevision reports whether a non-current target
456-
// snap revision already records the exact component state we want to end up
457-
// with. In that case, we must skip creating link-component entirely. Otherwise,
458-
// the undo path would end up unlinking components that should remain linked.
456+
// snap revision already contains the desired component revision. In that case,
457+
// we must skip creating link-component entirely. Otherwise, the undo path
458+
// would end up unlinking a component that should remain linked for that
459+
// snap revision.
459460
func (cc *componentInstallChoreographer) targetSnapAlreadyHasComponentRevision() bool {
460461
if !cc.snapst.IsInstalled() {
461462
return false
462463
}
463464

465+
targetSnapRevision := cc.snapsup.Revision()
466+
targetCompSideInfo := cc.compsup.CompSideInfo
467+
464468
// only consider non-current revisions when checking for the component.
465-
if cc.snapst.Current == cc.snapsup.Revision() {
466-
// when refreshing to the current snap revision, component refreshes
467-
// rely on unlink-current-component/link-component. thus, undo can
468-
// restore the old component revision cleanly.
469+
if cc.snapst.Current == targetSnapRevision {
470+
// when operating on the current snap revision, we're either going to:
471+
// * install a new component, for which we'll always need a
472+
// link-component task.
473+
// * change revisions of an already present component. in that case, we
474+
// create unlink-current-component and then a later link-component.
469475
return false
470476
}
471477

472-
idx := cc.snapst.LastIndex(cc.snapsup.Revision())
478+
idx := cc.snapst.LastIndex(targetSnapRevision)
473479
if idx < 0 {
474480
return false
475481
}
482+
// the target snap revision is already present at idx
476483

477-
cs := cc.snapst.Sequence.ComponentStateForRev(idx, cc.compsup.CompSideInfo.Component)
484+
cs := cc.snapst.Sequence.ComponentStateForRev(idx, targetCompSideInfo.Component)
478485
if cs == nil {
479486
return false
480487
}
481488

482-
return cs.CompType == cc.compsup.CompType && *cs.SideInfo == *cc.compsup.CompSideInfo
489+
return cs.SideInfo.Equal(targetCompSideInfo)
483490
}
484491

485492
func (cc *componentInstallChoreographer) BeforeLocalSystemMod(st *state.State, s *taskChainSpan) ([]*state.Task, error) {

0 commit comments

Comments
 (0)