func getPlugAndSlotRefs(task *state.Task) (*interfaces.PlugRef, *interfaces.SlotRef, error) { var plugRef interfaces.PlugRef var slotRef interfaces.SlotRef if err := task.Get("plug", &plugRef); err != nil { return nil, nil, err } if err := task.Get("slot", &slotRef); err != nil { return nil, nil, err } return &plugRef, &slotRef, nil }
func (m *SnapManager) undoLinkSnap(t *state.Task, _ *tomb.Tomb) error { st := t.State() st.Lock() defer st.Unlock() ss, snapst, err := snapSetupAndState(t) if err != nil { return err } var oldChannel string err = t.Get("old-channel", &oldChannel) if err != nil { return err } // relinking of the old snap is done in the undo of unlink-current-snap snapst.Candidate = snapst.Sequence[len(snapst.Sequence)-1] snapst.Sequence = snapst.Sequence[:len(snapst.Sequence)-1] snapst.Active = false snapst.Channel = oldChannel newInfo, err := readInfo(ss.Name, snapst.Candidate) if err != nil { return err } pb := &TaskProgressAdapter{task: t} st.Unlock() // pb itself will ask for locking err = m.backend.UnlinkSnap(newInfo, pb) st.Lock() if err != nil { return err } // mark as inactive Set(st, ss.Name, snapst) return nil }
func (m *InterfaceManager) undoDiscardConns(task *state.Task, _ *tomb.Tomb) error { st := task.State() st.Lock() defer st.Unlock() var removed map[string]connState err := task.Get("removed", &removed) if err != nil && err != state.ErrNoState { return err } conns, err := getConns(st) if err != nil { return err } for id, connState := range removed { conns[id] = connState } setConns(st, conns) task.Set("removed", nil) return nil }
func TaskSnapSetup(t *state.Task) (*SnapSetup, error) { var ss SnapSetup err := t.Get("snap-setup", &ss) if err != nil && err != state.ErrNoState { return nil, err } if err == nil { return &ss, nil } var id string err = t.Get("snap-setup-task", &id) if err != nil { return nil, err } ts := t.State().Task(id) if err := ts.Get("snap-setup", &ss); err != nil { return nil, err } return &ss, nil }
func (m *InterfaceManager) doRemoveProfiles(task *state.Task, _ *tomb.Tomb) error { st := task.State() st.Lock() defer st.Unlock() // Get SnapSetup for this snap. This is gives us the name of the snap. snapSetup, err := snapstate.TaskSnapSetup(task) if err != nil { return err } snapName := snapSetup.Name // Get SnapState for this snap var snapState snapstate.SnapState err = snapstate.Get(st, snapName, &snapState) if err != nil && err != state.ErrNoState { return err } // Get the old-devmode flag from the task. // This flag is set by setup-profiles in case we have to undo. var oldDevMode bool err = task.Get("old-devmode", &oldDevMode) if err != nil && err != state.ErrNoState { return err } // Restore the state of DevMode flag if old-devmode was saved in the task. if err == nil { if oldDevMode { snapState.Flags |= snapstate.DevMode } else { snapState.Flags &= ^snapstate.DevMode } snapstate.Set(st, snapName, &snapState) } // Disconnect the snap entirely. // This is required to remove the snap from the interface repository. // The returned list of affected snaps will need to have its security setup // to reflect the change. affectedSnaps, err := m.repo.DisconnectSnap(snapName) if err != nil { return err } // Setup security of the affected snaps. for _, snapInfo := range affectedSnaps { if snapInfo.Name() == snapName { // Skip setup for the snap being removed as this is handled below. continue } if err := setupSnapSecurity(task, snapInfo, m.repo); err != nil { return state.Retry } } // Remove the snap from the interface repository. // This discards all the plugs and slots belonging to that snap. if err := m.repo.RemoveSnap(snapName); err != nil { return err } // Remove security artefacts of the snap. if err := removeSnapSecurity(task, snapName); err != nil { return state.Retry } return nil }