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


Golang storage.Storage类代码示例

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


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

示例1: lookupTagNames

func lookupTagNames(store *storage.Storage, fileTags entities.FileTags) ([]string, error) {
	tagNames := make([]string, 0, len(fileTags))

	for _, fileTag := range fileTags {
		tag, err := store.Tag(fileTag.TagId)
		if err != nil {
			return nil, fmt.Errorf("could not lookup tag: %v", err)
		}
		if tag == nil {
			return nil, fmt.Errorf("tag '%v' does not exist", fileTag.TagId)
		}

		var tagName string
		if fileTag.ValueId == 0 {
			tagName = tag.Name
		} else {
			value, err := store.Value(fileTag.ValueId)
			if err != nil {
				return nil, fmt.Errorf("could not lookup value: %v", err)
			}
			if value == nil {
				return nil, fmt.Errorf("value '%v' does not exist", fileTag.ValueId)
			}

			tagName = tag.Name + "=" + value.Name
		}

		tagNames = append(tagNames, tagName)
	}

	sort.Strings(tagNames)

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

示例2: listValuesForTag

func listValuesForTag(store *storage.Storage, tagName string, showCount, onePerLine bool) 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)
	}

	log.Infof(2, "retrieving values for tag '%v'.", tagName)

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

	if showCount {
		fmt.Println(len(values))
	} else {
		if onePerLine {
			for _, value := range values {
				fmt.Println(value.Name)
			}
		} else {
			valueNames := make([]string, len(values))
			for index, value := range values {
				valueNames[index] = value.Name
			}

			format.Columns(valueNames, terminalWidth())
		}
	}

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

示例3: repairModified

func repairModified(store *storage.Storage, modified fileIdAndInfoMap, pretend bool, fingerprintAlgorithm string) error {
	log.Infof(2, "repairing modified files")

	for path, fileIdAndStat := range modified {
		fileId := fileIdAndStat.fileId
		stat := fileIdAndStat.stat

		log.Infof(1, "%v: modified", path)

		fingerprint, err := fingerprint.Create(path, fingerprintAlgorithm)
		if err != nil {
			return fmt.Errorf("%v: could not create fingerprint: %v", path, err)
		}

		if !pretend {
			_, err := store.UpdateFile(fileId, path, fingerprint, stat.ModTime(), stat.Size(), stat.IsDir())
			if err != nil {
				return fmt.Errorf("%v: could not update file in database: %v", path, err)
			}
		}

	}

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

示例4: repairModified

func (command RepairCommand) repairModified(store *storage.Storage, modified fileIdAndInfoMap) error {
	if command.verbose {
		log.Info("repairing modified files")
	}

	for path, fileIdAndStat := range modified {
		fileId := fileIdAndStat.fileId
		stat := fileIdAndStat.stat

		log.Infof("%v: modified", path)

		fingerprint, err := fingerprint.Create(path)
		if err != nil {
			return fmt.Errorf("%v: could not create fingerprint: %v", path, err)
		}

		if !command.pretend {
			_, err := store.UpdateFile(fileId, path, fingerprint, stat.ModTime(), stat.Size(), stat.IsDir())
			if err != nil {
				return fmt.Errorf("%v: could not update file in database: %v", path, err)
			}
		}

	}

	return nil
}
开发者ID:kelvinhammond,项目名称:tmsu,代码行数:27,代码来源:repair.go

示例5: deleteImplication

func (command ImplyCommand) deleteImplication(store *storage.Storage, tagName, impliedTagName string) error {
	tag, err := store.Db.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)
	}

	impliedTag, err := store.Db.TagByName(impliedTagName)
	if err != nil {
		return fmt.Errorf("could not retrieve tag '%v': %v", impliedTagName, err)
	}
	if impliedTag == nil {
		return fmt.Errorf("no such tag '%v'.", impliedTagName)
	}

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

	if err = store.RemoveImplication(tag.Id, impliedTag.Id); err != nil {
		return fmt.Errorf("could not add delete tag implication of '%v' to '%v': %v", tagName, impliedTagName, err)
	}

	return nil
}
开发者ID:kelvinhammond,项目名称:tmsu,代码行数:27,代码来源:imply.go

示例6: listTagsForPath

func (command TagsCommand) listTagsForPath(store *storage.Storage, path string) error {
	if command.verbose {
		log.Infof("%v: retrieving tags.", path)
	}

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

	if len(tags) == 0 {
		_, err := os.Stat(path)
		if err != nil {
			switch {
			case os.IsPermission(err):
				log.Warnf("%v: permission denied", path)
			case os.IsNotExist(err):
				return fmt.Errorf("%v: file not found", path)
			default:
				return fmt.Errorf("%v: could not stat file: %v", path, err)
			}
		}
	}

	if command.count {
		log.Print(len(tags))
	} else {
		for _, tag := range tags {
			log.Print(tag.Name)
		}
	}

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

示例7: 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

示例8: getOrCreateValue

func getOrCreateValue(store *storage.Storage, valueName string) (*entities.Value, error) {
	value, err := store.ValueByName(valueName)
	if err != nil {
		return nil, err
	}
	if value == nil {
		value, err = store.AddValue(valueName)
		if err != nil {
			return nil, err
		}
	}

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

示例9: repairMissing

func repairMissing(store *storage.Storage, missing databaseFileMap, pretend, force bool) error {
	for path, dbFile := range missing {
		if force && !pretend {
			if err := store.DeleteFileTagsByFileId(dbFile.Id); err != nil {
				return fmt.Errorf("%v: could not delete file-tags: %v", path, err)
			}

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

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

示例10: 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

示例11: 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

示例12: tagPath

func tagPath(store *storage.Storage, path string, tagValuePairs []TagValuePair, recursive bool, fingerprintAlgorithm string) error {
	absPath, err := filepath.Abs(path)
	if err != nil {
		return fmt.Errorf("%v: could not get absolute path: %v", path, err)
	}

	stat, err := os.Stat(path)
	if err != nil {
		if os.IsNotExist(err) {
			stat, err = os.Lstat(path)
			if err != nil {
				return err
			}
		} else {
			return err
		}
	}

	log.Infof(2, "%v: checking if file exists", absPath)

	file, err := store.FileByPath(absPath)
	if err != nil {
		return fmt.Errorf("%v: could not retrieve file: %v", path, err)
	}
	if file == nil {
		file, err = addFile(store, absPath, stat.ModTime(), uint(stat.Size()), stat.IsDir(), fingerprintAlgorithm)
		if err != nil {
			return fmt.Errorf("%v: could not add file: %v", path, err)
		}
	}

	log.Infof(2, "%v: applying tags.", file.Path())

	for _, tagValuePair := range tagValuePairs {
		if _, err = store.AddFileTag(file.Id, tagValuePair.TagId, tagValuePair.ValueId); err != nil {
			return fmt.Errorf("%v: could not apply tags: %v", file.Path(), err)
		}
	}

	if recursive && stat.IsDir() {
		if err = tagRecursively(store, path, tagValuePairs, fingerprintAlgorithm); err != nil {
			return err
		}
	}

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

示例13: addFile

func (command *TagCommand) addFile(store *storage.Storage, path string, modTime time.Time, size uint, isDir bool) (*database.File, error) {
	if command.verbose {
		log.Infof("%v: adding file.", path)
	}

	fingerprint, err := fingerprint.Create(path)
	if err != nil {
		return nil, fmt.Errorf("%v: could not create fingerprint: %v", path, err)
	}

	file, err := store.AddFile(path, fingerprint, modTime, int64(size), isDir)
	if err != nil {
		return nil, fmt.Errorf("%v: could not add file to database: %v", path, err)
	}

	return file, nil
}
开发者ID:kelvinhammond,项目名称:tmsu,代码行数:17,代码来源:tag.go

示例14: addFile

func addFile(store *storage.Storage, path string, modTime time.Time, size uint, isDir bool, fingerprintAlgorithm string) (*entities.File, error) {
	log.Infof(2, "%v: creating fingerprint", path)

	fingerprint, err := fingerprint.Create(path, fingerprintAlgorithm)
	if err != nil {
		return nil, fmt.Errorf("%v: could not create fingerprint: %v", path, err)
	}

	log.Infof(2, "%v: adding file.", path)

	file, err := store.AddFile(path, fingerprint, modTime, int64(size), isDir)
	if err != nil {
		return nil, fmt.Errorf("%v: could not add file to database: %v", path, err)
	}

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

示例15: getOrCreateTag

func getOrCreateTag(store *storage.Storage, tagName string) (*entities.Tag, error) {
	tag, err := store.TagByName(tagName)
	if err != nil {
		return nil, fmt.Errorf("could not look up tag '%v': %v", tagName, err)
	}

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

		log.Warnf("New tag '%v'.", tagName)
	}

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


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