Esempio n. 1
0
// combineWithDeletion updates the first CombinedAppStorage with new merged
// bucket and deletes other CombinedAppStorages
func combineWithDeletion(mergedStorage models.CombinedAppStorage, storages []models.CombinedAppStorage) (*models.CombinedAppStorage, error) {
	for i := 0; i < len(storages); i++ {
		if i == 0 {
			// UPDATE CombinedAppStorage with its new Bucket data
			storages[i].Bucket = mergedStorage.Bucket
			if err := helper.UpdateCombinedAppStorage(&storages[i]); err != nil {
				return nil, err
			}
		} else {
			// DELETE CombinedAppStorages in this block
			if err := helper.RemoveCombinedAppStorage(storages[i].Id); err != nil {
				return nil, err
			}
		}
	}

	return &storages[0], nil
}
Esempio n. 2
0
func deleteCombinedAppStorages(res interface{}) error {
	cs := res.(*models.CombinedAppStorage)

	if getAccountByID(cs.AccountId.Hex()) {
		storages, err := helper.GetAllCombinedAppStorageByAccountId(cs.AccountId)
		if err != nil {
			return err
		}
		if len(storages) > 1 {
			mergedStorage := mergeCombinedAppStorageData(storages)
			_, err := combineWithDeletion(mergedStorage, storages)
			if err != nil {
				return err
			}
		}
		return nil
	}

	fmt.Printf("deleting CombinedAppStorage %q\n", cs.Id)
	if !*flagDry {
		return helper.RemoveCombinedAppStorage(cs.Id)
	}
	return nil
}