// RemoveImportingModelDocs removes all documents from multi-model collections
// for the current model. This method asserts that the model's migration mode
// is "importing".
425427
func (st *State) RemoveImportingModelDocs() error {
	err := st.removeAllModelDocs(bson.D{{"migration-mode", MigrationModeImporting}})
	if errors.Cause(err) == txn.ErrAborted {
		return errors.New("can't remove model: model not being imported for migration")
	}
	return errors.Trace(err)
}
991690
func WithImportDetails(parent context.Context, value *[]string) context.Context {
	return context.WithValue(contextOrBackground(parent), keyImportDetails, value)
}
189853
func getImports(
	interfaces []reflect.Type,
	pkgPath string) importMap {
	imports := make(importMap)
	for _, it := range interfaces {
		addImportForType(imports, it)
		addImportsForInterfaceMethods(imports, it)
	}

	// Make sure there are imports for other types used by the generated code
	// itself.
	imports["fmt"] = "fmt"
	imports["oglemock"] = "github.com/jacobsa/oglemock"
	imports["runtime"] = "runtime"
	imports["unsafe"] = "unsafe"

	// Remove any self-imports generated above.
	for k, v := range imports {
		if v == pkgPath {
			delete(imports, k)
		}
	}

	return imports
}
275087
func (m *Manager) RemoveOrganization(globalID string, organization string) error {
	qry := bson.M{"globalid": globalID}
	update := bson.M{"$pull": bson.M{"orgowners": organization, "orgmembers": organization}}
	return m.collection.Update(qry, update)
}
760147
func migrateConfigToMinioSys(objAPI ObjectLayer) (err error) {
	// Construct path to config.json for the given bucket.
	configFile := path.Join(minioConfigPrefix, minioConfigFile)

	// Verify if config was already available in .minio.sys in which case, nothing more to be done.
	if err = checkConfig(context.Background(), objAPI, configFile); err != errConfigNotFound {
		return err
	}

	defer func() {
		// Rename config.json to config.json.deprecated only upon
		// success of this function.
		if err == nil {
			os.Rename(getConfigFile(), getConfigFile()+".deprecated")
		}
	}()

	transactionConfigFile := configFile + ".transaction"

	// As object layer's GetObject() and PutObject() take respective lock on minioMetaBucket
	// and configFile, take a transaction lock to avoid data race between readConfig()
	// and saveConfig().
	objLock := globalNSMutex.NewNSLock(minioMetaBucket, transactionConfigFile)
	if err = objLock.GetLock(globalOperationTimeout); err != nil {
		return err
	}
	defer objLock.Unlock()

	// Verify if backend already has the file (after holding lock)
	if err = checkConfig(context.Background(), objAPI, configFile); err != errConfigNotFound {
		return err
	} // if errConfigNotFound proceed to migrate..

	var config = &serverConfig{}
	if _, err = Load(getConfigFile(), config); err != nil {
		if !os.IsNotExist(err) {
			return err
		}
		// Read from deprecate file as well if necessary.
		if _, err = Load(getConfigFile()+".deprecated", config); err != nil {
			if !os.IsNotExist(err) {
				return err
			}
			// If all else fails simply initialize the server config.
			return newSrvConfig(objAPI)
		}

	}
	return saveServerConfig(context.Background(), objAPI, config)
}
649579
func (r *GormRepository) checkNoWITIsMissing(ctx context.Context, s *ImportHelper) error {
	type idType struct {
		ID uuid.UUID `gorm:"column:id" sql:"type:uuid"`
	}
	var IDs []idType
	query := fmt.Sprintf(`SELECT id FROM "%s" WHERE space_template_id = ?`, workitem.WorkItemType{}.TableName())
	db := r.db.Raw(query, s.Template.ID.String()).Scan(&IDs)
	if db.Error != nil {
		return errs.Wrapf(db.Error, "failed to load all work item types for space template '%s'", s.Template.ID)
	}
	toBeFoundIDs := id.Map{}
	for _, i := range IDs {
		toBeFoundIDs[i.ID] = struct{}{}
	}
	for _, wit := range s.WITs {
		delete(toBeFoundIDs, wit.ID)
	}
	if len(toBeFoundIDs) > 0 {
		return errs.Errorf("work item types to be imported must not remove these existing work item types: %s", toBeFoundIDs)
	}
	return nil
}
165699
func (m *DescriptionManager) Remove(globalid string) error {
	return m.collection.Remove(bson.M{"globalid": globalid})
}
31662
func InitModels() {
	index := mgo.Index{
		Key:      []string{"key"},
		Unique:   true,
		DropDups: false,
	}

	db.EnsureIndex(mongoOngoingPhonenumberValidationCollectionName, index)
	db.EnsureIndex(mongoOngoingEmailAddressValidationCollectionName, index)

	automaticExpiration := mgo.Index{
		Key:         []string{"createdat"},
		ExpireAfter: time.Second * 60 * 10,
		Background:  true,
	}
	db.EnsureIndex(mongoOngoingPhonenumberValidationCollectionName, automaticExpiration)

	automaticExpiration = mgo.Index{
		Key:         []string{"createdat"},
		ExpireAfter: time.Second * 3600 * 48,
		Background:  true,
	}
	db.EnsureIndex(mongoOngoingEmailAddressValidationCollectionName, automaticExpiration)

	index = mgo.Index{
		Key:      []string{"username", "phonenumber"},
		Unique:   true,
		DropDups: true,
	}
	db.EnsureIndex(mongoValidatedPhonenumbers, index)

	index = mgo.Index{
		Key:      []string{"phonenumber"},
		Unique:   true,
		DropDups: true,
	}
	db.EnsureIndex(mongoValidatedPhonenumbers, index)

	index = mgo.Index{
		Key:      []string{"username", "emailaddress"},
		Unique:   true,
		DropDups: true,
	}
	db.EnsureIndex(mongoValidatedEmailAddresses, index)
	index = mgo.Index{
		Key:      []string{"emailaddress"},
		Unique:   true,
		DropDups: true,
	}
	db.EnsureIndex(mongoValidatedEmailAddresses, index)

}
917315
func (a *Account) removeServiceImport(subject string) {
	a.mu.Lock()
	si, ok := a.imports.services[subject]
	if ok && si != nil && si.ae {
		a.nae--
	}
	delete(a.imports.services, subject)
	a.mu.Unlock()
	if a.srv != nil && a.srv.gateway.enabled {
		a.srv.gatewayHandleServiceImport(a, []byte(subject), nil, -1)
	}
}
1146790
func removeAttachments(ctx *context, ids []params.MachineStorageId) error {
	if len(ids) == 0 {
		return nil
	}
	errorResults, err := ctx.config.Life.RemoveAttachments(ids)
	if err != nil {
		return errors.Annotate(err, "removing attachments")
	}
	for i, result := range errorResults {
		if result.Error != nil && !params.IsCodeNotFound(result.Error) {
			// ignore not found error.
			return errors.Annotatef(
				result.Error, "removing attachment of %s to %s from state",
				ids[i].AttachmentTag, ids[i].MachineTag,
			)
		}
	}
	return nil
}
910906
func migrateLocalModelUsers(usermodels map[string]*ControllerModels) error {
	changes := false
	for _, modelDetails := range usermodels {
		for name, model := range modelDetails.Models {
			migratedName, changed, err := migrateModelName(name)
			if err != nil {
				return errors.Trace(err)
			}
			if !changed {
				continue
			}
			delete(modelDetails.Models, name)
			modelDetails.Models[migratedName] = model
			changes = true
		}
		migratedName, changed, err := migrateModelName(modelDetails.CurrentModel)
		if err != nil {
			return errors.Trace(err)
		}
		if !changed {
			continue
		}
		modelDetails.CurrentModel = migratedName
	}
	if changes {
		return WriteModelsFile(usermodels)
	}
	return nil
}
527253
func addImportsForInterfaceMethods(imports importMap, it reflect.Type) {
	// Handle each method.
	for i := 0; i < it.NumMethod(); i++ {
		m := it.Method(i)
		addImportsForType(imports, m.Type)
	}
}
1175924
func InitModels() {
	index := mgo.Index{
		Key:    []string{"sessionkey"},
		Unique: true,
	}

	db.EnsureIndex(mongoRegistrationsInProgressCollectionName, index)

	index = mgo.Index{
		Key:    []string{"emailvalidationkey"},
		Unique: false, // Uniqueness is enforced in the respective ongoing validation collection
	}

	db.EnsureIndex(mongoRegistrationsInProgressCollectionName, index)

	index = mgo.Index{
		Key:    []string{"phonevalidationkey"},
		Unique: false, // Uniqueness is enforced in the respective ongoing validation collection
	}

	db.EnsureIndex(mongoRegistrationsInProgressCollectionName, index)

	automaticExpiration := mgo.Index{
		Key:         []string{"createdat"},
		ExpireAfter: time.Second * 60 * 60 * 24, // Remove after one day
		Background:  true,
	}

	db.EnsureIndex(mongoRegistrationsInProgressCollectionName, automaticExpiration)
}
1135926
func (process *TeleportProcess) closeImportedDescriptors(prefix string) error {
	process.Lock()
	defer process.Unlock()

	var errors []error
	for i := range process.importedDescriptors {
		d := process.importedDescriptors[i]
		if strings.HasPrefix(d.Type, prefix) {
			process.Infof("Closing imported but unused descriptor %v %v.", d.Type, d.Address)
			errors = append(errors, d.File.Close())
		}
	}
	return trace.NewAggregate(errors...)
}
1013712
func InitModels() {
	index := mgo.Index{
		Key:      []string{"username"},
		Unique:   true,
		DropDups: true,
	}

	db.EnsureIndex(mongoUsersCollectionName, index)

	// Removes users without valid 2 factor authentication after 3 days
	automaticUserExpiration := mgo.Index{
		Key:         []string{"expire"},
		ExpireAfter: time.Second * 3600 * 24 * 3,
		Background:  true,
	}
	db.EnsureIndex(mongoUsersCollectionName, automaticUserExpiration)

	avatarIndex := mgo.Index{
		Key:      []string{"hash"},
		Unique:   true,
		DropDups: true,
	}
	db.EnsureIndex(mongoAvatarFileCollectionName, avatarIndex)

	emailIndex := mgo.Index{
		Key: []string{"emailaddresses.emailaddress"},
	}
	db.EnsureIndex(mongoUsersCollectionName, emailIndex)
}
1148269
func (s *store) RemoveModel(controllerName, modelName string) error {
	if err := ValidateControllerName(controllerName); err != nil {
		return errors.Trace(err)
	}
	if err := ValidateModelName(modelName); err != nil {
		return errors.Trace(err)
	}

	releaser, err := s.acquireLock()
	if err != nil {
		return errors.Annotatef(err,
			"cannot acquire lock file for removing model %s on controller %s", modelName, controllerName,
		)
	}
	defer releaser.Release()

	return errors.Trace(updateModels(
		controllerName,
		func(models *ControllerModels) (bool, error) {
			if _, ok := models.Models[modelName]; !ok {
				return false, errors.NotFoundf(
					"model %s:%s",
					controllerName,
					modelName,
				)
			}
			delete(models.Models, modelName)
			return true, nil
		},
	))
}
305570
func (md *RootMetadataV3) ClearForV4Migration() {
	md.WriterMetadata.WKeyBundleID = TLFWriterKeyBundleID{}
	md.RKeyBundleID = TLFReaderKeyBundleID{}
}