当前位置: 首页>>代码示例>>Golang>>正文


Golang Storage.FileTagsByFileId方法代码示例

本文整理汇总了Golang中tmsu/storage.Storage.FileTagsByFileId方法的典型用法代码示例。如果您正苦于以下问题:Golang Storage.FileTagsByFileId方法的具体用法?Golang Storage.FileTagsByFileId怎么用?Golang Storage.FileTagsByFileId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tmsu/storage.Storage的用法示例。


在下文中一共展示了Storage.FileTagsByFileId方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: listTagsForWorkingDirectory

func listTagsForWorkingDirectory(store *storage.Storage, showCount, onePerLine bool) error {
	file, err := os.Open(".")
	if err != nil {
		return fmt.Errorf("could not open working directory: %v", err)
	}
	defer file.Close()

	dirNames, err := file.Readdirnames(0)
	if err != nil {
		return fmt.Errorf("could not list working directory contents: %v", err)
	}

	sort.Strings(dirNames)

	for _, dirName := range dirNames {
		log.Infof(2, "%v: retrieving tags.", dirName)

		file, err := store.FileByPath(dirName)
		if err != nil {
			log.Warn(err.Error())
			continue
		}
		if file == nil {
			continue
		}

		fileTags, err := store.FileTagsByFileId(file.Id)
		if err != nil {
			return fmt.Errorf("could not retrieve file-tags: %v", err)
		}

		tagNames, err := lookupTagNames(store, fileTags)
		if err != nil {
			return err
		}

		if showCount {
			fmt.Println(dirName + ": " + strconv.Itoa(len(tagNames)))
		} else {
			if onePerLine {
				fmt.Println(dirName)
				for _, tagName := range tagNames {
					fmt.Println(tagName)
				}
				fmt.Println()
			} else {
				fmt.Println(dirName + ": " + strings.Join(tagNames, " "))
			}
		}
	}

	return nil
}
开发者ID:Konubinix,项目名称:tmsu,代码行数:53,代码来源:tags.go

示例2: expectTags

func expectTags(test *testing.T, store *storage.Storage, file *entities.File, tags ...*entities.Tag) {
	fileTags, err := store.FileTagsByFileId(file.Id)
	if err != nil {
		test.Fatal(err)
	}
	if len(fileTags) != len(tags) {
		test.Fatalf("File '%v' has %v tags but expected %v.", file.Path(), len(fileTags), len(tags))
	}
	for index, filetag := range fileTags {
		tag := tags[index]

		if filetag.TagId != tag.Id {
			test.Fatal("File '%v' is tagged %v but expected %v.", file.Path(), filetag.TagId, tag.Id)
		}
	}
}
开发者ID:Konubinix,项目名称:tmsu,代码行数:16,代码来源:common_test.go

示例3: listTagsForPath

func listTagsForPath(store *storage.Storage, path string, showCount, onePerLine bool) error {
	log.Infof(2, "%v: retrieving tags.", path)

	file, err := store.FileByPath(path)
	if err != nil {
		return fmt.Errorf("%v: could not retrieve file: %v", path, err)
	}

	var tagNames []string
	if file != nil {
		fileTags, err := store.FileTagsByFileId(file.Id)
		if err != nil {
			return fmt.Errorf("%v: could not retrieve file-tags: %v", path, err)
		}

		tagNames, err = lookupTagNames(store, fileTags)
		if err != nil {
			return err
		}
	} else {
		_, err := os.Stat(path)
		if err != nil {
			switch {
			case os.IsPermission(err):
				return fmt.Errorf("%v: permission denied", path)
			case os.IsNotExist(err):
				return fmt.Errorf("%v: no such file", path)
			default:
				return fmt.Errorf("%v: could not stat file: %v", path, err)
			}
		}
	}

	if showCount {
		fmt.Println(len(tagNames))
	} else {
		if onePerLine {
			for _, tagName := range tagNames {
				fmt.Println(tagName)
			}
		} else {
			format.Columns(tagNames, terminalWidth())
		}
	}

	return nil
}
开发者ID:Konubinix,项目名称:tmsu,代码行数:47,代码来源:tags.go

示例4: listTagsForPaths

func listTagsForPaths(store *storage.Storage, paths []string, showCount, onePerLine bool) error {
	wereErrors := false
	for _, path := range paths {
		log.Infof(2, "%v: retrieving tags.", path)

		file, err := store.FileByPath(path)
		if err != nil {
			log.Warn(err.Error())
			continue
		}

		var tagNames []string
		if file != nil {
			fileTags, err := store.FileTagsByFileId(file.Id)
			if err != nil {
				return err
			}

			tagNames, err = lookupTagNames(store, fileTags)
			if err != nil {
				return err
			}
		} else {
			_, err := os.Stat(path)
			if err != nil {
				switch {
				case os.IsPermission(err):
					log.Warnf("%v: permission denied", path)
					wereErrors = true
					continue
				case os.IsNotExist(err):
					log.Warnf("%v: no such file", path)
					wereErrors = true
					continue
				default:
					return fmt.Errorf("%v: could not stat file: %v", path, err)
				}
			}
		}

		if showCount {
			fmt.Println(path + ": " + strconv.Itoa(len(tagNames)))
		} else {
			if onePerLine {
				fmt.Println(path)
				for _, tagName := range tagNames {
					fmt.Println(tagName)
				}
				fmt.Println()
			} else {
				fmt.Println(path + ": " + strings.Join(tagNames, " "))
			}
		}
	}

	if wereErrors {
		return blankError
	}

	return nil
}
开发者ID:Konubinix,项目名称:tmsu,代码行数:61,代码来源:tags.go


注:本文中的tmsu/storage.Storage.FileTagsByFileId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。