func (vfs FuseVfs) openTaggedEntryDir(path []string) ([]fuse.DirEntry, fuse.Status) { log.Infof(2, "BEGIN openTaggedEntryDir(%v)", path) defer log.Infof(2, "END openTaggedEntryDir(%v)", path) expression := query.HasAll(path) files, err := vfs.store.QueryFiles(expression) if err != nil { log.Fatalf("could not query files: %v", err) } tagNames := make(map[string]interface{}, len(path)) for _, tagName := range path { tagNames[tagName] = nil } furtherTagNames := make([]string, 0, 10) for _, file := range files { fileTags, err := vfs.store.FileTagsByFileId(file.Id) if err != nil { log.Fatalf("could not retrieve file-tags for file '%v': %v", file.Id, err) } tagIds := make([]uint, len(fileTags)) for index, fileTag := range fileTags { tagIds[index] = fileTag.TagId } tags, err := vfs.store.TagsByIds(tagIds) if err != nil { log.Fatalf("could not retrieve tags: %v", err) } for _, tag := range tags { _, has := tagNames[tag.Name] if !has { if !containsName(furtherTagNames, tag.Name) { furtherTagNames = append(furtherTagNames, tag.Name) } } } } entries := make([]fuse.DirEntry, 0, len(files)+len(furtherTagNames)) for _, tagName := range furtherTagNames { entries = append(entries, fuse.DirEntry{Name: tagName, Mode: fuse.S_IFDIR | 0755}) } for _, file := range files { linkName := vfs.getLinkName(file) entries = append(entries, fuse.DirEntry{Name: linkName, Mode: fuse.S_IFLNK}) } return entries, fuse.OK }
// Retrieves the set of files with the specified tags. func (storage *Storage) FilesWithTags(tagNames []string) (entities.Files, error) { expression := query.HasAll(tagNames) return storage.Db.QueryFiles(expression) }
// Retrieves the count of files with the specified tags. func (storage *Storage) FileCountWithTags(tagNames []string) (uint, error) { expression := query.HasAll(tagNames) return storage.Db.QueryFileCount(expression) }