func (p4 patch4T) addCleanup(task *state.Task) error { // NOTE we could check for the status of the change itself, but // copy-snap-data is the one creating the trash, so if it's run there's // no sense in fiddling with the change. if task.Status().Ready() { return nil } snapsup, err := p4.taskSnapSetup(task) if err != nil { return err } var tid string if err := p4.get(task, "snap-setup-task", &tid); err != nil { return err } change := task.Change() revisionStr := "" if snapsup.SideInfo != nil { revisionStr = fmt.Sprintf(" (%s)", snapsup.Revision()) } tasks := change.Tasks() last := tasks[len(tasks)-1] newTask := task.State().NewTask("cleanup", fmt.Sprintf("Clean up %q%s install", snapsup.Name(), revisionStr)) newTask.Set("snap-setup-task", tid) newTask.WaitFor(last) change.AddTask(newTask) return nil }
func (p4 patch4T) mangle(task *state.Task) error { snapsup, snapst, err := p4.snapSetupAndState(task) if err != nil { return err } var hadCandidate bool if err := p4.getMaybe(task, "had-candidate", &hadCandidate); err != nil && err != state.ErrNoState { return err } if hadCandidate { change := task.Change() if change.Kind() != "revert-snap" { return fmt.Errorf("had-candidate true for task %s (%s) of non-revert change %s (%s)", task.ID(), task.Kind(), change.ID(), change.Kind()) } } task.Clear("had-candidate") task.Set("old-candidate-index", snapst.LastIndex(snapsup.SideInfo.Revision)) return nil }
// gget does the actual work of get and getMaybe func (patch4T) gget(task *state.Task, key string, passThroughMissing bool, value interface{}) error { err := task.Get(key, value) if err == nil || (passThroughMissing && err == state.ErrNoState) { return err } change := task.Change() return fmt.Errorf("cannot get %q from task %s (%s) of change %s (%s): %v", key, task.ID(), task.Kind(), change.ID(), change.Kind(), err) }