code: func WritePlannedStateUpdate(mgr Transient, planned *statefile.File) error {
  	// If the given manager uses snapshot metadata then we'll check to make
  	// sure no new snapshots have been created since we planned to write
  	// the given state file.
  	if mr, ok := mgr.(PersistentMeta); ok {
  		m := mr.StateSnapshotMeta()
  		if planned.Lineage != "" {
  			if planned.Lineage != m.Lineage {
  				return fmt.Errorf("planned state update is from an unrelated state lineage than the current state")
  			}
  			if planned.Serial != m.Serial {
  				return fmt.Errorf("stored state has been changed by another operation since the given update was planned")
  			}
  		}
  	}
  
  	return mgr.WriteState(planned.State)
  }
docs: // WritePlannedStateUpdate is a companion to PlannedStateUpdate that attempts
  // to apply a state update that was planned earlier to the given state
  // manager.
  //
  // An error is returned if this function detects that a new state snapshot
  // has been written to the backend since the update was planned, since that
  // invalidates the plan. An error is returned also if the manager itself
  // rejects the given state when asked to store it.
  //
  // If the returned error is nil, the given manager's transient state snapshot
  // is updated to match what was planned. It is the caller's responsibility
  // to then persist that state if the manager also implements Persistent and
  // the snapshot should be written to the persistent store.
  //
  // If the state manager implements Locker then it is the caller's
  // responsibility to hold the lock at least for the duration of this call.