func contains(files database.Files, searchFile *database.File) bool { for _, file := range files { if file.Path() == searchFile.Path() { return true } } return false }
func (vfs FuseVfs) getLinkName(file *database.File) string { extension := filepath.Ext(file.Path()) fileName := filepath.Base(file.Path()) linkName := fileName[0 : len(fileName)-len(extension)] suffix := "." + Uitoa(file.Id) + extension if len(linkName)+len(suffix) > 255 { linkName = linkName[0 : 255-len(suffix)] } return linkName + suffix }
func expectTags(test *testing.T, store *storage.Storage, file *database.File, tags ...*database.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) } } }
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 }
func (command *StatusCommand) checkFile(file *database.File, report *StatusReport) error { relPath := path.Rel(file.Path()) if command.verbose { log.Infof("%v: checking file status.", file.Path()) } stat, err := os.Stat(file.Path()) if err != nil { switch { case os.IsNotExist(err): if command.verbose { log.Infof("%v: file is missing.", file.Path()) } report.AddRow(Row{relPath, MISSING}) return nil case os.IsPermission(err): log.Warnf("%v: permission denied.", file.Path()) case strings.Contains(err.Error(), "not a directory"): report.AddRow(Row{relPath, MISSING}) return nil default: return fmt.Errorf("%v: could not stat: %v", file.Path(), err) } } else { if stat.Size() != file.Size || stat.ModTime().UTC() != file.ModTime { if command.verbose { log.Infof("%v: file is modified.", file.Path()) } report.AddRow(Row{relPath, MODIFIED}) } else { if command.verbose { log.Infof("%v: file is unchanged.", file.Path()) } report.AddRow(Row{relPath, TAGGED}) } } return nil }