本文整理汇总了Golang中tmsu/common/log.Infof函数的典型用法代码示例。如果您正苦于以下问题:Golang Infof函数的具体用法?Golang Infof怎么用?Golang Infof使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Infof函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例2: statusCheckFile
func statusCheckFile(file *entities.File, report *StatusReport) error {
relPath := path.Rel(file.Path())
log.Infof(2, "%v: checking file status.", file.Path())
stat, err := os.Stat(file.Path())
if err != nil {
switch {
case os.IsNotExist(err):
log.Infof(2, "%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 {
log.Infof(2, "%v: file is modified.", file.Path())
report.AddRow(Row{relPath, MODIFIED})
} else {
log.Infof(2, "%v: file is unchanged.", file.Path())
report.AddRow(Row{relPath, TAGGED})
}
}
return nil
}
示例3: Rmdir
func (vfs FuseVfs) Rmdir(name string, context *fuse.Context) fuse.Status {
log.Infof(2, "BEGIN Rmdir(%v)", name)
defer log.Infof(2, "END Rmdir(%v)", name)
path := vfs.splitPath(name)
switch path[0] {
case tagsDir:
if len(path) != 2 {
// can only remove top-level tag directories
return fuse.EPERM
}
tagName := path[1]
tag, err := vfs.store.TagByName(tagName)
if err != nil {
log.Fatalf("could not retrieve tag '%v': %v", tagName, err)
}
if tag == nil {
return fuse.ENOENT
}
count, err := vfs.store.FileTagCountByTagId(tag.Id)
if err != nil {
log.Fatalf("could not retrieve file-tag count for tag '%v': %v", tagName, err)
}
if count > 0 {
return fuse.Status(syscall.ENOTEMPTY)
}
if err := vfs.store.DeleteTag(tag.Id); err != nil {
log.Fatalf("could not delete tag '%v': %v", tagName, err)
}
if err := vfs.store.Commit(); err != nil {
log.Fatalf("could not commit transaction: %v", err)
}
return fuse.OK
case queriesDir:
if len(path) != 2 {
// can only remove top-level queries directories
return fuse.EPERM
}
text := path[1]
if err := vfs.store.DeleteQuery(text); err != nil {
log.Fatalf("could not remove tag '%v': %v", name, err)
}
if err := vfs.store.Commit(); err != nil {
log.Fatalf("could not commit transaction: %v", err)
}
return fuse.OK
}
return fuse.ENOSYS
}
示例4: getQueryAttr
func (vfs FuseVfs) getQueryAttr() (*fuse.Attr, fuse.Status) {
log.Infof(2, "BEGIN getQueryAttr")
defer log.Infof(2, "END getQueryAttr")
now := time.Now()
return &fuse.Attr{Mode: fuse.S_IFDIR | 0755, Nlink: 2, Size: 0, Mtime: uint64(now.Unix()), Mtimensec: uint32(now.Nanosecond())}, fuse.OK
}
示例5: openQueryEntryDir
func (vfs FuseVfs) openQueryEntryDir(path []string) ([]fuse.DirEntry, fuse.Status) {
log.Infof(2, "BEGIN openQueryEntryDir(%v)", path)
defer log.Infof(2, "END openQueryEntryDir(%v)", path)
queryText := path[0]
expression, err := query.Parse(queryText)
if err != nil {
return nil, fuse.ENOENT
}
tagNames := query.TagNames(expression)
tags, err := vfs.store.TagsByNames(tagNames)
for _, tagName := range tagNames {
if !containsTag(tags, tagName) {
return nil, fuse.ENOENT
}
}
files, err := vfs.store.QueryFiles(expression)
if err != nil {
log.Fatalf("could not query files: %v", err)
}
entries := make([]fuse.DirEntry, 0, len(files))
for _, file := range files {
linkName := vfs.getLinkName(file)
entries = append(entries, fuse.DirEntry{Name: linkName, Mode: fuse.S_IFLNK})
}
return entries, fuse.OK
}
示例6: Mkdir
func (vfs FuseVfs) Mkdir(name string, mode uint32, context *fuse.Context) fuse.Status {
log.Infof(2, "BEGIN Mkdir(%v)", name)
defer log.Infof(2, "END Mkdir(%v)", name)
path := vfs.splitPath(name)
if len(path) != 2 {
return fuse.EPERM
}
switch path[0] {
case tagsDir:
name := path[1]
if _, err := vfs.store.AddTag(name); err != nil {
log.Fatalf("could not create tag '%v': %v", name, err)
}
if err := vfs.store.Commit(); err != nil {
log.Fatalf("could not commit transaction: %v", err)
}
return fuse.OK
case queriesDir:
return fuse.EINVAL
}
return fuse.ENOSYS
}
示例7: topDirectories
func (vfs FuseVfs) topDirectories() ([]fuse.DirEntry, fuse.Status) {
log.Infof(2, "BEGIN topDirectories")
defer log.Infof(2, "END topDirectories")
entries := []fuse.DirEntry{fuse.DirEntry{Name: tagsDir, Mode: fuse.S_IFDIR},
fuse.DirEntry{Name: queriesDir, Mode: fuse.S_IFDIR}}
return entries, fuse.OK
}
示例8: Open
func (vfs FuseVfs) Open(name string, flags uint32, context *fuse.Context) (nodefs.File, fuse.Status) {
log.Infof(2, "BEGIN Open(%v)", name)
defer log.Infof(2, "END Open(%v)", name)
if name == filepath.Join(queriesDir, queryHelpFilename) {
return nodefs.NewDataFile([]byte(queryDirHelp)), fuse.OK
}
return nil, fuse.ENOSYS
}
示例9: openTaggedEntryDir
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
}
示例10: Readlink
func (vfs FuseVfs) Readlink(name string, context *fuse.Context) (string, fuse.Status) {
log.Infof(2, "BEGIN Readlink(%v)", name)
defer log.Infof(2, "END Readlink(%v)", name)
path := vfs.splitPath(name)
switch path[0] {
case tagsDir, queriesDir:
return vfs.readTaggedEntryLink(path[1:])
}
return "", fuse.ENOENT
}
示例11: getTagsAttr
func (vfs FuseVfs) getTagsAttr() (*fuse.Attr, fuse.Status) {
log.Infof(2, "BEGIN getTagsAttr")
defer log.Infof(2, "END getTagsAttr")
tagCount, err := vfs.store.TagCount()
if err != nil {
log.Fatalf("could not get tag count: %v", err)
}
now := time.Now()
return &fuse.Attr{Mode: fuse.S_IFDIR | 0755, Nlink: 2, Size: uint64(tagCount), Mtime: uint64(now.Unix()), Mtimensec: uint32(now.Nanosecond())}, fuse.OK
}
示例12: getQueryEntryAttr
func (vfs FuseVfs) getQueryEntryAttr(path []string) (*fuse.Attr, fuse.Status) {
log.Infof(2, "BEGIN getQueryEntryAttr(%v)", path)
defer log.Infof(2, "END getQueryEntryAttr(%v)", path)
pathLength := len(path)
name := path[pathLength-1]
if len(path) == 1 && path[0] == queryHelpFilename {
now := time.Now()
return &fuse.Attr{Mode: fuse.S_IFREG | 0444, Nlink: 1, Size: uint64(len(queryDirHelp)), Mtime: uint64(now.Unix()), Mtimensec: uint32(now.Nanosecond())}, fuse.OK
}
if len(path) > 1 {
fileId := vfs.parseFileId(name)
if fileId != 0 {
return vfs.getFileEntryAttr(fileId)
}
return nil, fuse.ENOENT
}
queryText := path[0]
if queryText[len(queryText)-1] == ' ' {
// prevent multiple entries for same query when typing path in a GUI
return nil, fuse.ENOENT
}
expression, err := query.Parse(queryText)
if err != nil {
return nil, fuse.ENOENT
}
tagNames := query.TagNames(expression)
tags, err := vfs.store.TagsByNames(tagNames)
for _, tagName := range tagNames {
if !containsTag(tags, tagName) {
return nil, fuse.ENOENT
}
}
_, _ = vfs.store.AddQuery(queryText)
if err := vfs.store.Commit(); err != nil {
log.Fatalf("could not commit transaction: %v", err)
}
now := time.Now()
return &fuse.Attr{Mode: fuse.S_IFDIR | 0755, Nlink: 2, Size: uint64(0), Mtime: uint64(now.Unix()), Mtimensec: uint32(now.Nanosecond())}, fuse.OK
}
示例13: 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
}
示例14: Unlink
func (vfs FuseVfs) Unlink(name string, context *fuse.Context) fuse.Status {
log.Infof(2, "BEGIN Unlink(%v)", name)
defer log.Infof(2, "END Unlink(%v)", name)
fileId := vfs.parseFileId(name)
if fileId == 0 {
// can only unlink file symbolic links
return fuse.EPERM
}
file, err := vfs.store.File(fileId)
if err != nil {
log.Fatal("could not retrieve file '%v': %v", fileId, err)
}
if file == nil {
// reply ok if file doesn't exist otherwise recursive deletes fail
return fuse.OK
}
path := vfs.splitPath(name)
switch path[0] {
case tagsDir:
tagName := path[len(path)-2]
//TODO value name
tag, err := vfs.store.TagByName(tagName)
if err != nil {
log.Fatal(err)
}
if tag == nil {
log.Fatalf("could not retrieve tag '%v'.", tagName)
}
if err = vfs.store.DeleteFileTag(fileId, tag.Id, 0); err != nil {
log.Fatal(err)
}
if err := vfs.store.Commit(); err != nil {
log.Fatalf("could not commit transaction: %v", err)
}
return fuse.OK
case queriesDir:
return fuse.EPERM
}
return fuse.ENOSYS
}
示例15: 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
}