Пример #1
0
func (command RepairCommand) repairMissing(store *storage.Storage, missing databaseFileMap) error {
	for path, dbFile := range missing {
		if command.force && !command.pretend {
			if err := store.RemoveFileTagsByFileId(dbFile.Id); err != nil {
				return fmt.Errorf("%v: could not delete file-tags: %v", path, err)
			}

			if err := store.RemoveFile(dbFile.Id); err != nil {
				return fmt.Errorf("%v: could not delete file: %v", path, err)
			}

			log.Infof("%v: removed", path)
		} else {
			log.Infof("%v: missing", path)
		}
	}

	return nil
}
Пример #2
0
func (command UntagCommand) removeUntaggedFile(store *storage.Storage, file *database.File) error {
	if command.verbose {
		log.Infof("%v: identifying whether file is tagged.", file.Path())
	}

	filetagCount, err := store.FileTagCountByFileId(file.Id)
	if err != nil {
		return fmt.Errorf("%v: could not get tag count: %v", file.Path(), err)
	}

	if filetagCount == 0 {
		if command.verbose {
			log.Infof("%v: removing untagged file.", file.Path())
		}

		err = store.RemoveFile(file.Id)
		if err != nil {
			return fmt.Errorf("%v: could not remove file: %v", file.Path(), err)
		}
	}

	return nil
}
Пример #3
0
func (command DeleteCommand) deleteTag(store *storage.Storage, tagName string) error {
	tag, err := store.TagByName(tagName)
	if err != nil {
		return fmt.Errorf("could not retrieve tag '%v': %v", tagName, err)
	}
	if tag == nil {
		return fmt.Errorf("no such tag '%v'.", tagName)
	}

	if command.verbose {
		log.Infof("finding files tagged '%v'.", tagName)
	}

	fileTags, err := store.FileTagsByTagId(tag.Id)
	if err != nil {
		return fmt.Errorf("could not retrieve taggings for tag '%v': %v", tagName, err)
	}

	if command.verbose {
		log.Infof("removing applications of tag '%v'.", tagName)
	}

	err = store.RemoveFileTagsByTagId(tag.Id)
	if err != nil {
		return fmt.Errorf("could not remove taggings for tag '%v': %v", tagName, err)
	}

	if command.verbose {
		log.Infof("removing tags implications involving tag '%v'.", tagName)
	}

	err = store.RemoveImplicationsForTagId(tag.Id)
	if err != nil {
		return fmt.Errorf("could not remove tag implications involving tag '%v': %v", tagName, err)
	}

	if command.verbose {
		log.Infof("deleting tag '%v'.", tagName)
	}

	err = store.DeleteTag(tag.Id)
	if err != nil {
		return fmt.Errorf("could not delete tag '%v': %v", tagName, err)
	}

	if command.verbose {
		log.Infof("identifying files left untagged as a result of tag deletion.")
	}

	removedFileCount := 0
	for _, fileTag := range fileTags {
		count, err := store.FileTagCountByFileId(fileTag.FileId)
		if err != nil {
			return fmt.Errorf("could not retrieve taggings count for file #%v: %v", fileTag.FileId, err)
		}
		if count == 0 {
			err := store.RemoveFile(fileTag.FileId)
			if err != nil {
				return fmt.Errorf("could not remove file #%v: %v", fileTag.FileId, err)
			}

			removedFileCount += 1
		}
	}

	if command.verbose {
		log.Infof("removed %v untagged files.", removedFileCount)
	}

	return nil
}