code: func CheckValidImport(newFile, existingFile *statefile.File) error {
  	if existingFile == nil || existingFile.State.Empty() {
  		// It's always okay to overwrite an empty state, regardless of
  		// its lineage/serial.
  		return nil
  	}
  	new := SnapshotMeta{
  		Lineage: newFile.Lineage,
  		Serial:  newFile.Serial,
  	}
  	existing := SnapshotMeta{
  		Lineage: existingFile.Lineage,
  		Serial:  existingFile.Serial,
  	}
  	rel := new.Compare(existing)
  	switch rel {
  	case SnapshotNewer:
  		return nil // a newer snapshot is fine
  	case SnapshotLegacy:
  		return nil // anything goes for a legacy state
  	case SnapshotUnrelated:
  		return fmt.Errorf("cannot import state with lineage %q over unrelated state with lineage %q", new.Lineage, existing.Lineage)
  	case SnapshotEqual:
  		if statefile.StatesMarshalEqual(newFile.State, existingFile.State) {
  			// If lineage, serial, and state all match then this is fine.
  			return nil
  		}
  		return fmt.Errorf("cannot overwrite existing state with serial %d with a different state that has the same serial", new.Serial)
  	case SnapshotOlder:
  		return fmt.Errorf("cannot import state with serial %d over newer state with serial %d", new.Serial, existing.Serial)
  	default:
  		// Should never happen, but we'll check to make sure for safety
  		return fmt.Errorf("unsupported state snapshot relationship %s", rel)
  	}
  }
docs: // CheckValidImport returns nil if the "new" snapshot can be imported as a
  // successor of the "existing" snapshot without forcing.
  //
  // If not, an error is returned describing why.