func mergeTags(store *storage.Storage, tx *storage.Tx, sourceTagNames []string, destTagName string) (error, warnings) { destTag, err := store.TagByName(tx, destTagName) if err != nil { return fmt.Errorf("could not retrieve tag '%v': %v", destTagName, err), nil } if destTag == nil { return fmt.Errorf("no such tag '%v'", destTagName), nil } warnings := make(warnings, 0, 10) for _, sourceTagName := range sourceTagNames { if sourceTagName == destTagName { warnings = append(warnings, fmt.Sprintf("cannot merge tag '%v' into itself", sourceTagName)) continue } sourceTag, err := store.TagByName(tx, sourceTagName) if err != nil { return fmt.Errorf("could not retrieve tag '%v': %v", sourceTagName, err), warnings } if sourceTag == nil { warnings = append(warnings, fmt.Sprintf("no such tag '%v'", sourceTagName)) continue } log.Infof(2, "finding files tagged '%v'.", sourceTagName) fileTags, err := store.FileTagsByTagId(tx, sourceTag.Id, true) if err != nil { return fmt.Errorf("could not retrieve files for tag '%v': %v", sourceTagName, err), warnings } log.Infof(2, "applying tag '%v' to these files.", destTagName) for _, fileTag := range fileTags { if _, err = store.AddFileTag(tx, fileTag.FileId, destTag.Id, fileTag.ValueId); err != nil { return fmt.Errorf("could not apply tag '%v' to file #%v: %v", destTagName, fileTag.FileId, err), warnings } } log.Infof(2, "deleting tag '%v'.", sourceTagName) if err = store.DeleteTag(tx, sourceTag.Id); err != nil { return fmt.Errorf("could not delete tag '%v': %v", sourceTagName, err), warnings } } return nil, warnings }