本文整理汇总了Golang中tmsu/storage.Open函数的典型用法代码示例。如果您正苦于以下问题:Golang Open函数的具体用法?Golang Open怎么用?Golang Open使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Open函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: listAllTags
func (command TagsCommand) listAllTags() error {
store, err := storage.Open()
if err != nil {
return fmt.Errorf("could not open storage: %v", err)
}
defer store.Close()
if command.verbose {
log.Info("retrieving all tags.")
}
if command.count {
count, err := store.TagCount()
if err != nil {
return fmt.Errorf("could not retrieve tag count: %v", err)
}
log.Print(count)
} else {
tags, err := store.Tags()
if err != nil {
return fmt.Errorf("could not retrieve tags: %v", err)
}
for _, tag := range tags {
log.Print(tag.Name)
}
}
return nil
}
示例2: findDuplicatesInDb
func findDuplicatesInDb() error {
store, err := storage.Open()
if err != nil {
return fmt.Errorf("could not open storage: %v", err)
}
defer store.Close()
log.Info(2, "identifying duplicate files.")
fileSets, err := store.DuplicateFiles()
if err != nil {
return fmt.Errorf("could not identify duplicate files: %v", err)
}
log.Infof(2, "found %v sets of duplicate files.", len(fileSets))
for index, fileSet := range fileSets {
if index > 0 {
fmt.Println()
}
fmt.Printf("Set of %v duplicates:\n", len(fileSet))
for _, file := range fileSet {
relPath := _path.Rel(file.Path())
fmt.Printf(" %v\n", relPath)
}
}
return nil
}
示例3: Exec
func (command ImplyCommand) Exec(options cli.Options, args []string) error {
command.verbose = options.HasOption("--verbose")
store, err := storage.Open()
if err != nil {
return fmt.Errorf("could not open storage: %v", err)
}
defer store.Close()
switch {
case options.HasOption("--list"):
return command.listImplications(store)
case options.HasOption("--delete"):
if len(args) < 2 {
return fmt.Errorf("Implying and implied tag must be specified.")
}
return command.deleteImplication(store, args[0], args[1])
}
if len(args) < 2 {
return fmt.Errorf("Implying and implied tag must be specified.")
}
return command.addImplication(store, args[0], args[1])
}
示例4: TestRenameDestTagAlreadyExists
func TestRenameDestTagAlreadyExists(test *testing.T) {
// set-up
databasePath := configureDatabase()
defer os.Remove(databasePath)
store, err := storage.Open()
if err != nil {
test.Fatal(err)
}
defer store.Close()
_, err = store.AddTag("source")
if err != nil {
test.Fatal(err)
}
_, err = store.AddTag("dest")
if err != nil {
test.Fatal(err)
}
command := RenameCommand{false}
// test
err = command.Exec(cli.Options{}, []string{"source", "dest"})
// validate
if err == nil {
test.Fatal("Existing dest tag not identified.")
}
}
示例5: findDuplicatesInDb
func (command DupesCommand) findDuplicatesInDb() error {
store, err := storage.Open()
if err != nil {
return fmt.Errorf("could not open storage: %v", err)
}
defer store.Close()
if command.verbose {
log.Info("identifying duplicate files.")
}
fileSets, err := store.DuplicateFiles()
if err != nil {
return fmt.Errorf("could not identify duplicate files: %v", err)
}
if command.verbose {
log.Infof("found %v sets of duplicate files.", len(fileSets))
}
for index, fileSet := range fileSets {
if index > 0 {
log.Print()
}
log.Printf("Set of %v duplicates:", len(fileSet))
for _, file := range fileSet {
relPath := _path.Rel(file.Path())
log.Printf(" %v", relPath)
}
}
return nil
}
示例6: Exec
func (StatsCommand) Exec(options cli.Options, args []string) error {
store, err := storage.Open()
if err != nil {
return fmt.Errorf("could not open storage: %v", err)
}
defer store.Close()
tagCount, err := store.TagCount()
if err != nil {
return fmt.Errorf("could not retrieve tag count: %v", err)
}
fileCount, err := store.FileCount()
if err != nil {
return fmt.Errorf("could not retrieve file count: %v", err)
}
fileTagCount, err := store.FileTagCount()
if err != nil {
return fmt.Errorf("could not retrieve taggings count: %v", err)
}
log.Printf(" Tags: %v", tagCount)
log.Printf(" Files: %v", fileCount)
log.Printf(" Taggings: %v", fileTagCount)
return nil
}
示例7: TestMergeNonExistentDestinationTag
func TestMergeNonExistentDestinationTag(test *testing.T) {
// set-up
databasePath := testDatabase()
defer os.Remove(databasePath)
store, err := storage.Open()
if err != nil {
test.Fatal(err)
}
defer store.Close()
_, err = store.AddTag("a")
if err != nil {
test.Fatal(err)
}
store.Commit()
// test
if err := MergeCommand.Exec(Options{}, []string{"a", "b"}); err == nil {
test.Fatal("Expected non-existent destination tag to be identified.")
}
}
示例8: TestMergeSourceAndDestinationTheSame
func TestMergeSourceAndDestinationTheSame(test *testing.T) {
// set-up
databasePath := testDatabase()
defer os.Remove(databasePath)
store, err := storage.Open()
if err != nil {
test.Fatal(err)
}
defer store.Close()
_, err = store.AddTag("a")
if err != nil {
test.Fatal(err)
}
store.Commit()
// test
if err := MergeCommand.Exec(Options{}, []string{"a", "a"}); err == nil {
test.Fatal("Expected source and destination the same tag to be identified.")
}
}
示例9: TestMergeNonExistentSourceTag
func TestMergeNonExistentSourceTag(test *testing.T) {
// set-up
databasePath := configureDatabase()
defer os.Remove(databasePath)
store, err := storage.Open()
if err != nil {
test.Fatal(err)
}
defer store.Close()
_, err = store.AddTag("b")
if err != nil {
test.Fatal(err)
}
command := MergeCommand{false}
// test
if err := command.Exec(cli.Options{}, []string{"a", "b"}); err == nil {
test.Fatal("Expected non-existent source tag to be identified.")
}
}
示例10: TestDupesNoneUntaggedFile
func TestDupesNoneUntaggedFile(test *testing.T) {
// set-up
databasePath := testDatabase()
defer os.Remove(databasePath)
err := redirectStreams()
if err != nil {
test.Fatal(err)
}
defer restoreStreams()
path := filepath.Join(os.TempDir(), "tmsu-file")
_, err = os.Create(path)
if err != nil {
test.Fatal(err)
}
defer os.Remove(path)
store, err := storage.Open()
if err != nil {
test.Fatal(err)
}
defer store.Close()
_, err = store.AddFile("/tmp/a", fingerprint.Fingerprint("abc"), time.Now(), 123, true)
if err != nil {
test.Fatal(err)
}
_, err = store.AddFile("/tmp/a/b", fingerprint.Fingerprint("def"), time.Now(), 123, false)
if err != nil {
test.Fatal(err)
}
_, err = store.AddFile("/tmp/b", fingerprint.Fingerprint("ghi"), time.Now(), 123, false)
if err != nil {
test.Fatal(err)
}
_, err = store.AddFile("/tmp/e/f", fingerprint.Fingerprint("klm"), time.Now(), 123, false)
if err != nil {
test.Fatal(err)
}
_, err = store.AddFile("/tmp/a/d", fingerprint.Fingerprint("nop"), time.Now(), 123, false)
if err != nil {
test.Fatal(err)
}
store.Commit()
// test
if err := DupesCommand.Exec(Options{}, []string{path}); err != nil {
test.Fatal(err)
}
// validate
outFile.Seek(0, 0)
bytes, err := ioutil.ReadAll(outFile)
compareOutput(test, "", string(bytes))
}
示例11: TestDupesMultipleUntaggedFile
func TestDupesMultipleUntaggedFile(test *testing.T) {
// set-up
databasePath := testDatabase()
defer os.Remove(databasePath)
err := redirectStreams()
if err != nil {
test.Fatal(err)
}
defer restoreStreams()
path := filepath.Join(os.TempDir(), "tmsu-file")
_, err = os.Create(path)
if err != nil {
test.Fatal(err)
}
defer os.Remove(path)
store, err := storage.Open()
if err != nil {
test.Fatal(err)
}
defer store.Close()
_, err = store.AddFile("/tmp/a", fingerprint.Fingerprint("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"), time.Now(), 123, true)
if err != nil {
test.Fatal(err)
}
_, err = store.AddFile("/tmp/a/b", fingerprint.Fingerprint("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"), time.Now(), 123, false)
if err != nil {
test.Fatal(err)
}
_, err = store.AddFile("/tmp/b", fingerprint.Fingerprint("xxx"), time.Now(), 123, false)
if err != nil {
test.Fatal(err)
}
_, err = store.AddFile("/tmp/e/f", fingerprint.Fingerprint("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"), time.Now(), 123, false)
if err != nil {
test.Fatal(err)
}
_, err = store.AddFile("/tmp/a/d", fingerprint.Fingerprint("xxx"), time.Now(), 123, false)
if err != nil {
test.Fatal(err)
}
store.Commit()
// test
if err := DupesCommand.Exec(Options{}, []string{path}); err != nil {
test.Fatal(err)
}
// validate
outFile.Seek(0, 0)
bytes, err := ioutil.ReadAll(outFile)
compareOutput(test, "/tmp/a\n/tmp/a/b\n/tmp/e/f\n", string(bytes))
}
示例12: createTags
func createTags(names []string) error {
store, err := storage.Open()
if err != nil {
return fmt.Errorf("could not open storage: %v", err)
}
defer store.Close()
defer store.Commit()
tags, err := store.TagsByNames(names)
if err != nil {
return fmt.Errorf("could not retrieve tags %v: %v", names, err)
}
wereErrors := false
for _, tag := range tags {
log.Warnf("tag '%v' already exists", tag.Name)
wereErrors = true
}
if wereErrors {
return blankError
}
for _, name := range names {
_, err := store.AddTag(name)
if err != nil {
return fmt.Errorf("could not add tag '%v': %v", name, err)
}
}
return nil
}
示例13: TestCopyDestTagAlreadyExists
func TestCopyDestTagAlreadyExists(test *testing.T) {
// set-up
databasePath := testDatabase()
defer os.Remove(databasePath)
store, err := storage.Open()
if err != nil {
test.Fatal(err)
}
defer store.Close()
_, err = store.AddTag("source")
if err != nil {
test.Fatal(err)
}
_, err = store.AddTag("dest")
if err != nil {
test.Fatal(err)
}
store.Commit()
// test
err = CopyCommand.Exec(Options{}, []string{"source", "dest"})
// validate
if err == nil {
test.Fatal("Existing dest tag not identified.")
}
}
示例14: TestTagsForSingleFile
func TestTagsForSingleFile(test *testing.T) {
// set-up
databasePath := configureDatabase()
defer os.Remove(databasePath)
outPath, errPath, err := configureOutput()
if err != nil {
test.Fatal(err)
}
defer os.Remove(outPath)
defer os.Remove(errPath)
store, err := storage.Open()
if err != nil {
test.Fatal(err)
}
defer store.Close()
file, err := store.AddFile("/tmp/tmsu/a", fingerprint.Fingerprint("123"), time.Now(), 0, false)
if err != nil {
test.Fatal(err)
}
appleTag, err := store.AddTag("apple")
if err != nil {
test.Fatal(err)
}
bananaTag, err := store.AddTag("banana")
if err != nil {
test.Fatal(err)
}
_, err = store.AddFileTag(file.Id, appleTag.Id)
if err != nil {
test.Fatal(err)
}
_, err = store.AddFileTag(file.Id, bananaTag.Id)
if err != nil {
test.Fatal(err)
}
tagsCommand := TagsCommand{false, false}
// test
if err := tagsCommand.Exec(cli.Options{}, []string{"/tmp/tmsu/a"}); err != nil {
test.Fatal(err)
}
// verify
log.Outfile.Seek(0, 0)
bytes, err := ioutil.ReadAll(log.Outfile)
compareOutput(test, "apple\nbanana\n", string(bytes))
}
示例15: findDuplicatesOf
func (command DupesCommand) findDuplicatesOf(paths []string) error {
store, err := storage.Open()
if err != nil {
return fmt.Errorf("could not open storage: %v", err)
}
defer store.Close()
first := true
for _, path := range paths {
if command.verbose {
log.Infof("%v: identifying duplicate files.\n", path)
}
fp, err := fingerprint.Create(path)
if err != nil {
return fmt.Errorf("%v: could not create fingerprint: %v", path, err)
}
if fp == fingerprint.Fingerprint("") {
return nil
}
files, err := store.FilesByFingerprint(fp)
if err != nil {
return fmt.Errorf("%v: could not retrieve files matching fingerprint '%v': %v", path, fp, err)
}
absPath, err := filepath.Abs(path)
if err != nil {
return fmt.Errorf("%v: could not determine absolute path: %v", path, err)
}
// filter out the file we're searching on
dupes := files.Where(func(file *database.File) bool { return file.Path() != absPath })
if len(paths) > 1 && len(dupes) > 0 {
if first {
first = false
} else {
log.Print()
}
log.Printf("%v duplicates of %v:", len(dupes), path)
for _, dupe := range dupes {
relPath := _path.Rel(dupe.Path())
log.Printf(" %v", relPath)
}
} else {
for _, dupe := range dupes {
relPath := _path.Rel(dupe.Path())
log.Print(relPath)
}
}
}
return nil
}