Esempio n. 1
0
File: tag.go Progetto: logtcn/TMSU
// Adds a tag.
func (storage *Storage) AddTag(tx *Tx, name string) (*entities.Tag, error) {
	if err := entities.ValidateTagName(name); err != nil {
		return nil, err
	}

	return database.InsertTag(tx.tx, name)
}
Esempio n. 2
0
File: tag.go Progetto: logtcn/TMSU
// Renames a tag.
func (storage Storage) RenameTag(tx *Tx, tagId entities.TagId, name string) (*entities.Tag, error) {
	if err := entities.ValidateTagName(name); err != nil {
		return nil, err
	}

	return database.RenameTag(tx.tx, tagId, name)
}
Esempio n. 3
0
File: tag.go Progetto: logtcn/TMSU
// Copies a tag.
func (storage Storage) CopyTag(tx *Tx, sourceTagId entities.TagId, name string) (*entities.Tag, error) {
	if err := entities.ValidateTagName(name); err != nil {
		return nil, err
	}

	tag, err := database.InsertTag(tx.tx, name)
	if err != nil {
		return nil, err
	}

	err = database.CopyFileTags(tx.tx, sourceTagId, tag.Id)
	if err != nil {
		return nil, err
	}

	return tag, nil
}
Esempio n. 4
0
func listFilesForQuery(store *storage.Storage, tx *storage.Tx, queryText, path string, dirOnly, fileOnly, print0, showCount, explicitOnly, ignoreCase bool, sort string) (error, warnings) {
	log.Info(2, "parsing query")

	expression, err := query.Parse(queryText)
	if err != nil {
		return fmt.Errorf("could not parse query: %v", err), nil
	}

	log.Info(2, "checking tag names")

	warnings := make(warnings, 0, 10)

	tagNames, err := query.TagNames(expression)
	if err != nil {
		return fmt.Errorf("could not identify tag names: %v", err), nil
	}

	tags, err := store.TagsByCasedNames(tx, tagNames, ignoreCase)
	for _, tagName := range tagNames {
		if err := entities.ValidateTagName(tagName); err != nil {
			warnings = append(warnings, err.Error())
			continue
		}

		if !tags.ContainsCasedName(tagName, ignoreCase) {
			warnings = append(warnings, fmt.Sprintf("no such tag '%v'", tagName))
			continue
		}
	}

	valueNames, err := query.ExactValueNames(expression)
	if err != nil {
		return fmt.Errorf("could not identify value names: %v", err), nil
	}

	values, err := store.ValuesByCasedNames(tx, valueNames, ignoreCase)
	for _, valueName := range valueNames {
		if err := entities.ValidateValueName(valueName); err != nil {
			warnings = append(warnings, err.Error())
			continue
		}

		if !values.ContainsCasedName(valueName, ignoreCase) {
			warnings = append(warnings, fmt.Sprintf("no such value '%v'", valueName))
			continue
		}
	}

	log.Info(2, "querying database")

	files, err := store.FilesForQuery(tx, expression, path, explicitOnly, ignoreCase, sort)
	if err != nil {
		if strings.Index(err.Error(), "parser stack overflow") > -1 {
			return fmt.Errorf("the query is too complex (see the troubleshooting wiki for how to increase the stack size)"), warnings
		} else {
			return fmt.Errorf("could not query files: %v", err), warnings
		}
	}

	if err = listFiles(tx, files, dirOnly, fileOnly, print0, showCount); err != nil {
		return err, warnings
	}

	return nil, warnings
}